import { useEffect, useState } from "react"; import { useAppSelector } from "../../hooks"; import { currFocus } from "../../reducers/focus"; import { ParaHandleCtl } from "./ParaHandle"; import AiTranslate from "../ai/AiTranslate"; interface IWidgetParaShellCtl { book: number; para: number; mode?: string; channels?: string[]; sentences: string[]; children?: React.ReactNode | React.ReactNode[]; } const ParaShellCtl = ({ book, para, mode = "read", channels, sentences, children, }: IWidgetParaShellCtl) => { const focus = useAppSelector(currFocus); const [isFocus, setIsFocus] = useState(false); const [aiTranslateParaId, setAiTranslateParaId] = useState(); useEffect(() => { if (focus) { if (focus.focus?.type === "para") { if (focus.focus.id) { const arrId = focus.focus.id.split("-"); if (arrId.length > 1) { const focusBook = parseInt(arrId[0]); const focusPara = arrId[1].split(",").map((item) => parseInt(item)); if (focusBook === book && focusPara.includes(para)) { setIsFocus(true); } } } else { setIsFocus(false); } } } else { setIsFocus(false); } }, [book, focus, para]); const borderColor = isFocus ? "#e35f00bd " : "rgba(128, 128, 128, 0.3)"; const border = mode === "read" ? "" : "2px solid " + borderColor; return (
setAiTranslateParaId(`${book}-${para}`)} />
{children}
); }; interface IWidget { props: string; children?: React.ReactNode | React.ReactNode[]; } const Widget = ({ props, children }: IWidget) => { const prop = JSON.parse(atob(props)) as IWidgetParaShellCtl; return ( <> {children} ); }; export default Widget;