Files
otunes/apps/web/app/(app)/album/[id]/page.tsx
T

72 lines
1.9 KiB
TypeScript

import { AlbumView } from "@/components/album-view"
import { LibraryLoading } from "@/components/library-loading"
import { api } from "@/convex/_generated/api"
import { fetchQuery } from "convex/nextjs"
import type { Id } from "@/convex/_generated/dataModel"
import { Metadata } from "next"
interface PageProps {
params: Promise<{ id: string }>
searchParams: Promise<{ s?: string }>
}
export async function generateMetadata({
params,
searchParams,
}: PageProps): Promise<Metadata> {
const { id } = await params
const { s: songId } = await searchParams
const album = await fetchQuery(api.library.browseAlbumDetail, {
id: id as Id<"albums">,
})
const sharedTrack =
album && songId
? album.tracks.find((track) => track.id === songId)
: undefined
const pageTitle = sharedTrack
? `${sharedTrack.title} - ${album!.title}`
: album
? album.title
: null
return {
title: `${album ? `${album.title} - oTunes` : "oTunes"}`,
openGraph: {
title: `${pageTitle ? `${pageTitle} - oTunes` : "oTunes"}`,
description: `${album ? album.artist.name : null}`,
images: album
? { url: `/api/album/${album.id}/cover`, width: 512, height: 512 }
: [],
},
}
}
export default async function Page({ params, searchParams }: PageProps) {
const { id } = await params
const { s: highlightedSongId } = await searchParams
const album = await fetchQuery(api.library.browseAlbumDetail, {
id: id as Id<"albums">,
})
if (album === undefined) {
return (
<div className="flex h-svh flex-col">
<LibraryLoading />
</div>
)
}
if (album === null) {
return (
<div className="flex h-svh flex-col">
<div className="flex flex-1 items-center justify-center pb-28">
<p className="text-sm text-muted-foreground">Album not found.</p>
</div>
</div>
)
}
return <AlbumView album={album} highlightedSongId={highlightedSongId} />
}