diff --git a/comps/custom/Detail.tsx b/comps/custom/Detail.tsx index b0cea3b..48055d8 100755 --- a/comps/custom/Detail.tsx +++ b/comps/custom/Detail.tsx @@ -1,7 +1,7 @@ import { useLocal } from "@/utils/use-local"; import { cx } from "class-variance-authority"; import { ArrowRight } from "lucide-react"; -import { FC, useEffect } from "react"; +import { FC } from "react"; import { Skeleton } from "../ui/skeleton"; import { formatName } from "lib/gen/utils"; @@ -24,9 +24,12 @@ export const Detail: FC<{ mode: mode, on_load, bound: false, + resolved_value: null as any, }); - let detail: any = _detail; + local.on_load = on_load; + + let detail = _detail; if (typeof detail !== "function") { detail = (load: any) => { const result: any = {}; @@ -40,76 +43,33 @@ export const Detail: FC<{ }; } - if (!isEditor) { - if ( - location.pathname !== local.pathname || - mode !== local.mode || - local.on_load !== on_load - ) { - local.status = "init"; - local.on_load = on_load; - local.mode = mode; - } + let values = {}; - if (typeof on_load === "object") { - local.detail = detail(on_load); - local.status = "ready"; - } - - useEffect(() => { - if (local.status === "init" && typeof on_load === "function") { - local.status = "loading"; - if (location.pathname === "") { - local.detail = detail({}); - } else { - local.detail = detail({}); - local.pathname = location.pathname; - } - local.render(); - - const res = on_load({ - params: {}, - bind: (fn) => { - if (!local.bound) { - local.bound = true; - local.render(); - - fn(async () => { - local.status = "loading"; - local.render(); - const item = await on_load({} as any); - local.detail = detail(item); - local.status = "ready"; - local.render(); - }); - } - }, - }); - if (typeof res === "object" && res instanceof Promise) { - res.then((item) => { - local.detail = detail(item); + if (local.status !== "loading") { + if (typeof on_load === "function") { + if (local.resolved_value) { + values = detail(local.resolved_value); + local.resolved_value = null; + local.status = "ready"; + } else { + const result = on_load({} as any); + if (result instanceof Promise) { + local.status = "loading"; + values = detail({}); + result.then((e) => { + local.resolved_value = e; local.status = "ready"; local.render(); }); } else { - local.detail = detail(res); + values = detail(result); local.status = "ready"; - local.render(); } } - }, [local.status]); - } - let values = {}; - - if (!isEditor) { - values = local.detail || {}; - } else { - if (typeof on_load === "function") { - values = detail(on_load({} as any)); } else { values = detail(on_load); + local.status = "ready"; } - local.status = "ready"; } if (typeof values !== "object" || values === null) return null; @@ -264,7 +224,7 @@ const Linkable: FC<{ ); if (!link) { - if (status !== "ready") return loading; + if (status !== "ready") return status; return sample || "-"; } diff --git a/comps/md/utils/md-hash.ts b/comps/md/utils/md-hash.ts index db2fa16..cd662ca 100755 --- a/comps/md/utils/md-hash.ts +++ b/comps/md/utils/md-hash.ts @@ -24,6 +24,8 @@ export const masterDetailParseHash = (md: MDLocal) => { } } + md.params.links = md.params.links.filter((e) => e); + const parsed_link = parseLink(); let changed = parsed_link.length !== md.params.links.length; @@ -92,6 +94,7 @@ const cleanHash = (hash: string) => { export const breadcrumbPrefix = (md: MDLocal) => { let prefix: (BreadItem & { url: string })[] = []; if (md.params.links && md.params.links.length > 0) { + md.params.links = md.params.links.filter((e) => e); const hashes: string[] = []; for (const link of md.params.links) { if (!hashes.includes(link.hash)) {