From c38f2a1da5778a64cabc8f9e939c02a6125f8997 Mon Sep 17 00:00:00 2001 From: Rizky Date: Tue, 30 Jan 2024 14:36:07 +0700 Subject: [PATCH] wip fix --- app/srv/ws/sync/actions-def.ts | 4 +- app/srv/ws/sync/actions.ts | 7 +- app/srv/ws/sync/actions/code_action.ts | 12 +++ app/srv/ws/sync/actions/code_parse.ts | 18 ---- app/srv/ws/sync/actions/index.ts | 2 +- app/web/src/nova/ed/logic/ed-global.ts | 7 +- .../src/nova/ed/logic/tree/assign-mitem.ts | 2 +- .../nova/ed/logic/tree/build/push-tree.tsx | 7 +- app/web/src/nova/ed/panel/popup/code/code.tsx | 84 ++++++++++++++----- .../src/nova/ed/panel/popup/script/monaco.tsx | 4 +- app/web/src/nova/vi/meta/meta.ts | 34 ++++---- 11 files changed, 115 insertions(+), 66 deletions(-) create mode 100644 app/srv/ws/sync/actions/code_action.ts delete mode 100644 app/srv/ws/sync/actions/code_parse.ts diff --git a/app/srv/ws/sync/actions-def.ts b/app/srv/ws/sync/actions-def.ts index 2ab52416..bceae2de 100644 --- a/app/srv/ws/sync/actions-def.ts +++ b/app/srv/ws/sync/actions-def.ts @@ -28,7 +28,7 @@ export const SyncActionDefinition = { "code": { "load": "16", "edit": "17", - "parse": "18" + "action": "18" } }; export const SyncActionPaths = { @@ -50,5 +50,5 @@ export const SyncActionPaths = { "15": "client.info", "16": "code.load", "17": "code.edit", - "18": "code.parse" + "18": "code.action" }; diff --git a/app/srv/ws/sync/actions.ts b/app/srv/ws/sync/actions.ts index 89241a2d..473cbb6a 100644 --- a/app/srv/ws/sync/actions.ts +++ b/app/srv/ws/sync/actions.ts @@ -120,7 +120,10 @@ export const SyncActions = { value: Uint8Array; } ) => ({}) as boolean | ParsedScope | string, - parse: async (code: string | Record) => - ({}) as Record>, + action: async (arg: { type: "startup-check"; site_id: string }) => + ({}) as { + type: "startup-check"; + status: "disabled" | "running" | "stopped"; + }, }, }; diff --git a/app/srv/ws/sync/actions/code_action.ts b/app/srv/ws/sync/actions/code_action.ts new file mode 100644 index 00000000..2cb00b3a --- /dev/null +++ b/app/srv/ws/sync/actions/code_action.ts @@ -0,0 +1,12 @@ + +import { SAction } from "../actions"; +import { SyncConnection } from "../type"; +export const code_action: SAction["code"]["action"] = async function ( + this: SyncConnection, +) { + let result = null as unknown as Awaited< + ReturnType + >; + + return result; +} \ No newline at end of file diff --git a/app/srv/ws/sync/actions/code_parse.ts b/app/srv/ws/sync/actions/code_parse.ts deleted file mode 100644 index abb357b6..00000000 --- a/app/srv/ws/sync/actions/code_parse.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { SAction } from "../actions"; -import { parseJs } from "../editor/parser/parse-js"; -import { SyncConnection } from "../type"; - -export const code_parse: SAction["code"]["parse"] = async function ( - this: SyncConnection, - code -) { - if (typeof code === "object") { - const result: Record> = {}; - for (const [k, v] of Object.entries(code)) { - result[k] = parseJs(v); - } - return result; - } - - return { _: parseJs(code) }; -}; diff --git a/app/srv/ws/sync/actions/index.ts b/app/srv/ws/sync/actions/index.ts index 018da2ce..11a8c937 100644 --- a/app/srv/ws/sync/actions/index.ts +++ b/app/srv/ws/sync/actions/index.ts @@ -16,4 +16,4 @@ export * from "./yjs_sv_remote"; export * from "./client_info"; export * from "./code_load"; export * from "./code_edit"; -export * from "./code_parse"; \ No newline at end of file +export * from "./code_action"; \ No newline at end of file diff --git a/app/web/src/nova/ed/logic/ed-global.ts b/app/web/src/nova/ed/logic/ed-global.ts index 3f99e4b5..59a09eb8 100644 --- a/app/web/src/nova/ed/logic/ed-global.ts +++ b/app/web/src/nova/ed/logic/ed-global.ts @@ -233,7 +233,12 @@ export const EDGlobal = { name: "site", log: "", loading: false, - startup_running: false, + startup_status: "init" as + | "init" + | "loading" + | "disabled" + | "stopped" + | "running", error: false, show_log: false, list: {} as Record, diff --git a/app/web/src/nova/ed/logic/tree/assign-mitem.ts b/app/web/src/nova/ed/logic/tree/assign-mitem.ts index 1466ad89..69a94983 100644 --- a/app/web/src/nova/ed/logic/tree/assign-mitem.ts +++ b/app/web/src/nova/ed/logic/tree/assign-mitem.ts @@ -51,7 +51,7 @@ export const assignMitem = (arg: { } } else { parent.mitem.get("childs")?.forEach((child) => { - if (child.get("id") === m.item.id) { + if (child && child.get && child.get("id") === m.item.id) { m.mitem = child; } }); diff --git a/app/web/src/nova/ed/logic/tree/build/push-tree.tsx b/app/web/src/nova/ed/logic/tree/build/push-tree.tsx index 6a4bf29a..b5d8c112 100644 --- a/app/web/src/nova/ed/logic/tree/build/push-tree.tsx +++ b/app/web/src/nova/ed/logic/tree/build/push-tree.tsx @@ -22,13 +22,18 @@ export const pushTreeNode = ( if (parent && parent.mitem) { parent.mitem.get("childs")?.forEach((mitem) => { - if (mitem.get("id") === meta.item.id) { + if (mitem && mitem.get && mitem.get("id") === meta.item.id) { meta.mitem = mitem; } }); } } + if (!meta.item || !meta.item.id) { + console.warn("Emptry Tree Item ", meta); + return null; + } + if (tree.find((t) => t.id === meta.item.id)) { console.warn("Double Tree Item: ", meta.item.id, meta.item.name); } else { diff --git a/app/web/src/nova/ed/panel/popup/code/code.tsx b/app/web/src/nova/ed/panel/popup/code/code.tsx index 5409f5fd..9d34827a 100644 --- a/app/web/src/nova/ed/panel/popup/code/code.tsx +++ b/app/web/src/nova/ed/panel/popup/code/code.tsx @@ -12,7 +12,7 @@ import { iconNewTab, iconScrollOff, iconScrollOn, - iconUpload + iconUpload, } from "./icons"; import { CodeNameItem, CodeNameList } from "./name-list"; @@ -46,6 +46,15 @@ export const EdPopCode = () => { } }, []); + if (p.ui.popup.code.startup_status === "init" && p.sync.code.action) { + p.ui.popup.code.startup_status = "loading"; + p.sync.code + .action({ type: "startup-check", site_id: p.site.id }) + .then((res) => { + console.log(res); + }); + } + return ( { ) ) { code.mode = "new"; + db.code.create({ + data: { id_site: p.site.id, name: "site" }, + }); p.ui.popup.code.open = false; p.render(); } @@ -95,7 +107,10 @@ export const EdPopCode = () => { const CodeBody = () => { const p = useGlobal(EDGlobal, "EDITOR"); - const local = useLocal({ namePicker: false, codeAssign: false }); + const local = useLocal({ + namePicker: false, + codeAssign: false, + }); const vscode_url = isLocalhost() ? "http://localhost:3000?" @@ -171,31 +186,54 @@ const CodeBody = () => { > */} -
{ - p.ui.popup.code.startup_running = - !p.ui.popup.code.startup_running; - p.render(); - }} - >
+ {["loading", "init"].includes(p.ui.popup.code.startup_status) ? ( +
+ + + + + + +
+ ) : ( +
{ + p.ui.popup.code.startup_status = "loading"; + p.render(); + }} + >
+ )}
{ if (item.childs) { for (const [_, v] of Object.entries(item.childs)) { - const carg: GenMetaArg = { - item: v, - is_root: false, - root: arg.root || arg.item, - parent: { - item: meta.item, - instance_id: arg.parent?.instance_id, - comp: arg.parent?.comp, - root_instances: arg.parent?.root_instances, - }, - }; - if (arg.jsx_prop) { - carg.jsx_prop = { - ...arg.jsx_prop, + if (v.id) { + const carg: GenMetaArg = { + item: v, is_root: false, + root: arg.root || arg.item, + parent: { + item: meta.item, + instance_id: arg.parent?.instance_id, + comp: arg.parent?.comp, + root_instances: arg.parent?.root_instances, + }, }; + if (arg.jsx_prop) { + carg.jsx_prop = { + ...arg.jsx_prop, + is_root: false, + }; + } + genMeta(p, carg); + } else { + console.warn("invalid item", v); } - genMeta(p, carg); } } };