fix layout

This commit is contained in:
Rizky 2023-11-21 20:34:59 +07:00
parent f9b2aad39d
commit 21b55c165c
5 changed files with 25 additions and 5 deletions

View File

@ -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,
};
}
}

View File

@ -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;

View File

@ -12,6 +12,7 @@ export const EdMain = () => {
{!p.page.building && (
<View
mode={p.mode}
layout={{ show: false, root: p.site.layout }}
isEditor={true}
api_url={p.site.config.api_url}
component={{

View File

@ -1,11 +1,13 @@
import { ReactElement } from "react";
import { IContent } from "../../../utils/types/general";
import { EdMeta, PG } from "../../ed/logic/ed-global";
import { IRoot } from "../../../utils/types/root";
export const ViewGlobal = {
mode: "" as "desktop" | "mobile",
status: "init" as "init" | "load-code" | "loading-code" | "ready" | "rebuild",
current: { site_id: "", page_id: "" },
layout: { show: false, root: undefined as void | IRoot },
meta: {} as Record<string, EdMeta>,
entry: [] as string[],
bodyCache: null as null | ReactElement,

View File

@ -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<ViewProp> = (props) => {
const BoxedView: FC<ViewProp> = ({
load,
site_id,
layout,
page_id,
bind,
hover,
@ -55,6 +58,8 @@ const BoxedView: FC<ViewProp> = ({
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<ViewProp> = ({
return <div className="flex flex-1 flex-col relative">{v.bodyCache}</div>;
};