diff --git a/apps/web/app/(app)/(home)/loading.tsx b/apps/web/app/(app)/(home)/loading.tsx new file mode 100644 index 0000000..1c563ef --- /dev/null +++ b/apps/web/app/(app)/(home)/loading.tsx @@ -0,0 +1,10 @@ +import { HomeSkeleton, PageHeader } from "@/components/library-skeletons" + +export default function Loading() { + return ( +
+ + +
+ ) +} diff --git a/apps/web/app/(app)/(home)/page.tsx b/apps/web/app/(app)/(home)/page.tsx new file mode 100644 index 0000000..fa3adf3 --- /dev/null +++ b/apps/web/app/(app)/(home)/page.tsx @@ -0,0 +1,42 @@ +"use client" + +import { ContentCarousel } from "@/components/content-carousel" +import { HomeSkeleton, PageHeader } from "@/components/library-skeletons" +import { useCachedQuery } from "@/hooks/use-cached-query" +import { api } from "@otunes/convex/_generated/api" + +export default function Page() { + const recentlyAdded = useCachedQuery(api.library.browseRecentlyAdded, { + limit: 9, + }) + const recentlyPlayed = useCachedQuery(api.library.browseRecentlyPlayed, { + limit: 9, + }) + + return ( +
+ + + {recentlyAdded === undefined || recentlyPlayed === undefined ? ( + + ) : ( +
+
+ {recentlyPlayed.length > 0 ? ( + + ) : null} + +
+
+ )} +
+ ) +} diff --git a/apps/web/app/(app)/album/[id]/loading.tsx b/apps/web/app/(app)/album/[id]/loading.tsx index 83cc615..9be4aad 100644 --- a/apps/web/app/(app)/album/[id]/loading.tsx +++ b/apps/web/app/(app)/album/[id]/loading.tsx @@ -1,9 +1,5 @@ -import { LibraryLoading } from "@/components/library-loading" +import { CollectionDetailSkeleton } from "@/components/library-skeletons" export default function Loading() { - return ( -
- -
- ) + return } diff --git a/apps/web/app/(app)/album/[id]/page.tsx b/apps/web/app/(app)/album/[id]/page.tsx index 2bf014f..95fef40 100644 --- a/apps/web/app/(app)/album/[id]/page.tsx +++ b/apps/web/app/(app)/album/[id]/page.tsx @@ -1,5 +1,4 @@ -import { AlbumView } from "@/components/album-view" -import { LibraryLoading } from "@/components/library-loading" +import { AlbumPage } from "@/components/album-page" import { api } from "@otunes/convex/_generated/api" import { fetchQuery } from "convex/nextjs" import { convexServerOptions } from "@/lib/convex-server" @@ -49,29 +48,15 @@ export async function generateMetadata({ } export default async function Page({ params, searchParams }: PageProps) { - const { id } = await params - const [{ s: highlightedSongId }, album] = await Promise.all([ + const [{ id }, { s: highlightedSongId }] = await Promise.all([ + params, searchParams, - fetchAlbumDetail(id as Id<"albums">), ]) - if (album === undefined) { - return ( -
- -
- ) - } - - if (album === null) { - return ( -
-
-

Album not found.

-
-
- ) - } - - return + return ( + } + highlightedSongId={highlightedSongId} + /> + ) } diff --git a/apps/web/app/(app)/artist/[id]/loading.tsx b/apps/web/app/(app)/artist/[id]/loading.tsx index 83cc615..21d05f6 100644 --- a/apps/web/app/(app)/artist/[id]/loading.tsx +++ b/apps/web/app/(app)/artist/[id]/loading.tsx @@ -1,9 +1,5 @@ -import { LibraryLoading } from "@/components/library-loading" +import { ArtistDetailSkeleton } from "@/components/library-skeletons" export default function Loading() { - return ( -
- -
- ) + return } diff --git a/apps/web/app/(app)/artist/[id]/page.tsx b/apps/web/app/(app)/artist/[id]/page.tsx index 7f66d42..ecd256a 100644 --- a/apps/web/app/(app)/artist/[id]/page.tsx +++ b/apps/web/app/(app)/artist/[id]/page.tsx @@ -1,7 +1,6 @@ import { fetchQuery } from "convex/nextjs" import { convexServerOptions } from "@/lib/convex-server" -import { ArtistView } from "@/components/artist-view" -import { LibraryLoading } from "@/components/library-loading" +import { ArtistPage } from "@/components/artist-page" import { api } from "@otunes/convex/_generated/api" import type { Id } from "@otunes/convex/_generated/dataModel" import { Metadata } from "next" @@ -39,25 +38,5 @@ export async function generateMetadata({ export default async function Page({ params }: PageProps) { const { id } = await params - const data = await fetchArtistDetail(id as Id<"artists">) - - if (data === undefined) { - return ( -
- -
- ) - } - - if (data === null) { - return ( -
-
-

Artist not found.

-
-
- ) - } - - return + return } /> } diff --git a/apps/web/app/(app)/library/albums/loading.tsx b/apps/web/app/(app)/library/albums/loading.tsx new file mode 100644 index 0000000..499135b --- /dev/null +++ b/apps/web/app/(app)/library/albums/loading.tsx @@ -0,0 +1,10 @@ +import { CardGridSkeleton, PageHeader } from "@/components/library-skeletons" + +export default function Loading() { + return ( +
+ + +
+ ) +} diff --git a/apps/web/app/(app)/library/albums/page.tsx b/apps/web/app/(app)/library/albums/page.tsx index fad5086..f4d361f 100644 --- a/apps/web/app/(app)/library/albums/page.tsx +++ b/apps/web/app/(app)/library/albums/page.tsx @@ -1,25 +1,23 @@ "use client" -import { useQuery } from "convex/react" - import { AlbumCard } from "@/components/album-card" -import { LibraryLoading } from "@/components/library-loading" +import { CardGridSkeleton, PageHeader } from "@/components/library-skeletons" +import { useCachedQuery } from "@/hooks/use-cached-query" +import { albumGridClassName } from "@/lib/album-grid-classes" import { api } from "@otunes/convex/_generated/api" export default function Page() { - const albums = useQuery(api.library.browseAlbums) + const albums = useCachedQuery(api.library.browseAlbums) return (
-
-

Albums

-
+ {albums === undefined ? ( - + ) : (
-
+
{albums.map((album) => ( ))} diff --git a/apps/web/app/(app)/library/artists/[id]/page.tsx b/apps/web/app/(app)/library/artists/[id]/page.tsx index fd2a55f..289e0e2 100644 --- a/apps/web/app/(app)/library/artists/[id]/page.tsx +++ b/apps/web/app/(app)/library/artists/[id]/page.tsx @@ -1,23 +1,21 @@ import { fetchQuery } from "convex/nextjs" import { convexServerOptions } from "@/lib/convex-server" -import { ArtistsView } from "@/components/artists-view" import { api } from "@otunes/convex/_generated/api" import { Metadata } from "next" -import { cache } from "react" interface PageProps { params: Promise<{ id: string }> } -const fetchArtists = cache(() => - fetchQuery(api.library.browseArtists, {}, convexServerOptions()) -) - export async function generateMetadata({ params, }: PageProps): Promise { const { id } = await params - const artists = await fetchArtists() + const artists = await fetchQuery( + api.library.browseArtists, + {}, + convexServerOptions() + ) const selectedArtist = artists.find((artist) => artist.id === id) return { @@ -36,19 +34,6 @@ export async function generateMetadata({ } } -export default async function Page({ params }: PageProps) { - const { id } = await params - const [artists, albums] = await Promise.all([ - fetchArtists(), - fetchQuery(api.library.browseAlbums, {}, convexServerOptions()), - ]) - - return ( -
-
-

Artists

-
- -
- ) +export default function Page() { + return null } diff --git a/apps/web/app/(app)/library/artists/layout.tsx b/apps/web/app/(app)/library/artists/layout.tsx new file mode 100644 index 0000000..2b6bda0 --- /dev/null +++ b/apps/web/app/(app)/library/artists/layout.tsx @@ -0,0 +1,14 @@ +import { ArtistsPage } from "@/components/artists-page" + +export default function ArtistsLayout({ + children, +}: Readonly<{ + children: React.ReactNode +}>) { + return ( + <> + + {children} + + ) +} diff --git a/apps/web/app/(app)/library/artists/loading.tsx b/apps/web/app/(app)/library/artists/loading.tsx new file mode 100644 index 0000000..5cfefc8 --- /dev/null +++ b/apps/web/app/(app)/library/artists/loading.tsx @@ -0,0 +1,7 @@ +/** + * The artists UI lives in the layout and renders from the client cache, so + * navigations only need this (empty) boundary to commit. + */ +export default function Loading() { + return null +} diff --git a/apps/web/app/(app)/library/artists/page.tsx b/apps/web/app/(app)/library/artists/page.tsx index be43b08..c174313 100644 --- a/apps/web/app/(app)/library/artists/page.tsx +++ b/apps/web/app/(app)/library/artists/page.tsx @@ -1,26 +1,3 @@ -import { fetchQuery } from "convex/nextjs" -import { convexServerOptions } from "@/lib/convex-server" -import { ArtistsView } from "@/components/artists-view" -import { LibraryLoading } from "@/components/library-loading" -import { api } from "@otunes/convex/_generated/api" - -export default async function Page() { - const [artists, albums] = await Promise.all([ - fetchQuery(api.library.browseArtists, {}, convexServerOptions()), - fetchQuery(api.library.browseAlbums, {}, convexServerOptions()), - ]) - - return ( -
-
-

Artists

-
- - {artists === undefined || albums === undefined ? ( - - ) : ( - - )} -
- ) +export default function Page() { + return null } diff --git a/apps/web/app/(app)/library/songs/loading.tsx b/apps/web/app/(app)/library/songs/loading.tsx new file mode 100644 index 0000000..a32a1d8 --- /dev/null +++ b/apps/web/app/(app)/library/songs/loading.tsx @@ -0,0 +1,10 @@ +import { PageHeader, SongListSkeleton } from "@/components/library-skeletons" + +export default function Loading() { + return ( +
+ + +
+ ) +} diff --git a/apps/web/app/(app)/page.tsx b/apps/web/app/(app)/page.tsx deleted file mode 100644 index cdb5ca4..0000000 --- a/apps/web/app/(app)/page.tsx +++ /dev/null @@ -1,50 +0,0 @@ -"use client" - -import { useQuery } from "convex/react" - -import { ContentCarousel } from "@/components/content-carousel" -import { LibraryLoading } from "@/components/library-loading" -import { api } from "@otunes/convex/_generated/api" - -export default function Page() { - const recentlyAdded = useQuery(api.library.browseRecentlyAdded, { limit: 9 }) - const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed, { - limit: 9, - }) - - if (recentlyAdded === undefined || recentlyPlayed === undefined) { - return ( -
-
-

Home

-
- -
- ) - } - - return ( -
-
-

Home

-
- -
-
- {recentlyPlayed.length > 0 ? ( - - ) : null} - -
-
-
- ) -} diff --git a/apps/web/app/(app)/playlist/[id]/loading.tsx b/apps/web/app/(app)/playlist/[id]/loading.tsx new file mode 100644 index 0000000..9be4aad --- /dev/null +++ b/apps/web/app/(app)/playlist/[id]/loading.tsx @@ -0,0 +1,5 @@ +import { CollectionDetailSkeleton } from "@/components/library-skeletons" + +export default function Loading() { + return +} diff --git a/apps/web/app/(app)/playlist/[id]/page.tsx b/apps/web/app/(app)/playlist/[id]/page.tsx index b6a189d..ab5d59d 100644 --- a/apps/web/app/(app)/playlist/[id]/page.tsx +++ b/apps/web/app/(app)/playlist/[id]/page.tsx @@ -1,5 +1,4 @@ -import { LibraryLoading } from "@/components/library-loading" -import { PlaylistView } from "@/components/playlist-view" +import { PlaylistPage } from "@/components/playlist-page" import { api } from "@otunes/convex/_generated/api" import { convexAuthNextjsToken } from "@convex-dev/auth/nextjs/server" import { fetchQuery } from "convex/nextjs" @@ -41,25 +40,5 @@ export async function generateMetadata({ export default async function Page({ params }: PageProps) { const { id } = await params - const playlist = await fetchPlaylistDetail(id as Id<"playlists">) - - if (playlist === undefined) { - return ( -
- -
- ) - } - - if (playlist === null) { - return ( -
-
-

Playlist not found.

-
-
- ) - } - - return + return } /> } diff --git a/apps/web/app/(app)/playlist/favorites/loading.tsx b/apps/web/app/(app)/playlist/favorites/loading.tsx new file mode 100644 index 0000000..9be4aad --- /dev/null +++ b/apps/web/app/(app)/playlist/favorites/loading.tsx @@ -0,0 +1,5 @@ +import { CollectionDetailSkeleton } from "@/components/library-skeletons" + +export default function Loading() { + return +} diff --git a/apps/web/app/(app)/playlist/favorites/page.tsx b/apps/web/app/(app)/playlist/favorites/page.tsx index 7f5d2cc..30da0f0 100644 --- a/apps/web/app/(app)/playlist/favorites/page.tsx +++ b/apps/web/app/(app)/playlist/favorites/page.tsx @@ -1,33 +1,7 @@ "use client" -import { useQuery } from "convex/react" - -import { LibraryLoading } from "@/components/library-loading" -import { PlaylistView } from "@/components/playlist-view" -import { api } from "@otunes/convex/_generated/api" +import { FavoritesPlaylistPage } from "@/components/playlist-page" export default function Page() { - const favorites = useQuery(api.favorites.browseFavoritesPlaylistDetail) - - if (favorites === undefined) { - return ( -
- -
- ) - } - - if (favorites === null) { - return ( -
-
-

- Sign in to view your favorites. -

-
-
- ) - } - - return + return } diff --git a/apps/web/app/(app)/playlists/loading.tsx b/apps/web/app/(app)/playlists/loading.tsx new file mode 100644 index 0000000..6984ca8 --- /dev/null +++ b/apps/web/app/(app)/playlists/loading.tsx @@ -0,0 +1,10 @@ +import { CardGridSkeleton, PageHeader } from "@/components/library-skeletons" + +export default function Loading() { + return ( +
+ + +
+ ) +} diff --git a/apps/web/app/(app)/playlists/page.tsx b/apps/web/app/(app)/playlists/page.tsx index e7e8095..9bbdf08 100644 --- a/apps/web/app/(app)/playlists/page.tsx +++ b/apps/web/app/(app)/playlists/page.tsx @@ -1,16 +1,17 @@ "use client" -import { useQuery } from "convex/react" import { Plus } from "lucide-react" import { useAddToPlaylist } from "@/components/add-to-playlist-provider" -import { LibraryLoading } from "@/components/library-loading" +import { CardGridSkeleton } from "@/components/library-skeletons" import { PlaylistCard } from "@/components/playlist-card" import { Button } from "@/components/ui/button" +import { useCachedQuery } from "@/hooks/use-cached-query" +import { albumGridClassName } from "@/lib/album-grid-classes" import { api } from "@otunes/convex/_generated/api" export default function Page() { - const playlists = useQuery(api.playlists.listAllPlaylists) + const playlists = useCachedQuery(api.playlists.listAllPlaylists) const { openCreatePlaylist } = useAddToPlaylist() return ( @@ -29,10 +30,10 @@ export default function Page() { {playlists === undefined ? ( - + ) : (
-
+
{playlists.map((playlist) => ( ))} diff --git a/apps/web/app/(app)/recently-added/loading.tsx b/apps/web/app/(app)/recently-added/loading.tsx new file mode 100644 index 0000000..83c4536 --- /dev/null +++ b/apps/web/app/(app)/recently-added/loading.tsx @@ -0,0 +1,10 @@ +import { CardGridSkeleton, PageHeader } from "@/components/library-skeletons" + +export default function Loading() { + return ( +
+ + +
+ ) +} diff --git a/apps/web/app/(app)/recently-added/page.tsx b/apps/web/app/(app)/recently-added/page.tsx index 4ae988c..919d85d 100644 --- a/apps/web/app/(app)/recently-added/page.tsx +++ b/apps/web/app/(app)/recently-added/page.tsx @@ -1,25 +1,23 @@ "use client" -import { useQuery } from "convex/react" - import { AlbumCard } from "@/components/album-card" -import { LibraryLoading } from "@/components/library-loading" +import { CardGridSkeleton, PageHeader } from "@/components/library-skeletons" +import { useCachedQuery } from "@/hooks/use-cached-query" +import { albumGridClassName } from "@/lib/album-grid-classes" import { api } from "@otunes/convex/_generated/api" export default function Page() { - const albums = useQuery(api.library.browseRecentlyAdded, {}) + const albums = useCachedQuery(api.library.browseRecentlyAdded, {}) return (
-
-

Recently Added

-
+ {albums === undefined ? ( - + ) : (
-
+
{albums.map((album) => ( ))} diff --git a/apps/web/app/(app)/recently-played/loading.tsx b/apps/web/app/(app)/recently-played/loading.tsx new file mode 100644 index 0000000..b4e0f1e --- /dev/null +++ b/apps/web/app/(app)/recently-played/loading.tsx @@ -0,0 +1,10 @@ +import { CardGridSkeleton, PageHeader } from "@/components/library-skeletons" + +export default function Loading() { + return ( +
+ + +
+ ) +} diff --git a/apps/web/app/(app)/recently-played/page.tsx b/apps/web/app/(app)/recently-played/page.tsx index 3fd0a4f..23d6d06 100644 --- a/apps/web/app/(app)/recently-played/page.tsx +++ b/apps/web/app/(app)/recently-played/page.tsx @@ -1,10 +1,10 @@ "use client" -import { useQuery } from "convex/react" - import { AlbumCard } from "@/components/album-card" -import { LibraryLoading } from "@/components/library-loading" +import { CardGridSkeleton, PageHeader } from "@/components/library-skeletons" import { PlaylistCard } from "@/components/playlist-card" +import { useCachedQuery } from "@/hooks/use-cached-query" +import { albumGridClassName } from "@/lib/album-grid-classes" import { api } from "@otunes/convex/_generated/api" import type { BrowseAlbum, PlaylistSummary } from "@otunes/convex/types" @@ -20,16 +20,14 @@ function RecentlyPlayedCard({ } export default function Page() { - const recentlyPlayed = useQuery(api.library.browseRecentlyPlayed, {}) + const recentlyPlayed = useCachedQuery(api.library.browseRecentlyPlayed, {}) return (
-
-

Recently Played

-
+ {recentlyPlayed === undefined ? ( - + ) : recentlyPlayed.length === 0 ? (

@@ -38,7 +36,7 @@ export default function Page() {

) : (
-
+
{recentlyPlayed.map((item) => ( ))} diff --git a/apps/web/app/(app)/search/loading.tsx b/apps/web/app/(app)/search/loading.tsx new file mode 100644 index 0000000..143c211 --- /dev/null +++ b/apps/web/app/(app)/search/loading.tsx @@ -0,0 +1,13 @@ +import { SearchResultsSkeleton } from "@/components/library-skeletons" +import { Skeleton } from "@/components/ui/skeleton" + +export default function Loading() { + return ( +
+
+ +
+ +
+ ) +} diff --git a/apps/web/app/(app)/search/page.tsx b/apps/web/app/(app)/search/page.tsx index ae5874a..2906365 100644 --- a/apps/web/app/(app)/search/page.tsx +++ b/apps/web/app/(app)/search/page.tsx @@ -1,14 +1,14 @@ "use client" import { Suspense, useCallback, useEffect, useRef, useState } from "react" -import { useQuery } from "convex/react" import { SearchIcon } from "lucide-react" import { usePathname, useSearchParams } from "next/navigation" import { ContentCarousel } from "@/components/content-carousel" -import { LibraryLoading } from "@/components/library-loading" +import { SearchResultsSkeleton } from "@/components/library-skeletons" import { SearchSongItem } from "@/components/search-song-item" import { SearchTopResultCard, type TopResult } from "@/components/search-top-result-card" +import { useCachedQuery } from "@/hooks/use-cached-query" import { api } from "@otunes/convex/_generated/api" const SEARCH_DEBOUNCE_MS = 300 @@ -30,11 +30,11 @@ function readUrlQuery() { function SearchResults({ query }: { query: string }) { const hasQuery = query.length > 0 - const results = useQuery( + const results = useCachedQuery( api.library.searchLibrary, hasQuery ? { query } : "skip" ) - const playlistResults = useQuery( + const playlistResults = useCachedQuery( api.playlists.searchPlaylists, hasQuery ? { query } : "skip" ) @@ -51,7 +51,7 @@ function SearchResults({ query }: { query: string }) { const showResults = hasQuery && results !== undefined if (isSearching) { - return + return } if (!hasQuery) { @@ -239,7 +239,7 @@ function SearchPageContent() { export default function Page() { return ( - }> + }> ) diff --git a/apps/web/components/add-to-playlist-provider.tsx b/apps/web/components/add-to-playlist-provider.tsx index abdfb8d..abfa338 100644 --- a/apps/web/components/add-to-playlist-provider.tsx +++ b/apps/web/components/add-to-playlist-provider.tsx @@ -6,6 +6,7 @@ import { useRouter } from "next/navigation" import { ListMusic, Plus } from "lucide-react" import { toast } from "sonner" +import { useCacheScope } from "@/components/persistent-cache-provider" import { Button } from "@/components/ui/button" import { Dialog, @@ -19,6 +20,7 @@ import { Input } from "@/components/ui/input" import { ScrollArea } from "@/components/ui/scroll-area" import { api } from "@otunes/convex/_generated/api" import type { Id } from "@otunes/convex/_generated/dataModel" +import { fetchCachedQuery } from "@/lib/cached-query" function countSongsToAdd( playlistSongIds: Id<"songs">[], @@ -80,6 +82,7 @@ export function AddToPlaylistProvider({ children: React.ReactNode }) { const convex = useConvex() + const cacheScope = useCacheScope() const router = useRouter() const addSongs = useMutation(api.playlists.addSongsToPlaylist) const createPlaylist = useMutation(api.playlists.createPlaylist) @@ -117,9 +120,14 @@ export function AddToPlaylistProvider({ async (albumId: Id<"albums">) => { const requestId = ++selectionRequestRef.current try { - const songIds = await convex.query(api.playlists.getAlbumSongIds, { - albumId, - }) + const songIds = await fetchCachedQuery( + convex, + cacheScope, + api.playlists.getAlbumSongIds, + { + albumId, + } + ) if (requestId === selectionRequestRef.current) { showAddToPlaylist(songIds) } @@ -131,16 +139,21 @@ export function AddToPlaylistProvider({ } } }, - [convex, showAddToPlaylist] + [convex, cacheScope, showAddToPlaylist] ) const openAddPlaylistToPlaylist = React.useCallback( async (playlistId: Id<"playlists">) => { const requestId = ++selectionRequestRef.current try { - const songIds = await convex.query(api.playlists.getPlaylistSongIds, { - playlistId, - }) + const songIds = await fetchCachedQuery( + convex, + cacheScope, + api.playlists.getPlaylistSongIds, + { + playlistId, + } + ) if (requestId === selectionRequestRef.current) { showAddToPlaylist(songIds) } @@ -152,16 +165,21 @@ export function AddToPlaylistProvider({ } } }, - [convex, showAddToPlaylist] + [convex, cacheScope, showAddToPlaylist] ) const openAddArtistToPlaylist = React.useCallback( async (artistId: Id<"artists">) => { const requestId = ++selectionRequestRef.current try { - const songIds = await convex.query(api.playlists.getArtistSongIds, { - artistId, - }) + const songIds = await fetchCachedQuery( + convex, + cacheScope, + api.playlists.getArtistSongIds, + { + artistId, + } + ) if (requestId === selectionRequestRef.current) { showAddToPlaylist(songIds) } @@ -173,7 +191,7 @@ export function AddToPlaylistProvider({ } } }, - [convex, showAddToPlaylist] + [convex, cacheScope, showAddToPlaylist] ) const openCreatePlaylist = React.useCallback(() => { diff --git a/apps/web/components/album-card.tsx b/apps/web/components/album-card.tsx index 1b044f3..abad4fb 100644 --- a/apps/web/components/album-card.tsx +++ b/apps/web/components/album-card.tsx @@ -6,6 +6,7 @@ import Link from "next/link" import { MoreHorizontal, Play } from "lucide-react" import { useConvex } from "convex/react" +import { useCacheScope } from "@/components/persistent-cache-provider" import { useAddToPlaylist } from "@/components/add-to-playlist-provider" import { useFavorites } from "@/components/favorites-provider" import { @@ -25,6 +26,7 @@ import type { BrowseAlbum } from "@otunes/convex/types" import type { Id } from "@otunes/convex/_generated/dataModel" import { albumCoverUrl } from "@/lib/cover-urls" import { cn } from "@/lib/utils" +import { fetchCachedQuery } from "@/lib/cached-query" let activeAlbumCardMenuClose: (() => void) | null = null @@ -43,6 +45,7 @@ function closeExclusiveAlbumCardMenu(closeMenu: () => void) { export function AlbumCard({ album }: { album: BrowseAlbum }) { const convex = useConvex() + const cacheScope = useCacheScope() const { openAddAlbumToPlaylist } = useAddToPlaylist() const { isAlbumFavorite, toggleAlbumFavorite } = useFavorites() const { playAlbum } = usePlayback() @@ -77,9 +80,14 @@ export function AlbumCard({ album }: { album: BrowseAlbum }) { case "play-next": case "play-last": case "shuffle": { - const songIds = await convex.query(api.playlists.getAlbumSongIds, { - albumId: album.id as Id<"albums">, - }) + const songIds = await fetchCachedQuery( + convex, + cacheScope, + api.playlists.getAlbumSongIds, + { + albumId: album.id as Id<"albums">, + } + ) void runQueueAction(action, songIds) break } diff --git a/apps/web/components/album-page.tsx b/apps/web/components/album-page.tsx new file mode 100644 index 0000000..f0c083b --- /dev/null +++ b/apps/web/components/album-page.tsx @@ -0,0 +1,34 @@ +"use client" + +import { AlbumView } from "@/components/album-view" +import { CollectionDetailSkeleton } from "@/components/library-skeletons" +import { PageMessage } from "@/components/page-message" +import { useCachedQuery } from "@/hooks/use-cached-query" +import { api } from "@otunes/convex/_generated/api" +import type { Id } from "@otunes/convex/_generated/dataModel" + +export function AlbumPage({ + albumId, + highlightedSongId, +}: { + albumId: Id<"albums"> + highlightedSongId?: string +}) { + const album = useCachedQuery(api.library.browseAlbumDetail, { id: albumId }) + + if (album === undefined) { + return + } + + if (album === null) { + return Album not found. + } + + return ( + + ) +} diff --git a/apps/web/components/album-view.tsx b/apps/web/components/album-view.tsx index aa0ed38..2ac3df5 100644 --- a/apps/web/components/album-view.tsx +++ b/apps/web/components/album-view.tsx @@ -39,6 +39,7 @@ import { } from "@/lib/selection-range-styles" import { albumCoverUrl } from "@/lib/cover-urls" import { sumDurationSeconds } from "@/lib/media-summary" +import { albumDetailSongs, rememberSongs } from "@/lib/song-cache" function formatDuration(seconds: number): string { const minutes = Math.floor(seconds / 60) @@ -269,6 +270,11 @@ export function AlbumView({ () => album.tracks.map((track) => track.id as Id<"songs">), [album.tracks] ) + + React.useEffect(() => { + rememberSongs(albumDetailSongs(album)) + }, [album]) + const metadata = formatMetadata(album.genre, album.year) const [activeTrackId, setActiveTrackId] = React.useState("") const validHighlightedSongId = React.useMemo(() => { @@ -398,14 +404,21 @@ export function AlbumView({ size="icon" className="rounded-full" aria-label="Shuffle album" - onClick={() => void playAlbumShuffled(album.id as Id<"albums">)} + onClick={() => + void playAlbumShuffled( + album.id as Id<"albums">, + albumSongIds + ) + } >