import type { MediaKind } from "@umt/contracts"; import { Check, Search, X } from "lucide-react"; import { useEffect, useState } from "react"; import { useEntitySearch } from "~/api/library.ts"; import { LoadingState } from "~/components/console/empty-state.tsx"; import { Button } from "~/components/ui/button.tsx"; import { Input } from "~/components/ui/input.tsx"; import { cn } from "~/lib/utils.ts"; import { MEDIA_KIND } from "./labels.ts"; export type PickedEntity = { id: string; title: string; year: number | null; kind: MediaKind }; /** 本地作品选择:输入关键字检索 media_entity,点选一项 */ export function EntityPicker({ value, onChange, placeholder = "搜索本地作品(标题/原名)", id, }: { value: PickedEntity | null; onChange: (v: PickedEntity | null) => void; placeholder?: string; id?: string; }) { const [q, setQ] = useState(""); const [debounced, setDebounced] = useState(""); useEffect(() => { const t = setTimeout(() => setDebounced(q), 250); return () => clearTimeout(t); }, [q]); const search = useEntitySearch(debounced, { enabled: !value && debounced.trim().length > 0 }); if (value) { return (
{(search.error as Error).message}
) : items.length === 0 ? (没有匹配的本地作品
) : (