import { useEffect, useState } from "react"; import { Layout, Affix, Col, Row } from "antd"; import DictSearch from "./DictSearch"; import SearchVocabulary from "./SearchVocabulary"; import Compound from "./Compound"; import TermShow from "../term/TermShow"; const { Content } = Layout; interface IWidget { word?: string; compact?: boolean; onSearch?: Function; } const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => { const [split, setSplit] = useState(); const [wordSearch, setWordSearch] = useState(); const [container, setContainer] = useState(null); const [dictType, setDictType] = useState("dict"); const [wordInput, setWordInput] = useState(word); const [wordId, setWordId] = useState(); useEffect(() => { console.debug("param word change", word); wordInputChange(word); }, [word]); const wordChange = (value?: string) => { console.debug("has ':'", value, value?.includes(":")); let currWord: string | undefined = ""; if (value?.includes(":")) { const param = value.split(" "); param.forEach((value) => { const kv = value.split(":"); if (kv.length === 2) { switch (kv[0]) { case "type": setDictType(kv[1]); break; case "word": currWord = kv[1]; break; case "id": setWordId(kv[1]); break; default: break; } } }); } else { setDictType("dict"); currWord = value?.toLowerCase(); } document.getElementById("pcd_dict_top")?.scrollIntoView(); return currWord; }; const wordInputChange = (value: string | undefined) => { setWordInput(value); console.debug("wordInput change", value); if (value !== wordSearch) { const currWord = wordChange(value); setWordSearch(currWord); } }; const dictSearch = (value: string, isFactor?: boolean) => { console.info("onSearch", value); const currWord = wordChange(value); if (typeof onSearch !== "undefined" && !isFactor) { onSearch(currWord); } setWordSearch(currWord); }; return (
container : undefined} className="dict_search_div" >
{compact ? <> : }
{ console.log("onSplit", word); setSplit(word); }} />
{compact ? <> : }
{compact ? <> : } {dictType === "dict" ? (
) : ( { const newInput = `type:term id:${value}`; console.debug("term onIdChange setWordInput", newInput); if (typeof onSearch !== "undefined") { onSearch(newInput); } else { wordInputChange(newInput); } }} /> )} {compact ? <> : }
); }; export default DictionaryWidget;