version 1
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
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
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import HeaderWithAuth from "@/components/headerWithAuth";
|
||||
import Main from "@/components/main";
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import Link from "next/link";
|
||||
import { isApiError } from "@/lib/api";
|
||||
import { getCollections } from "@/lib/serverApi";
|
||||
import type { CollectionResult } from "@/types/api";
|
||||
import { formatDate, type RelativeTimeTranslator } from "@/lib/formatDate";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { CreateCollectionDialog } from "./createCollectionDialog";
|
||||
|
||||
type Translator = (key: string, values?: Record<string, string | number | Date>) => string;
|
||||
|
||||
function CollectionCard({ collection, tc, tt, tl }: { collection: CollectionResult; tc: Translator; tt: RelativeTimeTranslator; tl: Translator }) {
|
||||
return (
|
||||
<Card size="sm" className="justify-between">
|
||||
<CardHeader>
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle><h4>{collection.name === "history" ? tc("history") : collection.name}</h4></CardTitle>
|
||||
<h5 className="flex flex-row gap-0.5 items-center text-muted-foreground">
|
||||
{tl(collection.lang)}
|
||||
</h5>
|
||||
</div>
|
||||
<CardDescription>
|
||||
<p>{collection.words.length} {collection.words.length === 1 ? tc("word") : tc("words")} • {tc("updated")} {formatDate(collection.updated_at, tt)}</p>
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
{collection.words.length > 0 && (<CardContent>
|
||||
<div className="flex flex-wrap gap-1.5 items-center">
|
||||
{[...collection.words].reverse().slice(0, 3).map((w) => (
|
||||
<Badge key={w} variant="outline">{w}</Badge>
|
||||
))}
|
||||
{collection.words.length > 3 && <h6 className="text-muted-foreground">{tc("andMore", { count: collection.words.length - 3 })}</h6>}
|
||||
</div>
|
||||
</CardContent>)}
|
||||
<CardFooter className="flex gap-2">
|
||||
<Link href={`/collections/${collection.id}`} className="w-full">
|
||||
<Button variant="outline" size="sm" className="w-full">{tc("seeAll")}</Button>
|
||||
</Link>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export default async function Collections() {
|
||||
const tt = await getTranslations("Time");
|
||||
const tc = await getTranslations("Common");
|
||||
const tl = await getTranslations("Languages");
|
||||
const tCollections = await getTranslations("Collections");
|
||||
const tApi = await getTranslations("ApiErrors");
|
||||
|
||||
let collections: CollectionResult[] = [];
|
||||
let error: string | null = null;
|
||||
|
||||
try {
|
||||
collections = await getCollections();
|
||||
} catch (err) {
|
||||
error = isApiError(err) ? tApi(err.kind) : tc("somethingWrong");
|
||||
}
|
||||
|
||||
return (
|
||||
<Main>
|
||||
<HeaderWithAuth />
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
<h2 className="font-semibold">{tCollections("title")}</h2>
|
||||
<CreateCollectionDialog />
|
||||
</div>
|
||||
{error ? (
|
||||
<p className="text-muted-foreground">{error}</p>
|
||||
) : (
|
||||
<div className="grid md:grid-cols-4 gap-4">
|
||||
{collections.map((c) => (
|
||||
<CollectionCard key={c.id} collection={c} tc={tc} tt={tt} tl={tl} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user