fix: form init

This commit is contained in:
DomWane 2024-10-02 16:32:52 +02:00
parent 5e37314daf
commit 1bcf0903ab
4 changed files with 10 additions and 4 deletions

View file

@ -8,7 +8,6 @@ export const useProject = defineStore('project', () => {
const { getProjectById } = useData()
function setProject(id: string) {
clearProject()
project.value = getProjectById(id, { shallow: false }) as Project
delete project.value.ratings
}

View file

@ -15,7 +15,6 @@ export const useProjectForm = defineStore('useProjectForm', () => {
const isEditingName = ref(false)
const { value: name, errorMessage: nameError } = useField<string>('name', yup.string().required().notOneOf(['Untitled', 'Undefined', 'Create', 'create']))
name.value = project.value?.name || 'Untitled'
function toggleEditName() {
isEditingName.value = !isEditingName.value
@ -87,6 +86,11 @@ export const useProjectForm = defineStore('useProjectForm', () => {
navigateTo(`/project/${project.value?.id || project.value?.name?.toLowerCase().replace(/\s+/g, '-')}`)
}
function initForm() {
selectedTab.value = 0
name.value = 'Untitled'
}
return {
isEditingName,
name,
@ -100,5 +104,6 @@ export const useProjectForm = defineStore('useProjectForm', () => {
publish,
jumpTo,
isPublishing,
initForm,
}
})

View file

@ -6,9 +6,11 @@ definePageMeta({
const { projects } = useData()
const { setProject, saveProjectImage } = useProject()
const { project } = storeToRefs(useProject())
const { initForm } = useProjectForm()
const route = useRoute()
await until(projects).toMatch(p => p?.length > 0)
initForm()
setProject(route.params.id as string)
if (!project.value) {

View file

@ -24,7 +24,7 @@ onChange((files) => {
saveProjectImage(file)
})
const { next, jumpTo, publish, toggleEditName } = useProjectForm()
const { next, jumpTo, publish, toggleEditName, initForm } = useProjectForm()
const { currentComponent, selectedTab, tabsArray, isEditingName, name, nameError, isPublishing } = storeToRefs(useProjectForm())
const projectNameInput = ref<HTMLInputElement | null>(null)
@ -40,7 +40,7 @@ const transitionDone = ref(false)
onBeforeMount(() => {
clearProject()
name.value = 'Untitled'
initForm()
})
</script>