import { TableList } from "lib/comps/list/TableList"; import { useLocal } from "lib/utils/use-local"; import { FC, useEffect, useRef } from "react"; import { FMLocal } from "../../typings"; export const TableEdit: FC<{ on_init: () => FMLocal; name: string; child: any; PassProp: any; item: PrasiItem; show_header?: "y" | "n"; bottom: any; body: any; }> = ({ on_init, name, child, PassProp, item, bottom, show_header }) => { const fm = on_init(); const local = useLocal( { tbl: null as any, }, () => {} ); const ref = useRef(null); const parent = fm; if (!Array.isArray(fm.data[name])) { if (typeof fm.data[name] === "object") { fm.data[name] = [JSON.parse(JSON.stringify(fm.data[name]))]; } else { fm.data[name] = []; } } const value = fm.data[name]; useEffect(() => { local.tbl.render(); }, [3000]); return ( <>
{ local.tbl.data.push(e ? e : {}); fm.render(); setTimeout(() => { const last = Array.from( ref.current?.querySelectorAll(".rdg-row") || [] ).pop(); const input = last?.querySelector("input"); if (input) { input.focus(); } }, 100); }, }} fm_parent={parent} > {bottom}
); };