v4: playlists sort by their last dump, their creation or their size, and /playlists is a grid of covers — every list of playlists came newest first, so one fed every week sank under those made since and left empty. GET /api/playlists and /api/users/:key/playlists take ?sort=updated|new|dumps (PLAYLIST_SORTS, shared/playlist.ts), updated being the default: the last to take a dump first, or its creation while it holds none; a new title, cover or description doesn't bring it back up. A playlist carries that date as lastDumpAt, read with its dumpCount by isMemberVisibleTo's rule (VISIBLE_DUMP_FIGURES, the viewer's id as ?1), so the owner's private dumps date and count their playlists for them alone, in the lists and over the socket: playlist_created, playlist_updated and playlist_dumps_updated carry each socket's own. The /playlists page and a profile's playlists tab show the orders as tabs beside the category menu and keep the one picked in ?sort=, the default being the bare path; a tab takes the current history entry's place, and picking a category keeps the order. Live, usePlaylistListSync takes the list's order: a new playlist goes where it puts it, one that rises moves up to its place, as in the updated order when it takes a dump, and one that falls stays until the list is fetched again, its place being perhaps on a page not loaded. The lists in an order of their own, the followed playlists and the search's, pass none, and take no new playlist as before (noNewEntries goes). comparePlaylists is the order on the client, which a test holds to the API's.
/playlists lays its cards out as tiles, the cover across the top, four to a row and two on a phone, on the wide column: the same PlaylistCard, laid out by its list's class (.playlist-grid), so each theme's card skin carries over. It drops the "public" badge there, every playlist listed being public. On every card, a playlist without a cover shows a tile of its own colour with its initial (ThumbnailPlaceholder) in place of the 📋, and the date is "updated …" of its last dump, or "created …". A middle, ctrl, cmd or shift click anywhere on a playlist card opens it in a new tab — only its title was a link, the rest navigating by a click handler. useCardLink (hooks/shared) is useDumpCardLink's handlers for any card, which the dump cards now get through it. A profile tab's query stays with the tab — going from the playlists to the dumps kept the whole query, so a playlist category, and now ?sort=, landed on the dumps' URL. Only the dump lists pass their category to each other; any other change of tab drops the query. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
/**
|
||||
* Renders every public playlist, `/playlists`, and those of one playlist
|
||||
* category, `/playlists/:categorySlug`, newest first.
|
||||
* category, `/playlists/:categorySlug`, in the order `?sort=` names.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { useCallback } from "react";
|
||||
import { useNavigate, useParams } from "react-router";
|
||||
import { useNavigate, useParams, useSearchParams } from "react-router";
|
||||
import { t } from "@lingui/core/macro";
|
||||
import { Trans } from "@lingui/react/macro";
|
||||
import { API_URL } from "../config/api.ts";
|
||||
import type { Playlist } from "../../shared/playlist.ts";
|
||||
import { playlistsPath } from "../../shared/paths.ts";
|
||||
import {
|
||||
parsePlaylistSort,
|
||||
type Playlist,
|
||||
type PlaylistSort,
|
||||
} from "../../shared/playlist.ts";
|
||||
import { playlistSortQuery, playlistsPath } from "../../shared/paths.ts";
|
||||
import { canLoadMore, pageUrl, readPage } from "../utils/feed/pagedList.ts";
|
||||
import {
|
||||
deserializePlaylist,
|
||||
@@ -34,18 +38,21 @@ import { PageShell } from "../components/layout/PageShell.tsx";
|
||||
import { PageHeader } from "../components/layout/PageHeader.tsx";
|
||||
import { CategorySwitcher } from "../components/category/CategorySwitcher.tsx";
|
||||
import { PlaylistCardList } from "../components/playlist/PlaylistCardList.tsx";
|
||||
import { PlaylistSortTabs } from "../components/playlist/PlaylistSortTabs.tsx";
|
||||
import { FeedFooter } from "../components/feed/FeedFooter.tsx";
|
||||
import { ListState } from "../components/shared/ListState.tsx";
|
||||
import { NotFound } from "./NotFound.tsx";
|
||||
|
||||
/**
|
||||
* Renders the list for the route's category, or every public playlist
|
||||
* without one. Each category's list is another, which the page mounts
|
||||
* afresh. A slug that names no playlist category, once the categories have
|
||||
* loaded, is a page not found.
|
||||
* without one, in the order of the URL's `?sort=`. Each category's list in
|
||||
* each order is another, which the page mounts afresh. A slug that names no
|
||||
* playlist category, once the categories have loaded, is a page not found.
|
||||
*/
|
||||
export function Playlists(): React.JSX.Element {
|
||||
const { categorySlug } = useParams();
|
||||
const [params] = useSearchParams();
|
||||
const sort = parsePlaylistSort(params.get("sort"));
|
||||
const { categories, isLoaded } = useCategories("playlist");
|
||||
const category = categorySlug
|
||||
? categories.find((c) => c.slug === categorySlug)
|
||||
@@ -55,31 +62,41 @@ export function Playlists(): React.JSX.Element {
|
||||
if (categorySlug && isLoaded && !category) return <NotFound />;
|
||||
return (
|
||||
<PlaylistsList
|
||||
key={categorySlug ?? ""}
|
||||
key={`${categorySlug ?? ""}:${sort}`}
|
||||
categorySlug={categorySlug}
|
||||
categoryId={category?.id}
|
||||
sort={sort}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the public playlists, from `GET /api/playlists`, a page at a time
|
||||
* as the list scrolls; with `categorySlug`, only those in that playlist
|
||||
* category, which the menu in the title row switches. The socket keeps them
|
||||
* live, a reconnection fetches the pages loaded again, and going back
|
||||
* restores the list and the scroll.
|
||||
* Renders the public playlists, from `GET /api/playlists`, as a grid of
|
||||
* covers, a page at a time as the list scrolls; with `categorySlug`, only
|
||||
* those in that playlist category, which the menu before the tabs switches,
|
||||
* keeping the order, while a tab changes the order in place of the current
|
||||
* history entry, as a feed's tabs do. The socket keeps them live, a
|
||||
* reconnection fetches the pages loaded again, and going back restores the
|
||||
* list and the scroll.
|
||||
*/
|
||||
function PlaylistsList(
|
||||
{ categorySlug, categoryId }: { categorySlug?: string; categoryId?: string },
|
||||
{ categorySlug, categoryId, sort }: {
|
||||
categorySlug?: string;
|
||||
categoryId?: string;
|
||||
sort: PlaylistSort;
|
||||
},
|
||||
) {
|
||||
const navigate = useNavigate();
|
||||
const { user, authFetch } = useAuth();
|
||||
const { cached, saveState } = useFeedCache<Playlist>(
|
||||
`feed:playlists:${categorySlug ?? "all"}`,
|
||||
`feed:playlists:${categorySlug ?? "all"}:${sort}`,
|
||||
hydratePlaylist,
|
||||
);
|
||||
const url = `${API_URL}/api/playlists${
|
||||
categorySlug ? `?category=${encodeURIComponent(categorySlug)}` : ""
|
||||
playlistSortQuery(
|
||||
sort,
|
||||
new URLSearchParams(categorySlug ? { category: categorySlug } : {}),
|
||||
)
|
||||
}`;
|
||||
const { state, setItems: setAllItems, loadMore, resync } = usePagedList<
|
||||
Playlist
|
||||
@@ -97,6 +114,7 @@ function PlaylistsList(
|
||||
usePlaylistListSync(
|
||||
loaded?.items ?? [],
|
||||
useCategoryFilter(setAllItems, categoryId),
|
||||
{ sort },
|
||||
);
|
||||
useOnReconnect(resync);
|
||||
|
||||
@@ -110,12 +128,19 @@ function PlaylistsList(
|
||||
useScrollRestore(cached?.scrollY, !!loaded);
|
||||
|
||||
return (
|
||||
<PageShell narrow>
|
||||
<PageShell>
|
||||
<PageHeader icon="📋" title={<Trans>Playlists</Trans>}>
|
||||
<CategorySwitcher
|
||||
kind="playlist"
|
||||
categorySlug={categorySlug}
|
||||
onSelect={(slug) => navigate(playlistsPath(slug))}
|
||||
<PlaylistSortTabs
|
||||
sort={sort}
|
||||
onChange={(s) =>
|
||||
navigate(playlistsPath(categorySlug, s), { replace: true })}
|
||||
leading={
|
||||
<CategorySwitcher
|
||||
kind="playlist"
|
||||
categorySlug={categorySlug}
|
||||
onSelect={(slug) => navigate(playlistsPath(slug, sort))}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</PageHeader>
|
||||
<ListState
|
||||
@@ -129,7 +154,7 @@ function PlaylistsList(
|
||||
>
|
||||
{({ data }) => (
|
||||
<>
|
||||
<PlaylistCardList playlists={data.items} />
|
||||
<PlaylistCardList playlists={data.items} grid privateBadgeOnly />
|
||||
<FeedFooter
|
||||
hasMore={data.hasMore}
|
||||
loadingMore={data.loadingMore}
|
||||
|
||||
Reference in New Issue
Block a user