Files
fancy/fancy-frontend/app/(protected)/collections/[id]/wordsSearch.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

69 lines
1.7 KiB
TypeScript

"use client";
import { useMemo, useState } from "react";
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group";
import { SearchIcon } from "lucide-react";
import type { Language } from "@/types/api";
import { WordCard } from "./wordCard";
interface WordsSearchProps {
words: string[];
lang: Language;
collectionId: string;
isRemovable: boolean;
placeholder: string;
noWordsLabel: string;
noResultsLabel: string;
}
export function WordsSearch({
words,
lang,
collectionId,
isRemovable,
placeholder,
noWordsLabel,
noResultsLabel,
}: WordsSearchProps) {
const [query, setQuery] = useState("");
const filtered = useMemo(() => {
const q = query.trim().toLowerCase();
if (!q) return words;
return words.filter((w) => w.toLowerCase().includes(q));
}, [words, query]);
return (
<div className="flex flex-col gap-4">
<InputGroup className="max-w-sm">
<InputGroupInput
placeholder={placeholder}
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
<InputGroupAddon>
<SearchIcon />
</InputGroupAddon>
</InputGroup>
{words.length === 0 ? (
<p className="text-muted-foreground mx-auto">{noWordsLabel}</p>
) : filtered.length === 0 ? (
<p className="text-muted-foreground mx-auto">{noResultsLabel}</p>
) : (
<div className="grid md:grid-cols-4 gap-4">
{filtered.map((word) => (
<div key={word}>
<WordCard
word={word}
lang={lang}
collectionId={collectionId}
isRemovable={isRemovable}
/>
</div>
))}
</div>
)}
</div>
);
}