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:
joshuafhigginsandClaude Opus 5.5 committed 2026-11-20 00:24:57 -05:00
1 parent f558613949
commit ca82ea2008
1 file changed
+90 -39
+90 -39
View File
@@ -3,12 +3,16 @@
import * as React from "react" import * as React from "react"
import { useFavorites } from "@/components/favorites-provider" 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 { PlaybackSongMeta } from "@/components/playback-song-meta"
import { usePlayback } from "@/components/playback-provider" import { usePlayback } from "@/components/playback-provider"
import { TrackCover, TrackRow } from "@/components/track-row" import { TrackCover, TrackRow } from "@/components/track-row"
import { Skeleton } from "@/components/ui/skeleton" import { Skeleton } from "@/components/ui/skeleton"
import { Spinner } from "@/components/ui/spinner" import { Spinner } from "@/components/ui/spinner"
import { useSongDownloadState } from "@/hooks/use-downloads"
import { useMediaActions } from "@/hooks/use-media-actions" import { useMediaActions } from "@/hooks/use-media-actions"
import { useTrackSelection } from "@/hooks/use-track-selection" import { useTrackSelection } from "@/hooks/use-track-selection"
import type { Id } from "@otunes/convex/_generated/dataModel" 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. */ /** A played song; clicking it plays it again from that point in history. */
function HistorySongRow({ function HistorySongRow({
song, song,
@@ -65,25 +114,27 @@ function HistorySongRow({
} }
return ( return (
<li <SongMenuArea song={song}>
role="button" <li
tabIndex={0} role="button"
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5" tabIndex={0}
onClick={() => onPlay(historyIndex)} className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5 data-[state=open]:bg-foreground/5"
onKeyDown={(event) => { onClick={() => onPlay(historyIndex)}
if (event.key === "Enter" || event.key === " ") { onKeyDown={(event) => {
event.preventDefault() if (event.key === "Enter" || event.key === " ") {
onPlay(historyIndex) event.preventDefault()
} onPlay(historyIndex)
}} }
> }}
<TrackCover >
albumId={song.album.id} <TrackCover
alt={song.album.title} albumId={song.album.id}
inRange={false} alt={song.album.title}
/> inRange={false}
<PlaybackSongMeta song={song} align="start" showAlbum={false} /> />
</li> <PlaybackSongMeta song={song} align="start" showAlbum={false} />
</li>
</SongMenuArea>
) )
} }
@@ -354,25 +405,25 @@ export function QueuePanel() {
{/* Fills the viewport so the current song can always scroll to the top. */} {/* Fills the viewport so the current song can always scroll to the top. */}
<div ref={currentRef} className="flex min-h-full flex-col"> <div ref={currentRef} className="flex min-h-full flex-col">
{currentQueueSongId ? ( {currentSong ? (
<div className="flex items-center gap-3 px-4 py-3"> <SongMenuArea song={currentSong}>
{currentSong ? ( <div className="flex items-center gap-3 px-4 py-3">
<> <TrackCover
<TrackCover albumId={currentSong.album.id}
albumId={currentSong.album.id} alt={currentSong.album.title}
alt={currentSong.album.title} inRange={false}
inRange={false} size="lg"
size="lg" />
/> <PlaybackSongMeta
<PlaybackSongMeta song={currentSong}
song={currentSong} align="start"
align="start" showAlbum={false}
showAlbum={false} />
/> </div>
</> </SongMenuArea>
) : ( ) : currentQueueSongId ? (
<Skeleton className="size-14 shrink-0 rounded-md" /> <div className="px-4 py-3">
)} <Skeleton className="size-14 shrink-0 rounded-md" />
</div> </div>
) : null} ) : null}