Some refactor

This commit is contained in:
2025-12-28 18:41:31 +01:00
parent ce658849e9
commit eaf822d73a
11 changed files with 202 additions and 36 deletions

View File

@ -1,31 +1,18 @@
import { getSingleArtwork } from "@/actions/artworks/getArtworks";
import { getCategoriesWithTags } from "@/actions/categories/getCategories";
import { getTags } from "@/actions/tags/getTags";
import ArtworkColors from "@/components/artworks/single/ArtworkColors";
import ArtworkVariants from "@/components/artworks/single/ArtworkVariants";
import DeleteArtworkButton from "@/components/artworks/single/DeleteArtworkButton";
import EditArtworkForm from "@/components/artworks/single/EditArtworkForm";
import { prisma } from "@/lib/prisma";
export default async function ArtworkSinglePage({ params }: { params: { id: string } }) {
export default async function ArtworkSinglePage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const item = await prisma.artwork.findUnique({
where: { id },
include: {
// album: true,
// type: true,
file: true,
gallery: true,
metadata: true,
albums: true,
categories: true,
colors: { include: { color: true } },
// sortContexts: true,
tags: true,
variants: true
}
})
const item = await getSingleArtwork(id);
const categories = await prisma.artCategory.findMany({ include: { tags: true }, orderBy: { sortIndex: "asc" } });
const tags = await prisma.artTag.findMany({ orderBy: { sortIndex: "asc" } });
const categories = await getCategoriesWithTags();
const tags = await getTags();
if (!item) return <div>Artwork with this id not found</div>

View File

@ -1,15 +1,11 @@
import { getCategoriesWithCount } from "@/actions/categories/getCategories";
import CategoryTable from "@/components/categories/CategoryTable";
import { prisma } from "@/lib/prisma";
import { PlusCircleIcon } from "lucide-react";
import Link from "next/link";
import { Suspense } from "react";
export default async function CategoriesPage() {
const items = await prisma.artCategory.findMany({
include: {
_count: { select: { artworks: true, tags: true } },
},
orderBy: [{ sortIndex: "asc" }, { name: "asc" }],
});
const items = await getCategoriesWithCount();
return (
<div>
@ -19,11 +15,13 @@ export default async function CategoriesPage() {
<PlusCircleIcon className="h-[1.2rem] w-[1.2rem] scale-100 rotate-0 transition-all text-primary-foreground" /> Add new category
</Link>
</div>
{items.length > 0 ? (
<CategoryTable categories={items} />
) : (
<p>There are no categories yet. Consider adding some!</p>
)}
<Suspense fallback={<p>Loading...</p>}>
{items.length > 0 ? (
<CategoryTable categories={items} />
) : (
<p>There are no categories yet. Consider adding some!</p>
)}
</Suspense>
</div>
);
}