Files
fancy/fancy-frontend/app/(protected)/collections/[id]/page.tsx
T
Ivan Rezchikov 628dd6384b
Build and Deploy / test-backend (push) Successful in 1m11s
Build and Deploy / lint-frontend (push) Successful in 21s
Build and Deploy / build-backend (push) Successful in 58s
Build and Deploy / deploy (push) Canceled after 0s
Build and Deploy / build-frontend (push) Canceled after 5m38s
version 1
2026-09-18 00:45:51 +03:00

70 lines
2.5 KiB
TypeScript

import HeaderWithAuth from "@/components/headerWithAuth";
import Main from "@/components/main";
import { ArrowLeftIcon } from "lucide-react";
import Link from "next/link";
import { notFound } from "next/navigation";
import { isApiError } from "@/lib/api";
import { getCollection } from "@/lib/serverApi";
import { LANGUAGES } from "@/lib/languages";
import type { CollectionResult } from "@/types/api";
import { MenuDialog } from "./menuDialog";
import { getTranslations } from "next-intl/server";
import { WordsSearch } from "./wordsSearch";
export default async function CollectionPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const tCollections = await getTranslations("Collections");
const tc = await getTranslations("Common");
const tl = await getTranslations("Languages");
const tApi = await getTranslations("ApiErrors");
let collection: CollectionResult;
try {
collection = await getCollection(id);
} catch (err) {
if (isApiError(err) && err.kind === "not-found") notFound();
const message = isApiError(err) ? tApi(err.kind) : tc("somethingWrong");
return (
<Main>
<HeaderWithAuth />
<p className="text-destructive">{message}</p>
</Main>
);
}
const language = LANGUAGES.find((l) => l.id === collection.lang);
const words = [...collection.words].reverse();
return (
<Main>
<HeaderWithAuth />
<Link href="/collections" className="flex items-center gap-1.5 text-muted-foreground w-fit">
<ArrowLeftIcon size={16} /><p>{tCollections("title")}</p>
</Link>
<div className="flex flex-row items-start justify-between">
<div className="flex flex-col gap-2.5 justify-between">
<h2 className="font-semibold">{collection.name === "history" ? tc("history") : collection.name}</h2>
<div className="flex flex-row gap-8">
<h3 className="font-medium">{collection.words.length} {collection.words.length === 1 ? tc("word") : tc("words")}</h3>
{language && <div className="flex flex-row gap-2.5 items-center">
<h3 className="font-medium">{tl(language.id)}</h3>
</div>}
</div>
</div>
<MenuDialog collection={collection} />
</div>
<WordsSearch
words={words}
lang={collection.lang}
collectionId={collection.id}
isRemovable={collection.type === "user"}
placeholder={tc("search")}
noWordsLabel={tCollections("noWords")}
noResultsLabel={tCollections("noSearchResults")}
/>
</Main>
);
}