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

This commit is contained in:
Ivan Rezchikov
2026-09-18 00:45:51 +03:00
commit 628dd6384b
149 changed files with 11478 additions and 0 deletions
@@ -0,0 +1,74 @@
"use client";
import Link from "next/link";
import { useMemo } from "react";
import { ArrowRightIcon } from "lucide-react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
import { lookupDictionary } from "@/lib/api";
import { useResource } from "@/hooks/useResource";
import { useTranslations } from "next-intl";
import type { DictionaryResult, Language } from "@/types/api";
import { RemoveWordButton } from "./removeWordButton";
export function WordCard({
word,
lang,
collectionId,
isRemovable,
}: {
word: string;
lang: Language;
collectionId: string;
isRemovable: boolean;
}) {
const td = useTranslations("Definition");
const key = `dict:${lang}:${word.toLowerCase()}`;
const state = useResource<DictionaryResult>(key, () => lookupDictionary(lang, word));
const definition = useMemo(() => {
if (state.status !== "done" || !state.data) return undefined;
const entry = state.data.entries[0];
if (!entry) return null;
return {
text: entry.senses[0]?.definition ?? null,
quantity: entry.senses.length,
};
}, [state]);
return (
<Card size="sm" className="h-full flex flex-col">
<CardHeader>
<div className="flex flex-row items-center justify-between">
<CardTitle><h4>{word}</h4></CardTitle>
<div className="flex flex-row items-center gap-2">
{isRemovable && <RemoveWordButton collectionId={collectionId} word={word} />}
<Link href={`/?text=${encodeURIComponent(word)}&sourceLang=${lang}`}>
<ArrowRightIcon size={18} className="text-muted-foreground" />
</Link>
</div>
</div>
</CardHeader>
<CardContent className="flex-1">
{state.status === "loading" ? (
<div className="flex flex-col gap-2">
<Skeleton className="w-full h-4" />
<Skeleton className="w-2/3 h-4" />
</div>
) : state.status === "error" || !definition?.text ? (
<h5 className="text-muted-foreground italic">{td("notFound")}</h5>
) : (
<div className="flex flex-col gap-2">
<h5 className="text-muted-foreground line-clamp-3">
{definition.text}
{definition.quantity > 1 && (
<span className="italic"> {td("otherDefinitions", { count: definition.quantity - 1 })}</span>
)}
</h5>
</div>
)}
</CardContent>
</Card>
);
}