Compare commits
3
Commits
No files matched your search
@@ -9,15 +9,13 @@
|
|||||||
"APP_VARIANT": "development"
|
"APP_VARIANT": "development"
|
||||||
},
|
},
|
||||||
"developmentClient": true,
|
"developmentClient": true,
|
||||||
"distribution": "internal",
|
"distribution": "internal"
|
||||||
"credentialsSource": "local"
|
|
||||||
},
|
},
|
||||||
"preview": {
|
"preview": {
|
||||||
"env": {
|
"env": {
|
||||||
"APP_VARIANT": "preview"
|
"APP_VARIANT": "preview"
|
||||||
},
|
},
|
||||||
"distribution": "internal",
|
"distribution": "internal"
|
||||||
"credentialsSource": "local"
|
|
||||||
},
|
},
|
||||||
"production": {
|
"production": {
|
||||||
"env": {
|
"env": {
|
||||||
|
|||||||
@@ -2,11 +2,18 @@
|
|||||||
|
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { useFavorites } from "@/components/favorites-provider"
|
||||||
|
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 { 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"
|
||||||
import type { BrowseSong, QueueSong } from "@otunes/convex/types"
|
import type { BrowseSong, QueueSong } from "@otunes/convex/types"
|
||||||
@@ -15,6 +22,7 @@ import {
|
|||||||
moveQueueBlock,
|
moveQueueBlock,
|
||||||
} from "@/lib/move-queue-block"
|
} from "@/lib/move-queue-block"
|
||||||
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
|
import { getSelectionRangePositions } from "@/lib/selection-range-styles"
|
||||||
|
import { stationArtistId } from "@/lib/station-artist"
|
||||||
import { useSongs } from "@/lib/song-cache"
|
import { useSongs } from "@/lib/song-cache"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -46,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,
|
||||||
@@ -61,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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +236,66 @@ export function QueuePanel() {
|
|||||||
() => selectableQueue.map((item) => ({ id: item.selectionId })),
|
() => selectableQueue.map((item) => ({ id: item.selectionId })),
|
||||||
[selectableQueue]
|
[selectableQueue]
|
||||||
)
|
)
|
||||||
const { selectedIds, handleSelect, handlePointerDown } =
|
const {
|
||||||
useTrackSelection(selectionItems)
|
selectedIds,
|
||||||
|
selectedCount,
|
||||||
|
handleSelect,
|
||||||
|
handlePointerDown,
|
||||||
|
prepareContextMenu,
|
||||||
|
clearSelection,
|
||||||
|
} = useTrackSelection(selectionItems)
|
||||||
|
const { isSongFavorite } = useFavorites()
|
||||||
|
const { runSongsAction } = useMediaActions()
|
||||||
|
|
||||||
|
/** The rows a menu acts on: the selection, else just the clicked row. */
|
||||||
|
const menuTargets = React.useCallback(
|
||||||
|
(selectionId: string) => {
|
||||||
|
const ids = selectedIds.has(selectionId)
|
||||||
|
? selectedIds
|
||||||
|
: new Set([selectionId])
|
||||||
|
return selectableQueue.filter((item) => ids.has(item.selectionId))
|
||||||
|
},
|
||||||
|
[selectableQueue, selectedIds]
|
||||||
|
)
|
||||||
|
|
||||||
|
const selectedStationArtistId = React.useMemo(
|
||||||
|
() =>
|
||||||
|
stationArtistId(
|
||||||
|
selectableQueue.flatMap((item) =>
|
||||||
|
item.song ? [{ id: item.selectionId, artist: item.song.artist }] : []
|
||||||
|
),
|
||||||
|
selectedIds
|
||||||
|
),
|
||||||
|
[selectableQueue, selectedIds]
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleMediaAction = React.useCallback(
|
||||||
|
(action: MediaContextAction, selectionId: string) => {
|
||||||
|
const songs = menuTargets(selectionId).flatMap((item) =>
|
||||||
|
item.song ? [item.song] : []
|
||||||
|
)
|
||||||
|
const artistId = songs[0]?.artist.id
|
||||||
|
runSongsAction(
|
||||||
|
action,
|
||||||
|
songs.map((song) => song.id),
|
||||||
|
songs.every((song) => song.artist.id === artistId)
|
||||||
|
? artistId
|
||||||
|
: undefined
|
||||||
|
)
|
||||||
|
},
|
||||||
|
[menuTargets, runSongsAction]
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleRemove = React.useCallback(
|
||||||
|
(selectionId: string) => {
|
||||||
|
const removed = new Set(
|
||||||
|
menuTargets(selectionId).map((item) => item.queueIndex)
|
||||||
|
)
|
||||||
|
clearSelection()
|
||||||
|
void reorderQueue(queueSongIds.filter((_, index) => !removed.has(index)))
|
||||||
|
},
|
||||||
|
[clearSelection, menuTargets, queueSongIds, reorderQueue]
|
||||||
|
)
|
||||||
|
|
||||||
const handleRowSelect = React.useCallback(
|
const handleRowSelect = React.useCallback(
|
||||||
(index: number, event: React.MouseEvent) => {
|
(index: number, event: React.MouseEvent) => {
|
||||||
@@ -292,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}
|
||||||
|
|
||||||
@@ -336,6 +449,11 @@ export function QueuePanel() {
|
|||||||
variant="queue"
|
variant="queue"
|
||||||
song={item.song}
|
song={item.song}
|
||||||
index={index}
|
index={index}
|
||||||
|
selectionId={item.selectionId}
|
||||||
|
isFavorite={isSongFavorite(item.song.id)}
|
||||||
|
selectedCount={selectedCount}
|
||||||
|
selectionStationArtistId={selectedStationArtistId}
|
||||||
|
removeLabel="Remove from Queue"
|
||||||
selectionPosition={selectionPositions[index]}
|
selectionPosition={selectionPositions[index]}
|
||||||
isDragging={draggingIndices.has(index)}
|
isDragging={draggingIndices.has(index)}
|
||||||
onPointerDown={handlePointerDown}
|
onPointerDown={handlePointerDown}
|
||||||
@@ -343,6 +461,9 @@ export function QueuePanel() {
|
|||||||
onPlay={handleRowPlay}
|
onPlay={handleRowPlay}
|
||||||
onDragStart={setDragIndex}
|
onDragStart={setDragIndex}
|
||||||
onDrop={handleDrop}
|
onDrop={handleDrop}
|
||||||
|
onPrepareContextMenu={prepareContextMenu}
|
||||||
|
onMediaAction={handleMediaAction}
|
||||||
|
onRemove={handleRemove}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<QueueSongRowSkeleton key={item.selectionId} />
|
<QueueSongRowSkeleton key={item.selectionId} />
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import type { DownloadSource } from "@otunes/convex/client/download-queue"
|
|||||||
* columns (use with `LibraryTrackListHeader`).
|
* columns (use with `LibraryTrackListHeader`).
|
||||||
* - `album`: favorite star, track number, title with optional credits.
|
* - `album`: favorite star, track number, title with optional credits.
|
||||||
* - `playlist`: cover with favorite overlay, track number, title.
|
* - `playlist`: cover with favorite overlay, track number, title.
|
||||||
* - `queue`: cover, title and artist, duration, and a reorder grip. No menu.
|
* - `queue`: cover, title and artist, duration, and a reorder grip.
|
||||||
*/
|
*/
|
||||||
export type TrackRowVariant = "library" | "album" | "playlist" | "queue"
|
export type TrackRowVariant = "library" | "album" | "playlist" | "queue"
|
||||||
|
|
||||||
@@ -47,6 +47,12 @@ export type TrackRowProps = {
|
|||||||
song: BrowseSong
|
song: BrowseSong
|
||||||
/** Position in the list the selection hook was given. */
|
/** Position in the list the selection hook was given. */
|
||||||
index: number
|
index: number
|
||||||
|
/**
|
||||||
|
* The id the selection hook knows this row by, passed to the menu and
|
||||||
|
* remove callbacks. Defaults to the song id; the queue uses a per-position
|
||||||
|
* id since a song can appear more than once.
|
||||||
|
*/
|
||||||
|
selectionId?: string
|
||||||
/** Number shown in the track number column (`album` and `playlist`). */
|
/** Number shown in the track number column (`album` and `playlist`). */
|
||||||
trackNumber?: number
|
trackNumber?: number
|
||||||
/** Secondary line under the title, e.g. album track credits. */
|
/** Secondary line under the title, e.g. album track credits. */
|
||||||
@@ -71,10 +77,10 @@ export type TrackRowProps = {
|
|||||||
onPointerDown: (event: React.MouseEvent) => void
|
onPointerDown: (event: React.MouseEvent) => void
|
||||||
onPlay: (index: number) => void
|
onPlay: (index: number) => void
|
||||||
onToggleFavorite?: (songId: string) => void
|
onToggleFavorite?: (songId: string) => void
|
||||||
onPrepareContextMenu?: (songId: string) => void
|
onPrepareContextMenu?: (selectionId: string) => void
|
||||||
/** Renders the "more options" and right-click menus when provided. */
|
/** Renders the "more options" and right-click menus when provided. */
|
||||||
onMediaAction?: (action: MediaContextAction, songId: string) => void
|
onMediaAction?: (action: MediaContextAction, selectionId: string) => void
|
||||||
onRemove?: (songId: string) => void
|
onRemove?: (selectionId: string) => void
|
||||||
/** Makes the row draggable when provided. */
|
/** Makes the row draggable when provided. */
|
||||||
onDragStart?: (index: number) => void
|
onDragStart?: (index: number) => void
|
||||||
onDrop?: (index: number) => void
|
onDrop?: (index: number) => void
|
||||||
@@ -251,6 +257,7 @@ function TrackRowComponent({
|
|||||||
variant,
|
variant,
|
||||||
song,
|
song,
|
||||||
index,
|
index,
|
||||||
|
selectionId,
|
||||||
trackNumber,
|
trackNumber,
|
||||||
subtitle,
|
subtitle,
|
||||||
downloadCollection,
|
downloadCollection,
|
||||||
@@ -284,6 +291,7 @@ function TrackRowComponent({
|
|||||||
const flush = variant === "library" || variant === "queue"
|
const flush = variant === "library" || variant === "queue"
|
||||||
const play = () => onPlay(index)
|
const play = () => onPlay(index)
|
||||||
const toggleFavorite = () => onToggleFavorite?.(song.id)
|
const toggleFavorite = () => onToggleFavorite?.(song.id)
|
||||||
|
const rowId = selectionId ?? song.id
|
||||||
|
|
||||||
const favoriteStar = (
|
const favoriteStar = (
|
||||||
<div className="flex shrink-0 items-center justify-center">
|
<div className="flex shrink-0 items-center justify-center">
|
||||||
@@ -333,8 +341,8 @@ function TrackRowComponent({
|
|||||||
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
|
stationArtistId: inRange ? selectionStationArtistId : song.artist.id,
|
||||||
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
|
selectedCount: inRange && selectedCount > 0 ? selectedCount : 1,
|
||||||
inSelectionRange: inRange,
|
inSelectionRange: inRange,
|
||||||
onOpenMenu: () => onPrepareContextMenu?.(song.id),
|
onOpenMenu: () => onPrepareContextMenu?.(rowId),
|
||||||
onAction: (action) => onMediaAction(action, song.id),
|
onAction: (action) => onMediaAction(action, rowId),
|
||||||
playlistLabel,
|
playlistLabel,
|
||||||
showFavorite: showFavoriteInMenu,
|
showFavorite: showFavoriteInMenu,
|
||||||
favorited: isFavorite,
|
favorited: isFavorite,
|
||||||
@@ -351,7 +359,7 @@ function TrackRowComponent({
|
|||||||
<MediaMenuItem
|
<MediaMenuItem
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
className="justify-between"
|
className="justify-between"
|
||||||
onClick={() => onRemove(song.id)}
|
onClick={() => onRemove(rowId)}
|
||||||
>
|
>
|
||||||
{removeLabel}
|
{removeLabel}
|
||||||
<Trash2 />
|
<Trash2 />
|
||||||
@@ -555,7 +563,7 @@ function TrackRowComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass stable callbacks: they receive the row's `index` or song id, so one
|
* Pass stable callbacks: they receive the row's `index`, song id or
|
||||||
* handler can serve every row.
|
* `selectionId`, so one handler can serve every row.
|
||||||
*/
|
*/
|
||||||
export const TrackRow = React.memo(TrackRowComponent)
|
export const TrackRow = React.memo(TrackRowComponent)
|
||||||
Reference in new issue
Block a user