From 21b55c165cc4fdff1bb074317292613a7cd55ca0 Mon Sep 17 00:00:00 2001 From: Rizky Date: Tue, 21 Nov 2023 20:34:59 +0700 Subject: [PATCH] fix layout --- app/srv/ws/sync/actions/site_load.ts | 16 ++++++++++++++-- app/web/src/nova/ed/logic/ed-global.ts | 5 +++-- app/web/src/nova/ed/panel/main/main.tsx | 1 + app/web/src/nova/view/logic/global.ts | 2 ++ app/web/src/nova/view/view.tsx | 6 +++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/srv/ws/sync/actions/site_load.ts b/app/srv/ws/sync/actions/site_load.ts index 91b199d7..88d00180 100644 --- a/app/srv/ws/sync/actions/site_load.ts +++ b/app/srv/ws/sync/actions/site_load.ts @@ -1,8 +1,9 @@ import { validate } from "uuid"; import { ESite } from "../../../../web/src/nova/ed/logic/ed-global"; +import { IRoot } from "../../../../web/src/utils/types/root"; import { SAction } from "../actions"; -import { SyncConnection } from "../type"; import { activity } from "../entity/activity"; +import { SyncConnection } from "../type"; export const site_load: SAction["site"]["load"] = async function ( this: SyncConnection, @@ -20,13 +21,24 @@ export const site_load: SAction["site"]["load"] = async function ( activity.site.room(site.id).join({ ws: this.ws }); + let layout = undefined; + const _layout = await db.page.findFirst({ + where: { + id_site: id, + is_deleted: false, + is_default_layout: true, + }, + }); + if (_layout) layout = _layout.content_tree as IRoot; + return { id: site.id, + name: site.name, config: config as ESite["config"], domain: site.domain, js: site.js || "", js_compiled: site.js_compiled || "", - name: site.name, + layout, }; } } diff --git a/app/web/src/nova/ed/logic/ed-global.ts b/app/web/src/nova/ed/logic/ed-global.ts index ffa96926..1c09e22c 100644 --- a/app/web/src/nova/ed/logic/ed-global.ts +++ b/app/web/src/nova/ed/logic/ed-global.ts @@ -2,12 +2,12 @@ import { NodeModel } from "@minoru/react-dnd-treeview"; import { FC, ReactElement } from "react"; import { deepClone } from "web-utils"; import { SAction } from "../../../../../srv/ws/sync/actions"; +import { parseJs } from "../../../../../srv/ws/sync/editor/parser/parse-js"; import { clientStartSync } from "../../../utils/sync/ws-client"; import { IItem, MItem } from "../../../utils/types/item"; -import { DComp, DPage } from "../../../utils/types/root"; +import { DComp, DPage, IRoot } from "../../../utils/types/root"; import { ISection } from "../../../utils/types/section"; import { IText, MText } from "../../../utils/types/text"; -import { parseJs } from "../../../../../srv/ws/sync/editor/parser/parse-js"; export const EmptySite = { id: "", @@ -16,6 +16,7 @@ export const EmptySite = { config: { api_url: "" }, js: "", js_compiled: "", + layout: undefined as undefined | IRoot, }; export type ESite = typeof EmptySite; diff --git a/app/web/src/nova/ed/panel/main/main.tsx b/app/web/src/nova/ed/panel/main/main.tsx index 5e089652..7d2c639c 100644 --- a/app/web/src/nova/ed/panel/main/main.tsx +++ b/app/web/src/nova/ed/panel/main/main.tsx @@ -12,6 +12,7 @@ export const EdMain = () => { {!p.page.building && ( , entry: [] as string[], bodyCache: null as null | ReactElement, diff --git a/app/web/src/nova/view/view.tsx b/app/web/src/nova/view/view.tsx index 2805f37c..96a8bd26 100644 --- a/app/web/src/nova/view/view.tsx +++ b/app/web/src/nova/view/view.tsx @@ -8,6 +8,7 @@ import { vLoadCode } from "./logic/load-code"; import { VLoad, VLoadComponent } from "./logic/types"; import { VEntry } from "./render/entry"; import { ErrorBox } from "./render/meta/script/error-box"; +import { IRoot } from "../../utils/types/root"; type ViewProp = { load: VLoad; @@ -16,6 +17,7 @@ type ViewProp = { page_id: string; api_url: string; mode: "desktop" | "mobile"; + layout?: { root: undefined | IRoot; show: boolean }; isEditor?: boolean; bind?: (arg: { render: () => void }) => void; hidden?: (item: IContent) => boolean; @@ -36,6 +38,7 @@ export const View: FC = (props) => { const BoxedView: FC = ({ load, site_id, + layout, page_id, bind, hover, @@ -55,6 +58,8 @@ const BoxedView: FC = ({ if (v.current.page_id !== page_id || v.current.site_id !== site_id) { v.status = "init"; } + + v.layout = layout ? layout : { show: false, root: undefined }; v.component.map = component.map; v.component.load = component.load; @@ -96,4 +101,3 @@ const BoxedView: FC = ({ return
{v.bodyCache}
; }; -