Files
silo-server/web/src/pages/LibraryCollections.tsx
T
88aa769fe6 feat(collections): surface server collections on the user Collections tab (#156)
* feat(collections): surface server collections on the user Collections tab

The user-facing Collections tab only showed personal collections, which are
usually empty — leaving most users with a confusingly blank page. Server
(admin-curated) collections were reachable only inside each individual
library's tab.

Add a new GET /collections/server endpoint that aggregates visible library
collections across every accessible library (honoring access scope, capped per
library with a total_count for a See all link), and restructure Collections.tsx
into two titled sections: Your collections (personal) and Server collections
(horizontal teaser rows per library, linking into each library's Collections
tab). Extract the shared CollectionPosterCard so the per-library grid and the
new rows share one implementation.

* fix(collections): match server-collections loading skeleton to row layout

The Server collections section renders as one horizontal teaser row per
library, but the loading skeleton showed a poster grid — so data arriving
visibly reflowed the page from a grid into rows. Mirror the final layout
(section header + per-library rows of poster cards) in the skeleton, and
drop the now-unused COLLECTION_POSTER_GRID_CLASSES import.

Addresses CodeRabbit review comment on PR #156.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Align server collections with shared carousel behavior

- Add opt-out edge padding to reusable media carousels
- Render server collection rows with shared carousel controls and spacing

---------

Co-authored-by: Quick <31828688+Quick104@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 10:51:12 -04:00

133 lines
4.1 KiB
TypeScript

import type { LibraryTabCollection, LibraryTabGroup, LibraryTabUngrouped } from "@/api/types";
import { useLibraryCollections } from "@/hooks/queries/libraryCollections";
import { Card, CardContent } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
import {
COLLECTION_POSTER_GRID_CLASSES as GRID_CLASSES,
CollectionPosterCard,
} from "@/components/collections/CollectionPosterCard";
interface LibraryCollectionsProps {
libraryId: number;
}
export default function LibraryCollections({ libraryId }: LibraryCollectionsProps) {
const { data, isLoading } = useLibraryCollections(libraryId);
if (isLoading) {
return (
<div className="page-shell py-6 sm:py-8">
<div className={GRID_CLASSES}>
{Array.from({ length: 24 }, (_, i) => (
<div key={i}>
<Skeleton className="aspect-[2/3] rounded-lg" />
<Skeleton className="mt-2 h-4 w-3/4" />
</div>
))}
</div>
</div>
);
}
const groups = data?.groups ?? [];
const ungroupedData = data?.ungrouped ?? null;
const ungrouped = ungroupedData?.collections ?? [];
if (groups.length === 0 && ungrouped.length === 0) {
return (
<div className="page-shell py-6 sm:py-8">
<Card className="surface-panel overflow-hidden rounded-[2rem] border-0 shadow-none">
<CardContent className="py-10 text-center">
<p className="text-lg font-semibold">No collections yet</p>
<p className="text-muted-foreground mt-2 text-sm">
Create library collections from the admin area to feature curated shelves here.
</p>
</CardContent>
</Card>
</div>
);
}
return (
<div className="page-shell space-y-6 py-6 sm:py-8">
<div className="page-header gap-5">
<div className="space-y-3">
<h1 className="page-title text-[clamp(2rem,4vw,3rem)]">Collections</h1>
<p className="page-subtitle text-sm sm:text-base">
Browse hand-picked shelves and smart lists created for this library.
</p>
</div>
</div>
<div className="space-y-8">
{buildRenderOrder(groups, ungroupedData).map((item) =>
item.kind === "ungrouped" ? (
<UngroupedGroupSection
key="ungrouped"
collections={item.collections}
libraryId={libraryId}
/>
) : (
<GroupSection key={item.group.id} group={item.group} libraryId={libraryId} />
),
)}
</div>
</div>
);
}
// Build a unified render order from groups + (optional) ungrouped, sorted by
// each item's effective sort position.
type RenderItem =
| { kind: "group"; group: LibraryTabGroup }
| { kind: "ungrouped"; collections: LibraryTabCollection[] };
function buildRenderOrder(
groups: LibraryTabGroup[],
ungroupedData: LibraryTabUngrouped | null,
): RenderItem[] {
type Slot = { order: number; item: RenderItem };
const slots: Slot[] = groups.map((g) => ({
order: g.sort_order,
item: { kind: "group" as const, group: g },
}));
if (ungroupedData && ungroupedData.collections.length > 0) {
slots.push({
order: ungroupedData.sort_order,
item: { kind: "ungrouped" as const, collections: ungroupedData.collections },
});
}
slots.sort((a, b) => a.order - b.order);
return slots.map((s) => s.item);
}
function UngroupedGroupSection({
collections,
libraryId,
}: {
collections: LibraryTabCollection[];
libraryId: number;
}) {
return (
<section>
<div className={GRID_CLASSES}>
{collections.map((c) => (
<CollectionPosterCard key={c.id} collection={c} kind="regular" libraryId={libraryId} />
))}
</div>
</section>
);
}
function GroupSection({ group, libraryId }: { group: LibraryTabGroup; libraryId: number }) {
return (
<section>
<h2 className="mb-3 text-lg font-semibold">{group.name}</h2>
<div className={GRID_CLASSES}>
{group.collections.map((c) => (
<CollectionPosterCard key={c.id} collection={c} kind={group.kind} libraryId={libraryId} />
))}
</div>
</section>
);
}