From 01e65b4858220611c03b24504183a54ab60d1501 Mon Sep 17 00:00:00 2001 From: rizky Date: Fri, 9 Aug 2024 03:11:09 -0700 Subject: [PATCH] fix header --- comps/form/utils/init.tsx | 12 +++++++----- comps/md/MasterDetail.tsx | 2 +- comps/md/parts/MDDetail.tsx | 8 +++++++- comps/md/parts/MDHeader.tsx | 1 + comps/md/utils/typings.ts | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/comps/form/utils/init.tsx b/comps/form/utils/init.tsx index 8b60e0e..8afacad 100755 --- a/comps/form/utils/init.tsx +++ b/comps/form/utils/init.tsx @@ -7,6 +7,7 @@ import { formError } from "./error"; import { toast } from "lib/comps/ui/toast"; import { Button } from "lib/comps/ui/button"; import { MDLocal } from "lib/comps/md/utils/typings"; +import { masterDetailApplyParams } from "lib/comps/md/utils/md-hash"; export const formInit = (fm: FMLocal, props: FMProps) => { for (const [k, v] of Object.entries(props)) { @@ -57,6 +58,7 @@ export const formInit = (fm: FMLocal, props: FMProps) => { size={"xs"} className="c-cursor-pointer" onClick={() => { + const md = fm.deps.md as MDLocal; toast.dismiss(); md.selected = null; md.tab.active = "master"; @@ -74,14 +76,14 @@ export const formInit = (fm: FMLocal, props: FMProps) => { size={"xs"} className="c-cursor-pointer" onClick={() => { + const md = fm.deps.md as MDLocal; toast.dismiss(); - for (const k of Object.keys(md.selected)) { - delete md.selected[k]; - } - md.tab.active = "detail"; + md.params.hash[md.name] = "+"; + md.selected = {}; + md.internal.reset_detail = true; + md.tab.active = "detail"; md.params.apply(); - md.render(); }} >
{opt.addNewText}
diff --git a/comps/md/MasterDetail.tsx b/comps/md/MasterDetail.tsx index 41b2315..87c828b 100755 --- a/comps/md/MasterDetail.tsx +++ b/comps/md/MasterDetail.tsx @@ -48,7 +48,7 @@ export const MasterDetail: FC = (arg) => { active: "", list: [], }, - internal: { action_should_refresh: false }, + internal: { action_should_refresh: false, reset_detail: false }, childs: {}, props: { mode, diff --git a/comps/md/parts/MDDetail.tsx b/comps/md/parts/MDDetail.tsx index 6b474e9..5dfb510 100755 --- a/comps/md/parts/MDDetail.tsx +++ b/comps/md/parts/MDDetail.tsx @@ -13,9 +13,15 @@ export const should_show_tab = (md: MDLocal) => { }; export const MDDetail: FC<{ md: MDLocal; mdr: MDRef }> = ({ md, mdr }) => { - const local = useLocal({ selected: "", synced: false }); const detail = md.childs[md.tab.active]; const PassProp = mdr.PassProp; + + if (md.internal.reset_detail) { + md.internal.reset_detail = false; + md.render(); + return null; + } + if (!detail) { return null; } diff --git a/comps/md/parts/MDHeader.tsx b/comps/md/parts/MDHeader.tsx index 9d482ec..7926fd1 100755 --- a/comps/md/parts/MDHeader.tsx +++ b/comps/md/parts/MDHeader.tsx @@ -15,5 +15,6 @@ export const MDHeader: FC<{ md: MDLocal; mdr: MDRef }> = ({ md, mdr }) => { md.header.breadcrumb = [...prefix, ...md.header.master.breadcrumb()]; } + if (md.internal.reset_detail) return null; return {head}; }; diff --git a/comps/md/utils/typings.ts b/comps/md/utils/typings.ts index dc65f56..5a793aa 100755 --- a/comps/md/utils/typings.ts +++ b/comps/md/utils/typings.ts @@ -54,7 +54,7 @@ export type MDLocalInternal = { active: string; list: string[]; }; - internal: { action_should_refresh: boolean }; + internal: { action_should_refresh: boolean; reset_detail: boolean }; master: { reload: (arg?: { toast: boolean }) => void; render: () => void;