fix: project publish

This commit is contained in:
DomWane 2024-10-02 15:57:10 +02:00
parent 2f92361afb
commit 5e37314daf
4 changed files with 25 additions and 30 deletions

View file

@ -4,7 +4,6 @@ import type { Project } from '~/types'
export const useProject = defineStore('project', () => {
const project = ref<Partial<Project>>()
const projectImage = ref<File>()
const isPublishing = ref(false)
const { getProjectById } = useData()
@ -30,7 +29,6 @@ export const useProject = defineStore('project', () => {
}
async function publishProject() {
isPublishing.value = true
try {
let imageBuffer: Buffer | undefined
let base64Image: string | undefined
@ -58,14 +56,10 @@ export const useProject = defineStore('project', () => {
catch (e) {
console.error(e)
}
finally {
isPublishing.value = false
}
}
return {
project,
isPublishing,
setProject,
clearProject,
saveProject,

View file

@ -11,7 +11,7 @@ import ProjectCreateCategoriesHistory from '~/components/Project/Create/Categori
export const useProjectForm = defineStore('useProjectForm', () => {
const { saveProject, publishProject } = useProject()
const { project, isPublishing } = storeToRefs(useProject())
const { project } = storeToRefs(useProject())
const isEditingName = ref(false)
const { value: name, errorMessage: nameError } = useField<string>('name', yup.string().required().notOneOf(['Untitled', 'Undefined', 'Create', 'create']))
@ -45,10 +45,9 @@ export const useProjectForm = defineStore('useProjectForm', () => {
const currentComponent = ref()
async function next() {
if (selectedTab.value === 0) {
if (!(await currentComponent.value.isFormValid()) || nameError.value)
return
}
const isFormValid = selectedTab.value === 0 ? await currentComponent.value.isFormValid() : true
if (!isFormValid || nameError.value)
return
saveName()
currentComponent.value.save()
@ -59,12 +58,9 @@ export const useProjectForm = defineStore('useProjectForm', () => {
}
async function jumpTo(index: number) {
if (selectedTab.value === 0) {
if (!(await currentComponent.value.isFormValid()) || nameError.value)
return
if (nameError.value)
return
else saveName()
const isFormValid = selectedTab.value === 0 ? await currentComponent.value.isFormValid() : true
if (!isFormValid || nameError.value) {
return
}
saveName()
@ -73,19 +69,18 @@ export const useProjectForm = defineStore('useProjectForm', () => {
selectedTab.value = index
}
const isPublishing = ref(false)
async function publish(isNew?: boolean) {
if (selectedTab.value === 0) {
if (!(await currentComponent.value.isFormValid()) || nameError.value)
return
}
else if (isPublishing) {
isPublishing.value = true
const isFormValid = selectedTab.value === 0 ? await currentComponent.value.isFormValid() : true
if (!isFormValid || nameError.value)
return
}
saveName()
currentComponent.value?.save()
await publishProject()
isPublishing.value = false
if (isNew)
navigateTo('/')
else
@ -104,5 +99,6 @@ export const useProjectForm = defineStore('useProjectForm', () => {
next,
publish,
jumpTo,
isPublishing,
}
})

View file

@ -5,7 +5,7 @@ definePageMeta({
const { projects } = useData()
const { setProject, saveProjectImage } = useProject()
const { project, isPublishing } = storeToRefs(useProject())
const { project } = storeToRefs(useProject())
const route = useRoute()
await until(projects).toMatch(p => p?.length > 0)
@ -38,7 +38,7 @@ onChange((files) => {
})
const { next, jumpTo, publish, toggleEditName } = useProjectForm()
const { currentComponent, selectedTab, tabsArray, isEditingName, name, nameError } = storeToRefs(useProjectForm())
const { currentComponent, selectedTab, tabsArray, isEditingName, name, nameError, isPublishing } = storeToRefs(useProjectForm())
name.value = project.value?.name || 'Untitled'
const projectNameInput = ref<HTMLInputElement | null>(null)
@ -299,7 +299,7 @@ const transitionDone = ref(false)
w-full
lg="w-fit"
inverted-color
@click="publish()"
@click="isPublishing ? null : publish()"
>
<UnoIcon
v-if="isPublishing"

View file

@ -3,8 +3,8 @@ definePageMeta({
layout: 'create',
})
const { saveProjectImage } = useProject()
const { project, isPublishing } = storeToRefs(useProject())
const { saveProjectImage, clearProject } = useProject()
const { project } = storeToRefs(useProject())
const { open, onChange } = useFileDialog({
accept: 'image/*', // Set to accept only image files
@ -25,7 +25,7 @@ onChange((files) => {
})
const { next, jumpTo, publish, toggleEditName } = useProjectForm()
const { currentComponent, selectedTab, tabsArray, isEditingName, name, nameError } = storeToRefs(useProjectForm())
const { currentComponent, selectedTab, tabsArray, isEditingName, name, nameError, isPublishing } = storeToRefs(useProjectForm())
const projectNameInput = ref<HTMLInputElement | null>(null)
watch(isEditingName, () => {
@ -37,6 +37,11 @@ watch(isEditingName, () => {
})
const transitionDone = ref(false)
onBeforeMount(() => {
clearProject()
name.value = 'Untitled'
})
</script>
<template>
@ -284,7 +289,7 @@ const transitionDone = ref(false)
w-full
lg="w-fit"
inverted-color
@click="publish(true)"
@click="isPublishing ? null : publish(true)"
>
<UnoIcon
v-if="isPublishing"