From 43d034d0b440becf4d23f84ca0a434eb5f136d92 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Sat, 13 Jun 2026 21:03:46 -0400 Subject: [PATCH] fix: make metadata server sided --- app/(app)/album/[id]/page.tsx | 31 ++-- app/(app)/artist/[id]/page.tsx | 46 ++++-- app/(app)/library/artists/[id]/page.tsx | 50 ++++-- app/(app)/library/artists/page.tsx | 11 +- app/(app)/playlist/[id]/page.tsx | 34 ++-- app/layout.tsx | 1 + components/artists-view.tsx | 202 +++++++++++------------- 7 files changed, 212 insertions(+), 163 deletions(-) diff --git a/app/(app)/album/[id]/page.tsx b/app/(app)/album/[id]/page.tsx index b2c39ab..49010b4 100644 --- a/app/(app)/album/[id]/page.tsx +++ b/app/(app)/album/[id]/page.tsx @@ -3,11 +3,32 @@ 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 }> } +export async function generateMetadata({ + params, +}: PageProps): Promise { + const { id } = await params + const album = await fetchQuery(api.library.browseAlbumDetail, { + id: id as Id<"albums">, + }) + + return { + title: `${album ? `${album.title} - oTunes` : "oTunes"}`, + openGraph: { + title: `${album ? `${album.title} - 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 }: PageProps) { const { id } = await params const album = await fetchQuery(api.library.browseAlbumDetail, { @@ -32,13 +53,5 @@ export default async function Page({ params }: PageProps) { ) } - return ( - <> - {`${album.title} - oTunes`} - - - - - - ) + return } diff --git a/app/(app)/artist/[id]/page.tsx b/app/(app)/artist/[id]/page.tsx index ef5a4df..83a771b 100644 --- a/app/(app)/artist/[id]/page.tsx +++ b/app/(app)/artist/[id]/page.tsx @@ -1,16 +1,41 @@ -"use client" - -import { useParams } from "next/navigation" -import { useQuery } from "convex/react" - +import { fetchQuery } from "convex/nextjs" import { ArtistView } from "@/components/artist-view" import { LibraryLoading } from "@/components/library-loading" import { api } from "@/convex/_generated/api" import type { Id } from "@/convex/_generated/dataModel" +import { Metadata } from "next" -export default function Page() { - const { id } = useParams<{ id: string }>() - const data = useQuery(api.library.browseArtistDetail, { +interface PageProps { + params: Promise<{ id: string }> +} + +export async function generateMetadata({ + params, +}: PageProps): Promise { + const { id } = await params + const data = await fetchQuery(api.library.browseArtistDetail, { + id: id as Id<"artists">, + }) + + return { + title: `${data ? `${data.artist.name} - oTunes` : "oTunes"}`, + openGraph: { + title: `${data ? `${data.artist.name} - oTunes` : "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 fetchQuery(api.library.browseArtistDetail, { id: id as Id<"artists">, }) @@ -37,7 +62,10 @@ export default function Page() { {`${data.artist.name} - oTunes`} {/**/} - + () - const artists = useQuery(api.library.browseArtists) - const albums = useQuery(api.library.browseAlbums) +interface PageProps { + params: Promise<{ id: string }> +} + +export async function generateMetadata({ + params, +}: PageProps): Promise { + const { id } = await params + const artists = await fetchQuery(api.library.browseArtists) + const selectedArtist = artists.find((artist) => artist.id === id) + + return { + title: `${selectedArtist ? `${selectedArtist.name} - oTunes` : "oTunes"}`, + openGraph: { + title: `${selectedArtist ? `${selectedArtist.name} - oTunes` : "oTunes"}`, + description: "oTunes", + images: selectedArtist + ? { + url: `/api/artist/${selectedArtist.id}/cover`, + width: 512, + height: 512, + } + : [], + }, + } +} + +export default async function Page({ params }: PageProps) { + const { id } = await params + const artists = await fetchQuery(api.library.browseArtists) + const albums = await fetchQuery(api.library.browseAlbums) return (

Artists

- - {artists === undefined || albums === undefined ? ( - - ) : ( - - )} +
) } diff --git a/app/(app)/library/artists/page.tsx b/app/(app)/library/artists/page.tsx index be6db88..22f307e 100644 --- a/app/(app)/library/artists/page.tsx +++ b/app/(app)/library/artists/page.tsx @@ -1,14 +1,11 @@ -"use client" - -import { useQuery } from "convex/react" - +import { fetchQuery } from "convex/nextjs" import { ArtistsView } from "@/components/artists-view" import { LibraryLoading } from "@/components/library-loading" import { api } from "@/convex/_generated/api" -export default function Page() { - const artists = useQuery(api.library.browseArtists) - const albums = useQuery(api.library.browseAlbums) +export default async function Page() { + const artists = await fetchQuery(api.library.browseArtists) + const albums = await fetchQuery(api.library.browseAlbums) return (
diff --git a/app/(app)/playlist/[id]/page.tsx b/app/(app)/playlist/[id]/page.tsx index 45cb4c9..1571149 100644 --- a/app/(app)/playlist/[id]/page.tsx +++ b/app/(app)/playlist/[id]/page.tsx @@ -3,11 +3,32 @@ import { PlaylistView } from "@/components/playlist-view" 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 }> } +export async function generateMetadata({ + params, +}: PageProps): Promise { + const { id } = await params + const playlist = await fetchQuery(api.playlists.browsePlaylistDetail, { + id: id as Id<"playlists">, + }) + + return { + title: `${playlist ? `${playlist.title} - oTunes` : "oTunes"}`, + openGraph: { + title: `${playlist ? `${playlist.title} - oTunes` : "oTunes"}`, + description: `${playlist ? playlist.owner : null}`, + 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 fetchQuery(api.playlists.browsePlaylistDetail, { @@ -32,16 +53,5 @@ export default async function Page({ params }: PageProps) { ) } - return ( - <> - {`${playlist.title} - oTunes`} - - - - - - ) + return } diff --git a/app/layout.tsx b/app/layout.tsx index 4453162..6ca61b6 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -18,6 +18,7 @@ const fontMono = Geist_Mono({ export const metadata: Metadata = { title: "oTunes", description: "Our Music", + metadataBase: new URL(process.env.HOSTED_URL || "http://localhost:3000"), } export default function RootLayout({ diff --git a/components/artists-view.tsx b/components/artists-view.tsx index 9713ec7..079736b 100644 --- a/components/artists-view.tsx +++ b/components/artists-view.tsx @@ -32,6 +32,7 @@ function ArtistAvatar({ artist }: { artist: BrowseArtist }) { src={artistCoverUrl(artist.id)} alt={artist.name} fill + sizes="(max-width: 256px) 100vw, (max-width: 1024px) 50vw, 33vw" className="object-cover" />
@@ -150,119 +151,100 @@ export function ArtistsView({ } return ( - <> - {`${selectedArtist && artistId ? `${selectedArtist.name} - oTunes` : "oTunes"}`} - - - -
- -
- {sortedArtists.map((artist) => ( - router.push(`/library/artists/${artist.id}`)} - onMediaAction={(action) => - void handleMediaAction(artist.id, action) - } - /> - ))} -
-
+
+ +
+ {sortedArtists.map((artist) => ( + router.push(`/library/artists/${artist.id}`)} + onMediaAction={(action) => + void handleMediaAction(artist.id, action) + } + /> + ))} +
+
- - {selectedArtist ? ( -
-
- + {selectedArtist ? ( +
+
+ + {selectedArtist.name} + + + +
+ - - - void toggleArtistFavorite( - selectedArtist.id as Id<"artists"> - ) - } - favoritedLabel={`Remove ${selectedArtist.name} from favorites`} - unfavoritedLabel={`Favorite ${selectedArtist.name}`} - /> - {}} - onAction={(action) => - void handleMediaAction(selectedArtist.id, action) - } - favorited={isArtistFavorite(selectedArtist.id)} - trackRowTrigger={false} - triggerVariant="secondary" - triggerClassName="rounded-full" - /> -
-
- -
- {artistAlbums.length > 0 ? ( -
- {artistAlbums.map((album) => ( - - ))} -
- ) : ( -

- No albums for this artist. -

- )} + + + + + void toggleArtistFavorite( + selectedArtist.id as Id<"artists"> + ) + } + favoritedLabel={`Remove ${selectedArtist.name} from favorites`} + unfavoritedLabel={`Favorite ${selectedArtist.name}`} + /> + {}} + onAction={(action) => + void handleMediaAction(selectedArtist.id, action) + } + favorited={isArtistFavorite(selectedArtist.id)} + trackRowTrigger={false} + triggerVariant="secondary" + triggerClassName="rounded-full" + />
- ) : null} - -
- + +
+ {artistAlbums.length > 0 ? ( +
+ {artistAlbums.map((album) => ( + + ))} +
+ ) : ( +

+ No albums for this artist. +

+ )} +
+
+ ) : null} +
+
) }