Files
otunes/apps/web/app/(app)/album/[id]/page.tsx
T
joshuafhiggins Verified 1cea1fe745 feat(docker): bundle Convex backend with oTunes
- Run the web app and Convex backend in one container with generated per-install keys
- Derive Convex URLs from the server address and update self-hosting docs
2026-10-08 15:24:00 -04:00

78 lines
2.1 KiB
TypeScript

import { AlbumView } from "@/components/album-view"
import { LibraryLoading } from "@/components/library-loading"
import { api } from "@otunes/convex/_generated/api"
import { fetchQuery } from "convex/nextjs"
import { convexServerOptions } from "@/lib/convex-server"
import type { Id } from "@otunes/convex/_generated/dataModel"
import { Metadata } from "next"
import { cache } from "react"
interface PageProps {
params: Promise<{ id: string }>
searchParams: Promise<{ s?: string }>
}
const fetchAlbumDetail = cache((id: Id<"albums">) =>
fetchQuery(api.library.browseAlbumDetail, { id }, convexServerOptions())
)
export async function generateMetadata({
params,
searchParams,
}: PageProps): Promise<Metadata> {
const { id } = await params
const [{ s: songId }, album] = await Promise.all([
searchParams,
fetchAlbumDetail(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"}`,
openGraph: {
title: `${pageTitle ? `${pageTitle}` : "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 }, album] = await Promise.all([
searchParams,
fetchAlbumDetail(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} />
}