From e41c3db80a5f7fc9605e32a24891dd8cebedfda6 Mon Sep 17 00:00:00 2001 From: Rizky Date: Sat, 27 Jan 2024 15:04:56 +0700 Subject: [PATCH] wip fix --- app/srv/ws/sync/actions/code_edit.ts | 40 +++++++++++++++++++ app/srv/ws/sync/actions/yjs_diff_local.ts | 12 +++--- app/srv/ws/sync/editor/load-component.ts | 4 +- .../nova/ed/panel/popup/page/page-tree.tsx | 6 ++- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/app/srv/ws/sync/actions/code_edit.ts b/app/srv/ws/sync/actions/code_edit.ts index 03481f87..da67247d 100644 --- a/app/srv/ws/sync/actions/code_edit.ts +++ b/app/srv/ws/sync/actions/code_edit.ts @@ -22,6 +22,7 @@ export const code_edit: SAction["code"]["edit"] = async function ( let root = undefined as undefined | MRoot | MItem; let doc = undefined as undefined | Doc; + let save_to = "page"; if (page_id) { const ref = docs.page[page_id]; if (ref) { @@ -29,6 +30,7 @@ export const code_edit: SAction["code"]["edit"] = async function ( doc = ref.doc as Doc; } } else if (comp_id) { + save_to = "comp"; const ref = docs.comp[comp_id]; if (ref) { root = ref.doc.getMap("map").get("root"); @@ -80,6 +82,22 @@ export const code_edit: SAction["code"]["edit"] = async function ( } } }); + + if (save_to === "comp") { + await db.page.update({ + where: { id: page_id }, + data: { + content_tree: root.toJSON(), + }, + }); + } else { + await db.component.update({ + where: { id: comp_id }, + data: { + content_tree: root.toJSON(), + }, + }); + } } catch (e: any) { return e.message.toString(); } @@ -101,6 +119,22 @@ export const code_edit: SAction["code"]["edit"] = async function ( mprop.set("value", src); mprop.set("valueBuilt", res.code.substring(6)); }); + + if (save_to === "comp") { + await db.page.update({ + where: { id: page_id }, + data: { + content_tree: root.toJSON(), + }, + }); + } else { + await db.component.update({ + where: { id: comp_id }, + data: { + content_tree: root.toJSON(), + }, + }); + } } catch (e: any) { return e.message.toString(); } @@ -143,6 +177,12 @@ export const code_edit: SAction["code"]["edit"] = async function ( } } }); + await db.component.update({ + where: { id: comp_id }, + data: { + content_tree: root.toJSON(), + }, + }); } catch (e: any) { return e.message.toString(); } diff --git a/app/srv/ws/sync/actions/yjs_diff_local.ts b/app/srv/ws/sync/actions/yjs_diff_local.ts index 2a8933d5..c79ecbf6 100644 --- a/app/srv/ws/sync/actions/yjs_diff_local.ts +++ b/app/srv/ws/sync/actions/yjs_diff_local.ts @@ -13,13 +13,13 @@ export const yjs_diff_local: SAction["yjs"]["diff_local"] = async function ( console.log(`diff_local not found`, mode, id); return; } - const doc = docs[mode][id].doc as Y.Doc; - const diff = await gunzipAsync(bin); - const um = docs[mode][id].um; - um.addTrackedOrigin(this.client_id); - Y.applyUpdate(doc, diff, this.client_id); - if (mode === "page" || mode === "comp") { + const doc = docs[mode][id].doc as Y.Doc; + const diff = await gunzipAsync(bin); + const um = docs[mode][id].um; + um.addTrackedOrigin(this.client_id); + Y.applyUpdate(doc, diff, this.client_id); + const root = doc.getMap("map").get("root") as any; if (root) { if (mode === "page") { diff --git a/app/srv/ws/sync/editor/load-component.ts b/app/srv/ws/sync/editor/load-component.ts index 7f496803..1e53377d 100644 --- a/app/srv/ws/sync/editor/load-component.ts +++ b/app/srv/ws/sync/editor/load-component.ts @@ -1,5 +1,4 @@ import { IItem } from "../../../../web/src/utils/types/item"; -import { DComp } from "../../../../web/src/utils/types/root"; import { conns } from "../entity/conn"; import { docs } from "../entity/docs"; import { snapshot } from "../entity/snapshot"; @@ -57,6 +56,9 @@ export const loadComponent = async (comp_id: string, sync?: SyncConnection) => { const comp = await db.component.findFirst({ where: { id: comp_id } }); if (comp) { const item = comp.content_tree as IItem; + if (item.name === "card") { + console.log(item); + } if (item && item.component?.id !== comp.id) { item.component = { id: comp.id, props: {} }; } diff --git a/app/web/src/nova/ed/panel/popup/page/page-tree.tsx b/app/web/src/nova/ed/panel/popup/page/page-tree.tsx index a2da117a..f2498c7d 100644 --- a/app/web/src/nova/ed/panel/popup/page/page-tree.tsx +++ b/app/web/src/nova/ed/panel/popup/page/page-tree.tsx @@ -161,7 +161,11 @@ export const edPageTreeRender: NodeRender = ( if (confirm("Clone page ?")) { local.render(); const page = (await db.page.findFirst({ - where: { id: node.id as string }, + where: { + id: node.id as string, + is_deleted: false, + is_default_layout: false, + }, })) as any; delete page.id;