- Replace mobile placeholder with Expo Router app (tabs, playback, auth, library) - Move Convex backend to @otunes/convex for web and mobile reuse - Update web app imports and API routes to use shared package
115 lines
4.0 KiB
TypeScript
115 lines
4.0 KiB
TypeScript
"use client"
|
|
|
|
import Image from "next/image"
|
|
import Link from "next/link"
|
|
|
|
import type { PlaylistSummary } from "@otunes/convex/types"
|
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
|
import { playlistCoverUrl } from "@/lib/cover-urls"
|
|
import { useConvex } from "convex/react"
|
|
import { MoreHorizontal, Play } from "lucide-react"
|
|
|
|
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
|
|
import {
|
|
MediaContextMenuItems,
|
|
type MediaContextAction,
|
|
} from "@/components/media-context-menu"
|
|
import { usePlayback } from "@/components/playback-provider"
|
|
import { Button } from "@/components/ui/button"
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu"
|
|
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
|
|
import { api } from "@otunes/convex/_generated/api"
|
|
|
|
export function PlaylistCard({ playlist }: { playlist: PlaylistSummary }) {
|
|
const convex = useConvex()
|
|
const { openAddPlaylistToPlaylist } = useAddToPlaylist()
|
|
const { playPlaylist } = usePlayback()
|
|
const { runQueueAction } = useQueueMediaActions()
|
|
|
|
async function handleCardAction(action: MediaContextAction) {
|
|
switch (action) {
|
|
case "playlist":
|
|
void openAddPlaylistToPlaylist(playlist.id as Id<"playlists">)
|
|
break
|
|
case "play-next":
|
|
case "play-last":
|
|
case "shuffle": {
|
|
const songIds = await convex.query(api.playlists.getPlaylistSongIds, {
|
|
playlistId: playlist.id as Id<"playlists">,
|
|
})
|
|
void runQueueAction(action, songIds)
|
|
break
|
|
}
|
|
case "favorite":
|
|
break
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-col gap-2">
|
|
<div className="group relative aspect-square overflow-hidden rounded-lg ring-1 ring-foreground/10">
|
|
<Link className="absolute inset-0" href={"/playlist/" + playlist.id}>
|
|
<Image
|
|
src={playlistCoverUrl(playlist.id)}
|
|
alt={playlist.title}
|
|
fill
|
|
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 25vw, 16vw"
|
|
className="object-cover"
|
|
/>
|
|
</Link>
|
|
|
|
<div className="pointer-events-none absolute inset-0 bg-black/0 transition-colors group-hover:bg-black/40" />
|
|
|
|
<div className="pointer-events-none absolute inset-x-0 bottom-0 z-10 flex items-center justify-between p-2 opacity-0 transition-opacity group-hover:opacity-100 [&_button]:pointer-events-auto">
|
|
<Button
|
|
size="icon-sm"
|
|
className="rounded-full"
|
|
aria-label={`Play ${playlist.title}`}
|
|
onClick={(event) => {
|
|
event.preventDefault()
|
|
void playPlaylist(playlist.id as Id<"playlists">)
|
|
}}
|
|
>
|
|
<Play className="fill-current" />
|
|
</Button>
|
|
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
className="rounded-full text-white hover:bg-white/20 hover:text-white"
|
|
aria-label={`More options for ${playlist.title}`}
|
|
onClick={(event) => event.preventDefault()}
|
|
>
|
|
<MoreHorizontal />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-48">
|
|
<MediaContextMenuItems
|
|
selectedCount={1}
|
|
showFavorite={false}
|
|
onAction={(action) => void handleCardAction(action)}
|
|
share={{ type: "playlist", playlistId: playlist.id }}
|
|
/>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="min-w-0">
|
|
<Link href={"/playlist/" + playlist.id} className="hover:underline">
|
|
<p className="truncate text-sm font-medium">{playlist.title}</p>
|
|
</Link>
|
|
<p className="truncate text-xs text-muted-foreground decoration-muted-foreground">
|
|
{playlist.owner}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|