- 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
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { fetchQuery } from "convex/nextjs"
|
|
import { convexServerOptions } from "@/lib/convex-server"
|
|
import { ArtistView } from "@/components/artist-view"
|
|
import { LibraryLoading } from "@/components/library-loading"
|
|
import { api } from "@otunes/convex/_generated/api"
|
|
import type { Id } from "@otunes/convex/_generated/dataModel"
|
|
import { Metadata } from "next"
|
|
import { cache } from "react"
|
|
|
|
interface PageProps {
|
|
params: Promise<{ id: string }>
|
|
}
|
|
|
|
const fetchArtistDetail = cache((id: Id<"artists">) =>
|
|
fetchQuery(api.library.browseArtistDetail, { id }, convexServerOptions())
|
|
)
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: PageProps): Promise<Metadata> {
|
|
const { id } = await params
|
|
const data = await fetchArtistDetail(id as Id<"artists">)
|
|
|
|
return {
|
|
title: `${data ? `${data.artist.name}` : "oTunes"}`,
|
|
openGraph: {
|
|
title: `${data ? `${data.artist.name}` : "oTunes"}`,
|
|
description: "oTunes",
|
|
images: data
|
|
? {
|
|
url: `/api/artist/${data.artist.id}/cover`,
|
|
width: 512,
|
|
height: 512,
|
|
}
|
|
: [],
|
|
},
|
|
}
|
|
}
|
|
|
|
export default async function Page({ params }: PageProps) {
|
|
const { id } = await params
|
|
const data = await fetchArtistDetail(id as Id<"artists">)
|
|
|
|
if (data === undefined) {
|
|
return (
|
|
<div className="flex h-svh flex-col">
|
|
<LibraryLoading />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (data === 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">Artist not found.</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return <ArtistView artist={data.artist} albums={data.albums} />
|
|
}
|