Compare commits

...
+90 -39
View File
@@ -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,25 +114,27 @@ function HistorySongRow({
}
return (
<li
role="button"
tabIndex={0}
className="flex cursor-pointer items-center gap-3 px-4 py-2 text-sm hover:bg-foreground/5"
onClick={() => onPlay(historyIndex)}
onKeyDown={(event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault()
onPlay(historyIndex)
}
}}
>
<TrackCover
albumId={song.album.id}
alt={song.album.title}
inRange={false}
/>
<PlaybackSongMeta song={song} align="start" showAlbum={false} />
</li>
<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 data-[state=open]:bg-foreground/5"
onClick={() => onPlay(historyIndex)}
onKeyDown={(event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault()
onPlay(historyIndex)
}
}}
>
<TrackCover
albumId={song.album.id}
alt={song.album.title}
inRange={false}
/>
<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. */}
<div ref={currentRef} className="flex min-h-full flex-col">
{currentQueueSongId ? (
<div className="flex items-center gap-3 px-4 py-3">
{currentSong ? (
<>
<TrackCover
albumId={currentSong.album.id}
alt={currentSong.album.title}
inRange={false}
size="lg"
/>
<PlaybackSongMeta
song={currentSong}
align="start"
showAlbum={false}
/>
</>
) : (
<Skeleton className="size-14 shrink-0 rounded-md" />
)}
{currentSong ? (
<SongMenuArea song={currentSong}>
<div className="flex items-center gap-3 px-4 py-3">
<TrackCover
albumId={currentSong.album.id}
alt={currentSong.album.title}
inRange={false}
size="lg"
/>
<PlaybackSongMeta
song={currentSong}
align="start"
showAlbum={false}
/>
</div>
</SongMenuArea>
) : currentQueueSongId ? (
<div className="px-4 py-3">
<Skeleton className="size-14 shrink-0 rounded-md" />
</div>
) : null}