From da6b17b1949195ef8d12c560b995d6f202cc78c2 Mon Sep 17 00:00:00 2001 From: DomWane Date: Fri, 20 Sep 2024 12:06:54 +0200 Subject: [PATCH] fix: project data save --- composables/useProject.ts | 12 +++++++----- pages/project/[id]/edit.vue | 4 ++++ pages/project/create.vue | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/composables/useProject.ts b/composables/useProject.ts index 2b55d47..7086760 100644 --- a/composables/useProject.ts +++ b/composables/useProject.ts @@ -30,14 +30,16 @@ export const useProject = defineStore('project', () => { async function publishProject() { isPublishing.value = true try { - const imageArrayBuffer = await projectImage.value?.arrayBuffer() let imageBuffer: Buffer | undefined let base64Image: string | undefined - if (imageArrayBuffer) { - imageBuffer = Buffer.from(imageArrayBuffer) - const base64String = imageBuffer.toString('base64') - base64Image = base64String + if (projectImage.value) { + const imageArrayBuffer = await projectImage.value?.arrayBuffer() + if (imageArrayBuffer) { + imageBuffer = Buffer.from(imageArrayBuffer) + const base64String = imageBuffer.toString('base64') + base64Image = base64String + } } await $fetch(`/api/data`, { diff --git a/pages/project/[id]/edit.vue b/pages/project/[id]/edit.vue index 00b50e0..d53abb9 100644 --- a/pages/project/[id]/edit.vue +++ b/pages/project/[id]/edit.vue @@ -98,6 +98,7 @@ name.value = project.value?.name || 'Untitled' function save() { saveProject({ + ...project.value, name: name.value, }) } @@ -123,11 +124,14 @@ async function publish() { if (selectedTab.value === 'basic_info') { if (!currentComponent.value.isFormValid()) return + else save() } else if (isPublishing) { return } + currentComponent.value.save() + await publishProject() navigateTo(`/project/${project.value?.id || project.value?.name?.toLowerCase().replace(/\s+/g, '-')}`) } diff --git a/pages/project/create.vue b/pages/project/create.vue index a49cc45..fbadc91 100644 --- a/pages/project/create.vue +++ b/pages/project/create.vue @@ -107,13 +107,16 @@ async function publish() { if (selectedTab.value === 'basic_info') { if (!currentComponent.value.isFormValid()) return + else save() } else if (isPublishing) { return } + currentComponent.value?.save() + await publishProject() - navigateTo(`/project/${project.value?.id || project.value?.name?.toLowerCase().replace(/\s+/g, '-')}`) + navigateTo('/') } function jumpTo(tab: string) {