721 lines
23 KiB
TypeScript
721 lines
23 KiB
TypeScript
"use client"
|
|
|
|
import { MobileSidebarTrigger } from "@/components/mobile-sidebar-trigger"
|
|
import { stationArtistId } from "@/lib/station-artist"
|
|
import * as React from "react"
|
|
import Image from "next/image"
|
|
import { useRouter } from "next/navigation"
|
|
import { useMutation } from "convex/react"
|
|
import { Play, Share2, Shuffle, Star, Trash2 } from "lucide-react"
|
|
import { toast } from "sonner"
|
|
|
|
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
|
|
import { useFavorites } from "@/components/favorites-provider"
|
|
import { usePlayback } from "@/components/playback-provider"
|
|
import { MediaCollectionFooter } from "@/components/media-collection-footer"
|
|
import { TrackNumberPlayButton } from "@/components/track-number-play-button"
|
|
import {
|
|
MediaContextMenu,
|
|
type MediaContextAction,
|
|
} from "@/components/media-context-menu"
|
|
import { Button } from "@/components/ui/button"
|
|
import {
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
} from "@/components/ui/dropdown-menu"
|
|
import { ScrollArea } from "@/components/ui/scroll-area"
|
|
import { useCachedQuery } from "@/hooks/use-cached-query"
|
|
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
|
import { useTrackSelection } from "@/hooks/use-track-selection"
|
|
import { api } from "@otunes/convex/_generated/api"
|
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
|
import type { BrowsePlaylistDetail, BrowseSong } from "@otunes/convex/types"
|
|
import { albumCoverUrl, playlistCoverUrl } from "@/lib/cover-urls"
|
|
import { copyPlaylistLink } from "@/lib/media-links"
|
|
import { sumDurationSeconds } from "@/lib/media-summary"
|
|
import { rememberSongs } from "@/lib/song-cache"
|
|
import { cn } from "@/lib/utils"
|
|
import {
|
|
getSelectionRangePositions,
|
|
isInSelectionRange,
|
|
ALBUM_TRACK_ROW,
|
|
ALBUM_TRACK_TITLE,
|
|
SelectionRangeHighlight,
|
|
TrackRowActiveHighlight,
|
|
TrackRowHoverHighlight,
|
|
TRACK_ROW_PADDING,
|
|
type SelectionRangePosition,
|
|
} from "@/lib/selection-range-styles"
|
|
|
|
const ADD_TO_ANOTHER_PLAYLIST = "Add to Another Playlist"
|
|
|
|
function formatDuration(seconds: number): string {
|
|
const minutes = Math.floor(seconds / 60)
|
|
const remainingSeconds = seconds % 60
|
|
return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`
|
|
}
|
|
|
|
function PlaylistSongCover({
|
|
song,
|
|
inRange,
|
|
isFavorite,
|
|
onToggleFavorite,
|
|
}: {
|
|
song: BrowseSong
|
|
inRange: boolean
|
|
isFavorite: boolean
|
|
onToggleFavorite: () => void
|
|
}) {
|
|
return (
|
|
<div
|
|
className={cn(
|
|
"group/cover relative size-10 shrink-0 overflow-hidden rounded ring-1",
|
|
inRange ? "ring-white/25" : "ring-foreground/10"
|
|
)}
|
|
>
|
|
<Image
|
|
src={albumCoverUrl(song.album.id)}
|
|
alt={song.album.title}
|
|
fill
|
|
sizes="40px"
|
|
className="object-cover"
|
|
/>
|
|
<div
|
|
className={cn(
|
|
"absolute inset-0 flex items-center justify-center bg-black/0 opacity-0 transition-opacity group-hover/cover:opacity-100",
|
|
"group-hover/cover:bg-black/40"
|
|
)}
|
|
>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
className={cn(
|
|
"size-8",
|
|
inRange
|
|
? "text-primary-foreground hover:bg-white/15 hover:text-primary-foreground"
|
|
: "text-primary hover:text-primary"
|
|
)}
|
|
aria-label={
|
|
isFavorite
|
|
? `Remove ${song.title} from favorites`
|
|
: `Favorite ${song.title}`
|
|
}
|
|
onClick={(event) => {
|
|
event.stopPropagation()
|
|
onToggleFavorite()
|
|
}}
|
|
>
|
|
<Star
|
|
className={cn(
|
|
"size-4",
|
|
isFavorite && (inRange ? "fill-current" : "fill-primary")
|
|
)}
|
|
/>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function PlaylistSongRow({
|
|
song,
|
|
index,
|
|
isOwner,
|
|
canRemove,
|
|
isActive,
|
|
selectionPosition,
|
|
isFavorite,
|
|
selectedCount,
|
|
stationArtist,
|
|
isDragging,
|
|
onSelect,
|
|
onPointerDown,
|
|
onToggleFavorite,
|
|
onPrepareContextMenu,
|
|
onMediaAction,
|
|
onRemove,
|
|
onDragStart,
|
|
onDragOver,
|
|
onDrop,
|
|
showFavoriteInMenu = true,
|
|
removeLabel = "Remove from Playlist",
|
|
isNowPlaying,
|
|
onPlay,
|
|
}: {
|
|
song: BrowseSong
|
|
index: number
|
|
isOwner: boolean
|
|
canRemove: boolean
|
|
isActive: boolean
|
|
selectionPosition: SelectionRangePosition
|
|
isFavorite: boolean
|
|
selectedCount: number
|
|
stationArtist?: string
|
|
isDragging: boolean
|
|
onSelect: (event: React.MouseEvent) => void
|
|
onPointerDown: (event: React.MouseEvent) => void
|
|
onToggleFavorite: () => void
|
|
onPrepareContextMenu: () => void
|
|
onMediaAction: (action: MediaContextAction, songId: string) => void
|
|
onRemove: () => void
|
|
onDragStart: (event: React.DragEvent) => void
|
|
onDragOver: (event: React.DragEvent) => void
|
|
onDrop: (event: React.DragEvent) => void
|
|
showFavoriteInMenu?: boolean
|
|
removeLabel?: string
|
|
isNowPlaying: boolean
|
|
onPlay: () => void
|
|
}) {
|
|
const displayTrack = index + 1
|
|
const inRange = isInSelectionRange(selectionPosition)
|
|
|
|
return (
|
|
<div
|
|
role="button"
|
|
tabIndex={0}
|
|
draggable={isOwner}
|
|
onDragStart={onDragStart}
|
|
onDragOver={onDragOver}
|
|
onDrop={onDrop}
|
|
onMouseDown={onPointerDown}
|
|
onClick={onSelect}
|
|
onDoubleClick={(event) => {
|
|
event.preventDefault()
|
|
onPlay()
|
|
}}
|
|
onKeyDown={(event) => {
|
|
if (event.key === "Enter" || event.key === " ") {
|
|
event.preventDefault()
|
|
onSelect(event as unknown as React.MouseEvent)
|
|
}
|
|
}}
|
|
className={cn(
|
|
"group relative w-full cursor-pointer select-none py-2.5 text-left text-sm transition-colors",
|
|
inRange && "text-primary-foreground",
|
|
isDragging && "opacity-50"
|
|
)}
|
|
>
|
|
<SelectionRangeHighlight position={selectionPosition} />
|
|
{!inRange && isActive ? <TrackRowActiveHighlight /> : null}
|
|
{!inRange && !isActive ? <TrackRowHoverHighlight /> : null}
|
|
<div
|
|
className={cn("relative z-10", ALBUM_TRACK_ROW, TRACK_ROW_PADDING)}
|
|
>
|
|
<PlaylistSongCover
|
|
song={song}
|
|
inRange={inRange}
|
|
isFavorite={isFavorite}
|
|
onToggleFavorite={onToggleFavorite}
|
|
/>
|
|
|
|
<TrackNumberPlayButton
|
|
displayTrack={displayTrack}
|
|
title={song.title}
|
|
isActive={isActive}
|
|
isNowPlaying={isNowPlaying}
|
|
inRange={inRange}
|
|
onPlay={onPlay}
|
|
/>
|
|
|
|
<span className={ALBUM_TRACK_TITLE}>{song.title}</span>
|
|
|
|
<span
|
|
className={cn(
|
|
"shrink-0 text-right tabular-nums",
|
|
inRange ? "text-primary-foreground" : "text-muted-foreground"
|
|
)}
|
|
>
|
|
{formatDuration(song.durationSeconds)}
|
|
</span>
|
|
|
|
<MediaContextMenu
|
|
label={`More options for ${song.title}`}
|
|
stationArtistId={stationArtist}
|
|
selectedCount={selectedCount}
|
|
inSelectionRange={inRange}
|
|
onOpenMenu={onPrepareContextMenu}
|
|
onAction={(action) => onMediaAction(action, song.id)}
|
|
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
|
showFavorite={showFavoriteInMenu}
|
|
favorited={isFavorite}
|
|
navigation={{
|
|
artist: { id: song.artist.id },
|
|
album: { id: song.album.id },
|
|
}}
|
|
share={{
|
|
type: "song",
|
|
albumId: song.album.id,
|
|
songId: song.id,
|
|
}}
|
|
>
|
|
{canRemove ? (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
variant="destructive"
|
|
className="justify-between"
|
|
onClick={onRemove}
|
|
>
|
|
{removeLabel}
|
|
<Trash2 />
|
|
</DropdownMenuItem>
|
|
</>
|
|
) : null}
|
|
</MediaContextMenu>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export function PlaylistView({ playlist }: { playlist: BrowsePlaylistDetail }) {
|
|
const router = useRouter()
|
|
const isFavorites = playlist.isFavorites === true
|
|
const currentUser = useCachedQuery(api.auth.currentUser)
|
|
const isOwner =
|
|
currentUser === undefined
|
|
? playlist.isOwner
|
|
: currentUser?._id === playlist.owner.id
|
|
const { openAddToPlaylist } = useAddToPlaylist()
|
|
const {
|
|
isSongFavorite,
|
|
toggleSongFavorite,
|
|
toggleSongsFavorite,
|
|
favoriteSongs: addFavoriteSongs,
|
|
} = useFavorites()
|
|
const {
|
|
currentSong,
|
|
playInOrder,
|
|
playShuffled,
|
|
playPlaylist,
|
|
playPlaylistShuffled,
|
|
playFromSong,
|
|
} = usePlayback()
|
|
const { runQueueAction, createStation } = useQueueMediaActions()
|
|
const removeSongs = useMutation(api.playlists.removeSongsFromPlaylist)
|
|
const reorderSongs = useMutation(api.playlists.reorderPlaylistSongs)
|
|
const deletePlaylist = useMutation(api.playlists.deletePlaylist)
|
|
const subscribe = useMutation(api.playlists.subscribeToPlaylist)
|
|
const unsubscribe = useMutation(api.playlists.unsubscribeFromPlaylist)
|
|
|
|
const [playlistSongs, setPlaylistSongs] = React.useState(playlist.songs)
|
|
const [syncedPlaylist, setSyncedPlaylist] = React.useState(playlist)
|
|
const [hiddenFavoriteIds, setHiddenFavoriteIds] = React.useState(
|
|
() => new Set<string>()
|
|
)
|
|
const songs = isFavorites
|
|
? playlist.songs.filter((song) => !hiddenFavoriteIds.has(song.id))
|
|
: playlistSongs
|
|
const playlistSongIds = React.useMemo(
|
|
() => songs.map((song) => song.id as Id<"songs">),
|
|
[songs]
|
|
)
|
|
const [activeTrackId, setActiveTrackId] = React.useState("")
|
|
const [dragIndex, setDragIndex] = React.useState<number | null>(null)
|
|
const [isSubscribed, setIsSubscribed] = React.useState(playlist.isSubscribed)
|
|
const [subscriptionPending, setSubscriptionPending] = React.useState(false)
|
|
|
|
if (syncedPlaylist !== playlist) {
|
|
setSyncedPlaylist(playlist)
|
|
setPlaylistSongs(playlist.songs)
|
|
setIsSubscribed(playlist.isSubscribed)
|
|
}
|
|
|
|
const {
|
|
selectedIds,
|
|
selectedCount,
|
|
isSelected,
|
|
handleSelect,
|
|
handlePointerDown,
|
|
prepareContextMenu,
|
|
} = useTrackSelection(songs)
|
|
|
|
const selectedStationArtistId = React.useMemo(
|
|
() => stationArtistId(songs, selectedIds),
|
|
[songs, selectedIds]
|
|
)
|
|
|
|
const selectionPositions = React.useMemo(
|
|
() => getSelectionRangePositions(songs.map((song) => song.id), selectedIds),
|
|
[songs, selectedIds]
|
|
)
|
|
const totalDurationSeconds = React.useMemo(
|
|
() => sumDurationSeconds(songs),
|
|
[songs]
|
|
)
|
|
|
|
React.useEffect(() => {
|
|
rememberSongs(playlist.songs)
|
|
}, [playlist.songs])
|
|
|
|
function playAll(shuffled: boolean) {
|
|
if (playlist.id) {
|
|
const play = shuffled ? playPlaylistShuffled : playPlaylist
|
|
void play(playlist.id, playlistSongIds)
|
|
} else {
|
|
void (shuffled ? playShuffled : playInOrder)(playlistSongIds)
|
|
}
|
|
}
|
|
|
|
function resolveTargetIds(fallbackSongId?: string) {
|
|
return selectedIds.size > 0
|
|
? Array.from(selectedIds)
|
|
: fallbackSongId
|
|
? [fallbackSongId]
|
|
: activeTrackId
|
|
? [activeTrackId]
|
|
: []
|
|
}
|
|
|
|
function handleMediaAction(
|
|
action: MediaContextAction,
|
|
fallbackSongId?: string
|
|
) {
|
|
const targetIds = resolveTargetIds(fallbackSongId)
|
|
|
|
switch (action) {
|
|
case "create-station": {
|
|
const artistId = stationArtistId(songs, new Set(targetIds))
|
|
if (artistId) void createStation(artistId)
|
|
break
|
|
}
|
|
case "favorite":
|
|
void addFavoriteSongs(targetIds as Id<"songs">[])
|
|
break
|
|
case "playlist":
|
|
openAddToPlaylist(targetIds as Id<"songs">[])
|
|
break
|
|
case "play-next":
|
|
case "play-last":
|
|
case "shuffle":
|
|
void runQueueAction(action, targetIds as Id<"songs">[])
|
|
break
|
|
}
|
|
}
|
|
|
|
function handlePlaylistMediaAction(action: MediaContextAction) {
|
|
const targetIds = songs.map((song) => song.id as Id<"songs">)
|
|
|
|
switch (action) {
|
|
case "favorite":
|
|
void addFavoriteSongs(targetIds)
|
|
break
|
|
case "playlist":
|
|
openAddToPlaylist(targetIds)
|
|
break
|
|
case "play-next":
|
|
case "play-last":
|
|
case "shuffle":
|
|
void runQueueAction(action, targetIds)
|
|
break
|
|
}
|
|
}
|
|
|
|
async function handleRemoveSong(songId: string) {
|
|
const ids =
|
|
selectedIds.size > 0 && selectedIds.has(songId)
|
|
? Array.from(selectedIds)
|
|
: [songId]
|
|
|
|
if (isFavorites) {
|
|
const succeeded = await toggleSongsFavorite(
|
|
ids as Id<"songs">[],
|
|
true
|
|
)
|
|
if (!succeeded) return
|
|
return
|
|
}
|
|
|
|
try {
|
|
await removeSongs({
|
|
playlistId: playlist.id as Id<"playlists">,
|
|
songIds: ids as Id<"songs">[],
|
|
})
|
|
setPlaylistSongs((current) =>
|
|
current.filter((song) => !ids.includes(song.id))
|
|
)
|
|
toast.success(ids.length > 1 ? `Removed ${ids.length} songs` : "Removed song")
|
|
} catch (error) {
|
|
toast.error(
|
|
error instanceof Error ? error.message : "Failed to remove song"
|
|
)
|
|
}
|
|
}
|
|
|
|
async function persistOrder(
|
|
previousSongs: BrowseSong[],
|
|
nextSongs: BrowseSong[]
|
|
) {
|
|
try {
|
|
await reorderSongs({
|
|
playlistId: playlist.id as Id<"playlists">,
|
|
songIds: nextSongs.map((song) => song.id as Id<"songs">),
|
|
})
|
|
} catch (error) {
|
|
setPlaylistSongs((current) =>
|
|
current === nextSongs ? previousSongs : current
|
|
)
|
|
toast.error(
|
|
error instanceof Error ? error.message : "Failed to reorder songs"
|
|
)
|
|
}
|
|
}
|
|
|
|
function handleDrop(targetIndex: number) {
|
|
if (isFavorites || !isOwner || dragIndex === null || dragIndex === targetIndex) {
|
|
setDragIndex(null)
|
|
return
|
|
}
|
|
|
|
const previous = songs
|
|
const next = [...previous]
|
|
const [moved] = next.splice(dragIndex, 1)
|
|
next.splice(targetIndex, 0, moved)
|
|
setDragIndex(null)
|
|
setPlaylistSongs(next)
|
|
void persistOrder(previous, next)
|
|
}
|
|
|
|
async function handleDeletePlaylist() {
|
|
try {
|
|
await deletePlaylist({
|
|
playlistId: playlist.id as Id<"playlists">,
|
|
})
|
|
toast.success("Playlist deleted")
|
|
router.push("/playlists")
|
|
} catch (error) {
|
|
toast.error(
|
|
error instanceof Error ? error.message : "Failed to delete playlist"
|
|
)
|
|
}
|
|
}
|
|
|
|
async function handleSubscribeToggle() {
|
|
if (subscriptionPending) {
|
|
return
|
|
}
|
|
setSubscriptionPending(true)
|
|
try {
|
|
if (isSubscribed) {
|
|
await unsubscribe({
|
|
playlistId: playlist.id as Id<"playlists">,
|
|
})
|
|
setIsSubscribed(false)
|
|
toast.success("Unsubscribed from playlist")
|
|
} else {
|
|
await subscribe({
|
|
playlistId: playlist.id as Id<"playlists">,
|
|
})
|
|
setIsSubscribed(true)
|
|
toast.success("Subscribed to playlist")
|
|
}
|
|
} catch (error) {
|
|
toast.error(
|
|
error instanceof Error ? error.message : "Failed to update subscription"
|
|
)
|
|
} finally {
|
|
setSubscriptionPending(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex h-svh flex-col">
|
|
<ScrollArea className="min-h-0 flex-1">
|
|
<div className="pb-28">
|
|
<div className="mx-auto w-full min-w-0 max-w-9/10">
|
|
<div className="flex flex-col gap-8 px-6 pt-6 pb-8 sm:flex-row sm:items-end">
|
|
<div className="relative mx-auto aspect-square w-full max-w-60 shrink-0 overflow-hidden rounded-lg ring-1 ring-foreground/10 sm:mx-0">
|
|
{isFavorites ? (
|
|
<div className="flex size-full items-center justify-center bg-muted">
|
|
<Star className="size-16 fill-primary text-primary" />
|
|
</div>
|
|
) : (
|
|
<Image
|
|
src={playlistCoverUrl(playlist.id!)}
|
|
alt={playlist.title}
|
|
fill
|
|
sizes="240px"
|
|
className="object-cover"
|
|
preload
|
|
/>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex min-w-0 flex-1 flex-col gap-4">
|
|
<div className="space-y-1 text-center sm:text-left">
|
|
<p className="text-xs font-medium tracking-wide text-muted-foreground uppercase">
|
|
Playlist
|
|
</p>
|
|
<div className="flex min-w-0 items-center justify-center gap-2 sm:justify-start md:contents">
|
|
<MobileSidebarTrigger />
|
|
<h1 className="text-3xl font-bold tracking-tight sm:text-4xl">
|
|
{playlist.title}
|
|
</h1>
|
|
</div>
|
|
<p className="text-lg font-semibold text-primary">
|
|
{playlist.owner.name}
|
|
</p>
|
|
</div>
|
|
|
|
<div className="flex flex-wrap items-center justify-center gap-2 sm:justify-start">
|
|
<Button
|
|
variant="secondary"
|
|
size="icon"
|
|
className="rounded-full"
|
|
aria-label="Shuffle playlist"
|
|
onClick={() => playAll(true)}
|
|
disabled={playlistSongIds.length === 0}
|
|
>
|
|
<Shuffle />
|
|
</Button>
|
|
<Button
|
|
className="h-10 gap-2 rounded-full bg-foreground px-6 text-background hover:bg-foreground/90"
|
|
aria-label={`Play ${playlist.title}`}
|
|
onClick={() => playAll(false)}
|
|
disabled={playlistSongIds.length === 0}
|
|
>
|
|
<Play className="fill-current" />
|
|
Play
|
|
</Button>
|
|
{!isOwner ? (
|
|
<Button
|
|
variant={isSubscribed ? "secondary" : "default"}
|
|
className="h-10 rounded-full px-6"
|
|
onClick={() => void handleSubscribeToggle()}
|
|
disabled={subscriptionPending}
|
|
>
|
|
{isSubscribed ? "Subscribed" : "Subscribe"}
|
|
</Button>
|
|
) : null}
|
|
{!isFavorites ? (
|
|
<Button
|
|
variant="secondary"
|
|
size="icon"
|
|
className="rounded-full"
|
|
aria-label="Share playlist"
|
|
onClick={() =>
|
|
void copyPlaylistLink(playlist.id!, {
|
|
isFavorites,
|
|
})
|
|
}
|
|
>
|
|
<Share2 />
|
|
</Button>
|
|
) : null}
|
|
<MediaContextMenu
|
|
label="More playlist options"
|
|
selectedCount={songs.length}
|
|
onOpenMenu={() => {}}
|
|
onAction={handlePlaylistMediaAction}
|
|
playlistLabel={ADD_TO_ANOTHER_PLAYLIST}
|
|
showFavorite={!isFavorites}
|
|
trackRowTrigger={false}
|
|
triggerVariant="secondary"
|
|
triggerClassName="rounded-full"
|
|
share={{
|
|
type: "playlist",
|
|
playlistId: playlist.id ?? "favorites",
|
|
isFavorites,
|
|
}}
|
|
>
|
|
{isOwner && !isFavorites ? (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
variant="destructive"
|
|
className="justify-between"
|
|
onClick={handleDeletePlaylist}
|
|
>
|
|
Delete Playlist
|
|
<Trash2 />
|
|
</DropdownMenuItem>
|
|
</>
|
|
) : null}
|
|
</MediaContextMenu>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{songs.length > 0 ? (
|
|
songs.map((song, index) => (
|
|
<PlaylistSongRow
|
|
key={song.id}
|
|
song={song}
|
|
index={index}
|
|
isOwner={isOwner && !isFavorites}
|
|
canRemove={isFavorites || isOwner}
|
|
showFavoriteInMenu={!isFavorites}
|
|
removeLabel={
|
|
isFavorites ? "Unfavorite" : "Remove from Playlist"
|
|
}
|
|
isActive={song.id === activeTrackId}
|
|
selectionPosition={selectionPositions[index]}
|
|
isFavorite={isSongFavorite(song.id)}
|
|
selectedCount={
|
|
isSelected(song.id) && selectedCount > 0
|
|
? selectedCount
|
|
: 1
|
|
}
|
|
stationArtist={
|
|
isSelected(song.id)
|
|
? selectedStationArtistId
|
|
: song.artist.id
|
|
}
|
|
isDragging={dragIndex === index}
|
|
onPointerDown={handlePointerDown}
|
|
onSelect={(event) => {
|
|
handleSelect(song.id, index, event)
|
|
setActiveTrackId(song.id)
|
|
}}
|
|
onToggleFavorite={() => {
|
|
const wasFavorite = isSongFavorite(song.id)
|
|
void toggleSongFavorite(song.id as Id<"songs">)
|
|
if (isFavorites && wasFavorite) {
|
|
setHiddenFavoriteIds((current) => {
|
|
const next = new Set(current)
|
|
next.add(song.id)
|
|
return next
|
|
})
|
|
}
|
|
}}
|
|
onPrepareContextMenu={() => prepareContextMenu(song.id)}
|
|
onMediaAction={handleMediaAction}
|
|
onRemove={() => handleRemoveSong(song.id)}
|
|
onDragStart={(event) => {
|
|
if (isFavorites || !isOwner) {
|
|
return
|
|
}
|
|
setDragIndex(index)
|
|
event.dataTransfer.effectAllowed = "move"
|
|
}}
|
|
onDragOver={(event) => {
|
|
if (isFavorites || !isOwner) {
|
|
return
|
|
}
|
|
event.preventDefault()
|
|
}}
|
|
onDrop={(event) => {
|
|
event.preventDefault()
|
|
handleDrop(index)
|
|
}}
|
|
isNowPlaying={currentSong?.id === song.id}
|
|
onPlay={() =>
|
|
void playFromSong(song.id as Id<"songs">, playlistSongIds)
|
|
}
|
|
/>
|
|
))
|
|
) : (
|
|
<p className="px-6 py-8 text-sm text-muted-foreground">
|
|
This playlist has no songs yet.
|
|
</p>
|
|
)}
|
|
<MediaCollectionFooter
|
|
songCount={songs.length}
|
|
totalDurationSeconds={totalDurationSeconds}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</ScrollArea>
|
|
</div>
|
|
)
|
|
}
|