- 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
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { LibraryLoading } from "@/components/library-loading"
|
|
import { PlaylistView } from "@/components/playlist-view"
|
|
import { api } from "@otunes/convex/_generated/api"
|
|
import { convexAuthNextjsToken } from "@convex-dev/auth/nextjs/server"
|
|
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 }>
|
|
}
|
|
|
|
const fetchPlaylistDetail = cache(async (id: Id<"playlists">) => {
|
|
const token = await convexAuthNextjsToken()
|
|
return fetchQuery(
|
|
api.playlists.browsePlaylistDetail,
|
|
{ id },
|
|
convexServerOptions(token)
|
|
)
|
|
})
|
|
|
|
export async function generateMetadata({
|
|
params,
|
|
}: PageProps): Promise<Metadata> {
|
|
const { id } = await params
|
|
const playlist = await fetchPlaylistDetail(id as Id<"playlists">)
|
|
|
|
return {
|
|
title: `${playlist ? `${playlist.title}` : "oTunes"}`,
|
|
openGraph: {
|
|
title: `${playlist ? `${playlist.title}` : "oTunes"}`,
|
|
description: playlist ? `Playlist by ${playlist.owner.name}` : "oTunes",
|
|
images: playlist
|
|
? { url: `/api/playlist/${playlist.id}/cover`, width: 512, height: 512 }
|
|
: [],
|
|
},
|
|
}
|
|
}
|
|
|
|
export default async function Page({ params }: PageProps) {
|
|
const { id } = await params
|
|
const playlist = await fetchPlaylistDetail(id as Id<"playlists">)
|
|
|
|
if (playlist === undefined) {
|
|
return (
|
|
<div className="flex h-svh flex-col">
|
|
<LibraryLoading />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (playlist === 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">Playlist not found.</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return <PlaylistView key={playlist.id} playlist={playlist} />
|
|
}
|