feat(web): right click menu for queue history and current song
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f558613949
commit
ca82ea2008
1 file changed
+59
-8
@@ -3,12 +3,16 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { useFavorites } from "@/components/favorites-provider"
|
||||
import type { MediaContextAction } from "@/components/media-context-menu"
|
||||
import {
|
||||
MediaContextMenuArea,
|
||||
type MediaContextAction,
|
||||
} from "@/components/media-context-menu"
|
||||
import { PlaybackSongMeta } from "@/components/playback-song-meta"
|
||||
import { usePlayback } from "@/components/playback-provider"
|
||||
import { TrackCover, TrackRow } from "@/components/track-row"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { Spinner } from "@/components/ui/spinner"
|
||||
import { useSongDownloadState } from "@/hooks/use-downloads"
|
||||
import { useMediaActions } from "@/hooks/use-media-actions"
|
||||
import { useTrackSelection } from "@/hooks/use-track-selection"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
@@ -50,6 +54,51 @@ function toSelectableQueue(
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the song's right-click menu over `children`, for the queue rows that
|
||||
* stand alone (history and the current song) rather than in the selection.
|
||||
*/
|
||||
function SongMenuArea({
|
||||
song,
|
||||
children,
|
||||
}: {
|
||||
song: BrowseSong
|
||||
children: React.ReactElement
|
||||
}) {
|
||||
const { isSongFavorite, toggleSongFavorite } = useFavorites()
|
||||
const { runSongsAction } = useMediaActions()
|
||||
const downloaded = useSongDownloadState(song.id) === "here"
|
||||
|
||||
function handleAction(action: MediaContextAction) {
|
||||
if (action === "favorite") {
|
||||
void toggleSongFavorite(song.id)
|
||||
return
|
||||
}
|
||||
runSongsAction(action, [song.id], song.artist.id)
|
||||
}
|
||||
|
||||
return (
|
||||
<MediaContextMenuArea
|
||||
menu={{
|
||||
label: `More options for ${song.title}`,
|
||||
stationArtistId: song.artist.id,
|
||||
selectedCount: 1,
|
||||
onOpenMenu: () => {},
|
||||
onAction: handleAction,
|
||||
favorited: isSongFavorite(song.id),
|
||||
downloaded,
|
||||
navigation: {
|
||||
artist: { id: song.artist.id },
|
||||
album: { id: song.album.id },
|
||||
},
|
||||
share: { type: "song", albumId: song.album.id, songId: song.id },
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</MediaContextMenuArea>
|
||||
)
|
||||
}
|
||||
|
||||
/** A played song; clicking it plays it again from that point in history. */
|
||||
function HistorySongRow({
|
||||
song,
|
||||
@@ -65,10 +114,11 @@ function HistorySongRow({
|
||||
}
|
||||
|
||||
return (
|
||||
<SongMenuArea song={song}>
|
||||
<li
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5"
|
||||
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5 data-[state=open]:bg-foreground/5"
|
||||
onClick={() => onPlay(historyIndex)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
@@ -84,6 +134,7 @@ function HistorySongRow({
|
||||
/>
|
||||
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
|
||||
</li>
|
||||
</SongMenuArea>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -354,10 +405,9 @@ export function QueuePanel() {
|
||||
|
||||
{/* Fills the viewport so the current song can always scroll to the top. */}
|
||||
<div ref={currentRef} className="flex min-h-full flex-col">
|
||||
{currentQueueSongId ? (
|
||||
<div className="flex items-center gap-3 px-4 py-3">
|
||||
{currentSong ? (
|
||||
<>
|
||||
<SongMenuArea song={currentSong}>
|
||||
<div className="flex items-center gap-3 px-4 py-3">
|
||||
<TrackCover
|
||||
albumId={currentSong.album.id}
|
||||
alt={currentSong.album.title}
|
||||
@@ -369,10 +419,11 @@ export function QueuePanel() {
|
||||
align="start"
|
||||
showAlbum={false}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
</div>
|
||||
</SongMenuArea>
|
||||
) : currentQueueSongId ? (
|
||||
<div className="px-4 py-3">
|
||||
<Skeleton className="size-14 shrink-0 rounded-md" />
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
|
||||
Reference in new issue
Block a user