import { useState, type FormEvent } from "react"; import { NavLink } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { useVocabularies, useCreateVocabulary, useRenameVocabulary, useDeleteVocabulary } from "../api/queries"; import { DeleteConfirmDialog } from "../components/delete-confirm-dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { ListSkeleton } from "@/components/ui/skeletons"; export function VocabularyList() { const { t } = useTranslation(); const { data, isLoading, isError } = useVocabularies(); const create = useCreateVocabulary(); const renameVocabulary = useRenameVocabulary(); const deleteVocabulary = useDeleteVocabulary(); const [key, setKey] = useState(""); const [editingId, setEditingId] = useState(null); const [draftKey, setDraftKey] = useState(""); const onCreate = (event: FormEvent) => { event.preventDefault(); if (!key.trim()) return; create.mutate({ key: key.trim() }, { onSuccess: () => setKey("") }); }; return (
{t("vocab.newVocabulary")}
setKey(e.target.value)} />
{create.isError && (

{t("form.rejected")}

)}
{isLoading ? ( ) : (
    {isError && (
  • {t("vocab.loadError")}
  • )} {data?.length === 0 && (
  • {t("vocab.empty")}
  • )} {data?.map((v) => (
  • {editingId === v.id ? (
    { e.preventDefault(); renameVocabulary.mutate( { id: v.id, key: draftKey.trim() }, { onSuccess: () => setEditingId(null) }, ); }} > setDraftKey(e.target.value)} /> {renameVocabulary.isError && (

    {t("form.rejected")}

    )}
    ) : ( <> `block flex-1 px-3 py-2 text-sm ${isActive ? "bg-primary/10" : "hover:bg-muted"}` } > {v.key} deleteVocabulary.mutateAsync(v.id)} /> )}
  • ))}
)}
); }