fix route
This commit is contained in:
parent
885bf0e7fc
commit
7ba2c91dc0
|
|
@ -1,6 +1,10 @@
|
|||
import { NodeModel } from "@minoru/react-dnd-treeview";
|
||||
import { clientStartSync } from "../../../utils/sync/client";
|
||||
import { IItem } from "../../../utils/types/item";
|
||||
import { IContent, MContent } from "../../../utils/types/general";
|
||||
import { IItem, MItem } from "../../../utils/types/item";
|
||||
import { DPage, IRoot } from "../../../utils/types/root";
|
||||
import { IText, MText } from "../../../utils/types/text";
|
||||
import { NodeMeta } from "../../editor/logic/global";
|
||||
|
||||
const EmptySite = {
|
||||
id: "",
|
||||
|
|
@ -20,6 +24,11 @@ const EmptyPage = {
|
|||
snapshot: null as null | Uint8Array,
|
||||
};
|
||||
|
||||
export type EdMeta = {
|
||||
item: IItem | IText;
|
||||
mitem?: MItem | MText;
|
||||
};
|
||||
|
||||
export const EDGlobal = {
|
||||
status: "init" as
|
||||
| "init"
|
||||
|
|
@ -33,6 +42,9 @@ export const EDGlobal = {
|
|||
current: EmptyPage,
|
||||
doc: null as null | DPage,
|
||||
root: null as null | IRoot,
|
||||
entry: [] as string[],
|
||||
tree: [] as NodeModel<EdMeta>[],
|
||||
meta: {} as Record<string, { item: IContent; mitem?: MContent }>,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { IRoot } from "../../../utils/types/root";
|
||||
import { PG } from "./ed-global";
|
||||
import { produce } from "immer";
|
||||
import { treeRebuild } from "./tree/build";
|
||||
export const edRoute = async (p: PG) => {
|
||||
if (p.status === "ready") {
|
||||
if (!p.site.domain && !p.site.name) {
|
||||
|
|
@ -32,10 +33,7 @@ export const edRoute = async (p: PG) => {
|
|||
p.page.doc = doc as any;
|
||||
|
||||
if (p.page.doc) {
|
||||
const root = p.page.doc.getMap("map").get("root")?.toJSON() as IRoot;
|
||||
if (root) {
|
||||
p.page.root = produce(root, () => {});
|
||||
}
|
||||
treeRebuild(p);
|
||||
}
|
||||
}
|
||||
p.status = "ready";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,68 @@
|
|||
import { IItem } from "../../../../utils/types/item";
|
||||
import { ISection } from "../../../../utils/types/section";
|
||||
import { PG } from "../ed-global";
|
||||
import { IItem, MItem } from "../../../../utils/types/item";
|
||||
import { MRoot } from "../../../../utils/types/root";
|
||||
import { MSection } from "../../../../utils/types/section";
|
||||
import { walk } from "../../../editor/logic/tree-logic";
|
||||
import { EdMeta, PG } from "../ed-global";
|
||||
|
||||
export const treeRebuild = (items: (ISection | IItem)[]) => {};
|
||||
export const treeRebuild = async (p: PG) => {
|
||||
const root = p.page.doc?.getMap("map").get("root");
|
||||
if (root) {
|
||||
p.page.entry = [];
|
||||
p.page.tree = [];
|
||||
p.page.meta = {};
|
||||
|
||||
const sections = root.get("childs");
|
||||
if (sections) {
|
||||
await Promise.all(
|
||||
sections.map(async (e) => {
|
||||
p.page.entry.push(e.get("id"));
|
||||
await walkMap(p, { mitem: e, tree_parent_id: "root" });
|
||||
})
|
||||
);
|
||||
console.log(p.page);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const walkMap = async (
|
||||
p: PG,
|
||||
arg: { mitem: MItem | MSection; tree_parent_id: string }
|
||||
) => {
|
||||
const { mitem, tree_parent_id } = arg;
|
||||
|
||||
const item = {} as unknown as IItem;
|
||||
mitem.forEach((e, k) => {
|
||||
if (k !== "childs") {
|
||||
let val = e;
|
||||
if (typeof e === "object" && e) {
|
||||
if ((e as any).toJSON) {
|
||||
val = e.toJSON() as any;
|
||||
}
|
||||
}
|
||||
(item as any)[k] = val;
|
||||
} else {
|
||||
item[k] = [];
|
||||
}
|
||||
});
|
||||
|
||||
const meta: EdMeta = {
|
||||
item,
|
||||
mitem: mitem as MItem,
|
||||
};
|
||||
|
||||
p.page.meta[item.id] = meta;
|
||||
|
||||
p.page.tree.push({
|
||||
id: item.id,
|
||||
parent: tree_parent_id,
|
||||
text: item.name,
|
||||
data: meta,
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
mitem.get("childs")?.map(async (e, k) => {
|
||||
item.childs.push(e.get("id"));
|
||||
await walkMap(p, { mitem: e, tree_parent_id: item.id });
|
||||
}) || []
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue