Files
otunes/apps/web/components/search-song-item.tsx
T
joshuafhiggins 73c7283d4d Add Expo mobile app and extract shared Convex package
- 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
2026-08-02 04:14:01 +00:00

85 lines
2.7 KiB
TypeScript

"use client"
import Image from "next/image"
import Link from "next/link"
import { useAddToPlaylist } from "@/components/add-to-playlist-provider"
import { useFavorites } from "@/components/favorites-provider"
import { useQueueMediaActions } from "@/hooks/use-queue-media-actions"
import {
MediaContextMenu,
type MediaContextAction,
} from "@/components/media-context-menu"
import type { Id } from "@otunes/convex/_generated/dataModel"
import type { BrowseSong } from "@otunes/convex/types"
import { albumCoverUrl } from "@/lib/cover-urls"
export function SearchSongItem({ song }: { song: BrowseSong }) {
const { openAddToPlaylist } = useAddToPlaylist()
const { isSongFavorite, toggleSongFavorite } = useFavorites()
const { runQueueAction } = useQueueMediaActions()
const songIds = [song.id as Id<"songs">]
function handleAction(action: MediaContextAction) {
switch (action) {
case "playlist":
openAddToPlaylist(songIds)
break
case "play-next":
case "play-last":
case "shuffle":
void runQueueAction(action, songIds)
break
case "favorite":
void toggleSongFavorite(song.id as Id<"songs">)
break
}
}
return (
<div className="group flex items-center gap-3 rounded-lg px-1 py-1.5 transition-colors hover:bg-muted/50">
<Link
href={`/album/${song.album.id}`}
className="relative size-11 shrink-0 overflow-hidden rounded ring-1 ring-foreground/10"
>
<Image
src={albumCoverUrl(song.album.id)}
alt={song.album.title}
fill
className="object-cover"
/>
</Link>
<div className="min-w-0 flex-1">
<Link href={`/album/${song.album.id}`} className="hover:underline">
<p className="truncate text-sm font-medium">{song.title}</p>
</Link>
<Link
href={`/artist/${song.artist.id}`}
className="text-muted-foreground hover:text-foreground hover:underline"
>
<p className="truncate text-sm">{song.artist.name}</p>
</Link>
</div>
<MediaContextMenu
label={`More options for ${song.title}`}
selectedCount={1}
onOpenMenu={() => {}}
onAction={handleAction}
favorited={isSongFavorite(song.id)}
navigation={{
artist: { id: song.artist.id },
album: { id: song.album.id },
}}
share={{
type: "song",
albumId: song.album.id,
songId: song.id,
}}
triggerClassName="size-8 shrink-0 opacity-0 transition-opacity group-hover:opacity-100 data-[state=open]:opacity-100"
triggerVariant="ghost"
/>
</div>
)
}