Change animal index page
This commit is contained in:
@ -30,13 +30,6 @@ function sortArtworks(a: SimpleArtwork, b: SimpleArtwork) {
|
||||
}
|
||||
|
||||
export default async function AnimalListPage() {
|
||||
/**
|
||||
* We fetch all "animal page" tags and only artworks that are:
|
||||
* - published
|
||||
* - in "Animal Studies" category
|
||||
*
|
||||
* This makes the list reflect exactly what the user sees on the Animal Studies page.
|
||||
*/
|
||||
const tags = await prisma.artTag.findMany({
|
||||
where: { showOnAnimalPage: true },
|
||||
select: {
|
||||
@ -45,8 +38,6 @@ export default async function AnimalListPage() {
|
||||
slug: true,
|
||||
sortIndex: true,
|
||||
parentId: true,
|
||||
|
||||
// artworks tagged with THIS tag
|
||||
artworks: {
|
||||
where: {
|
||||
published: true,
|
||||
@ -59,7 +50,6 @@ export default async function AnimalListPage() {
|
||||
orderBy: [{ sortIndex: "asc" }, { name: "asc" }],
|
||||
});
|
||||
|
||||
// Build maps to render a robust parent/child hierarchy (no reliance on Prisma nested children)
|
||||
const byId = new Map(tags.map((t) => [t.id, t]));
|
||||
const childrenByParentId = new Map<string, typeof tags>();
|
||||
|
||||
@ -79,17 +69,16 @@ export default async function AnimalListPage() {
|
||||
.slice()
|
||||
.sort(sortBySortIndexName);
|
||||
|
||||
// Orphans: child references a parentId that isn't present (or isn't showOnAnimalPage)
|
||||
const orphans = tags
|
||||
.filter((t) => t.parentId !== null && !byId.has(t.parentId))
|
||||
.slice()
|
||||
.sort(sortBySortIndexName);
|
||||
|
||||
// Small helper to render artworks list (linked)
|
||||
const ArtworkList = ({ items }: { items: SimpleArtwork[] }) => {
|
||||
const list = items.slice().sort(sortArtworks);
|
||||
if (list.length === 0) {
|
||||
return <p className="text-sm text-muted-foreground italic">No artworks found.</p>;
|
||||
// return <p className="text-sm text-muted-foreground italic">No artworks found.</p>;
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
@ -124,11 +113,10 @@ export default async function AnimalListPage() {
|
||||
);
|
||||
};
|
||||
|
||||
// Count helper for badges
|
||||
const countArtworks = (tagId: string) => {
|
||||
const t = byId.get(tagId);
|
||||
return t?.artworks?.length ?? 0;
|
||||
};
|
||||
// const countArtworks = (tagId: string) => {
|
||||
// const t = byId.get(tagId);
|
||||
// return t?.artworks?.length ?? 0;
|
||||
// };
|
||||
|
||||
const countArtworksInChildren = (tagId: string) => {
|
||||
const children = childrenByParentId.get(tagId) ?? [];
|
||||
@ -164,7 +152,9 @@ export default async function AnimalListPage() {
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<CardHeader className="space-y-1">
|
||||
<CardTitle className="text-base">Grouped animals</CardTitle>
|
||||
<CardTitle className="text-base">
|
||||
{/* Grouped animals */}
|
||||
</CardTitle>
|
||||
{/* <p className="text-sm text-muted-foreground">
|
||||
Parent tags expand into children; standalone tags appear as single entries.
|
||||
</p> */}
|
||||
@ -192,21 +182,21 @@ export default async function AnimalListPage() {
|
||||
<div className="flex w-full items-center justify-between pr-2">
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<span className="truncate font-medium">{p.name}</span>
|
||||
{isStandalone ? (
|
||||
{/* {isStandalone ? (
|
||||
<Badge variant="secondary">single</Badge>
|
||||
) : (
|
||||
<Badge variant="secondary">{children.length} sub</Badge>
|
||||
)}
|
||||
)} */}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
{parentDirectCount > 0 ? (
|
||||
{/* {parentDirectCount > 0 ? (
|
||||
<Badge variant="outline">{parentDirectCount} direct</Badge>
|
||||
) : null}
|
||||
) : null} */}
|
||||
{!isStandalone ? (
|
||||
<Badge variant="outline">{childrenCount} in sub</Badge>
|
||||
<Badge variant="outline">{childrenCount} {childrenCount !== 1 ? "artworks" : "artwork"}</Badge>
|
||||
) : (
|
||||
<Badge variant="outline">{parentDirectCount} artworks</Badge>
|
||||
<Badge variant="outline">{parentDirectCount} {parentDirectCount !== 1 ? "artworks" : "artwork"}</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@ -227,7 +217,9 @@ export default async function AnimalListPage() {
|
||||
{/* Optional: artworks directly on the parent */}
|
||||
<div className="rounded-md border p-4">
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<div className="text-sm font-medium">Directly tagged</div>
|
||||
<div className="text-sm font-medium">
|
||||
{/* Directly tagged */}
|
||||
</div>
|
||||
<Badge variant="outline">{p.artworks.length}</Badge>
|
||||
</div>
|
||||
<ArtworkList items={p.artworks} />
|
||||
@ -242,9 +234,9 @@ export default async function AnimalListPage() {
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-sm font-medium">{c.name}</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{/* <div className="text-xs text-muted-foreground">
|
||||
Sub-tag of {p.name}
|
||||
</div>
|
||||
</div> */}
|
||||
</div>
|
||||
<Badge variant="outline">{c.artworks.length}</Badge>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user