From fd951c294f1c0bab71888d1cb483fa75c51f591a Mon Sep 17 00:00:00 2001 From: Peaceultime Date: Mon, 2 Dec 2024 15:31:16 +0100 Subject: [PATCH] Rework the project editor to include file edition and display the file sorter in the sidebar. --- components/Editor.vue | 12 +- components/base/DraggableTree.vue | 2 +- db.sqlite | Bin 569344 -> 569344 bytes db.sqlite-shm | Bin 32768 -> 32768 bytes db.sqlite-wal | Bin 362592 -> 1582112 bytes layouts/default.vue | 10 +- layouts/null.vue | 3 + nuxt.config.ts | 17 +- pages/explore/[...path].vue | 3 +- pages/explore/edit/[...path].vue | 124 ----------- pages/explore/edit/index.vue | 341 ++++++++++++++++++++---------- server/api/project.post.ts | 21 +- 12 files changed, 270 insertions(+), 263 deletions(-) create mode 100644 layouts/null.vue delete mode 100644 pages/explore/edit/[...path].vue diff --git a/components/Editor.vue b/components/Editor.vue index 3b5e5e7..0a22a43 100644 --- a/components/Editor.vue +++ b/components/Editor.vue @@ -3,11 +3,11 @@ const External = Annotation.define(); \ No newline at end of file diff --git a/pages/explore/edit/index.vue b/pages/explore/edit/index.vue index 0c67441..49a3f89 100644 --- a/pages/explore/edit/index.vue +++ b/pages/explore/edit/index.vue @@ -1,110 +1,164 @@ \ No newline at end of file diff --git a/server/api/project.post.ts b/server/api/project.post.ts index dd2fb72..3f9ef73 100644 --- a/server/api/project.post.ts +++ b/server/api/project.post.ts @@ -20,22 +20,27 @@ export default defineEventHandler(async (e) => { throw body.error; } - const items = buildOrder(body.data.items); + const items = buildOrder(body.data.items) as Array; const db = useDatabase(); - const { content, ...cols } = getTableColumns(explorerContentTable); - const full = db.select(cols).from(explorerContentTable).all(); + const { ...cols } = getTableColumns(explorerContentTable); + const full = db.select(cols).from(explorerContentTable).all() as Record[]; for(let i = full.length - 1; i >= 0; i--) { - if(items.find(e => (e.path === '' ? [e.parent, parsePath(e.name === '' ? e.title : e.name)].filter(e => !!e).join('/') : e.path) === full[i].path)) - full.splice(i, 1); + const item = items.find(e => (e.path === '' ? [e.parent, parsePath(e.name === '' ? e.title : e.name)].filter(e => !!e).join('/') : e.path) === full[i].path); + if(item) + { + item.match = i; + full[i].include = true; + } } db.transaction((tx) => { for(let i = 0; i < items.length; i++) { const item = items[i]; + const old = full[item.match!]; tx.insert(explorerContentTable).values({ path: item.path, @@ -45,7 +50,7 @@ export default defineEventHandler(async (e) => { navigable: item.navigable, private: item.private, order: item.order, - content: null, + content: item.content ?? old.content, }).onConflictDoUpdate({ set: { path: [item.parent, parsePath(item.name === '' ? item.title : item.name)].filter(e => !!e).join('/'), @@ -55,13 +60,15 @@ export default defineEventHandler(async (e) => { private: item.private, order: item.order, timestamp: new Date(), + content: item.content ?? old.content, }, target: explorerContentTable.path, }).run(); } for(let i = 0; i < full.length; i++) { - tx.delete(explorerContentTable).where(eq(explorerContentTable.path, full[i].path)).run(); + if(full[i].include !== true) + tx.delete(explorerContentTable).where(eq(explorerContentTable.path, full[i].path)).run(); } }); });