diff --git a/components/story/create/storyForm.vue b/components/story/create/storyForm.vue index ce36ef8..b80c0db 100644 --- a/components/story/create/storyForm.vue +++ b/components/story/create/storyForm.vue @@ -5,7 +5,7 @@ import { Field, FieldArray, useForm, useFieldArray } from "vee-validate"; import { ASpin } from "#components"; import { storySchema } from "@client/storyFormSchema"; - import { FormStory, defaultChapter } from "@client/types/form/story"; + import { FormStory, defaultChapter, FormChapter } from "@client/types/form/story"; import { autoEdit, autoSave, debouncedAutoEdit, debouncedAutoSave } from "@client/utils"; import findUser from "~/components/findUser.vue"; @@ -20,17 +20,16 @@ endpoint: string; endpointMethod: "put" | "post"; submitText?: string; + draftData?: { + endpoint: string; + endpointMethod: "put" | "post"; + }; }>(); - let w; - onMounted(() => { - w = window; - }); const dc = defaultChapter; - // data: FormStory; const sdata = defineModel("data", { required: true, }); - let drag = false; + let drag: boolean = false; const expandos = ref([]); function logSubmit(values, actions) { @@ -46,27 +45,32 @@ otherBtnInvoked.value = false; await autoSave(values); } else { - const { data: dat } = await useApiFetch(`/story/new`, { + const { data: dat } = await useApiFetch(`/story/new`, { method: "post", body: values, }); - if (dat.success) { - await router.push(`/story/${dat.story._id}/1`); + if (dat.value.success) { + await router.push(`/story/${dat.value.story._id}/1`); } } } else { await autoEdit(values, props.endpoint, props.endpointMethod); } } - function inval({ values, errors, results }) { - logSubmit(values, undefined); - } + const { values, setFieldValue, handleSubmit } = useForm({ keepValuesOnUnmount: true, validationSchema: storySchema, initialValues: sdata.value, }); - // const { push, remove, move, fields } = useFieldArray("chapters"); + function renumber(update: (idx: number, value: FormChapter) => void) { + for (let i = 0; i < values.chapters.length; i++) { + const nv = values.chapters[i]; + nv.index = i + 1; + update(i, nv); + sdata.value.chapters[i].index = i + 1; + } + } const subCb = handleSubmit(onSubmit); const pushHOF = (push) => (e) => { @@ -96,7 +100,18 @@ };