From 739cfb5efffeff4159015ed3814b833c67a78e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Fri, 15 Mar 2024 19:05:23 -0400 Subject: [PATCH] fix(components): make it so that reordering chapters in the story form no longer causes catastrophic state loss, rendering the tinymce components useless all hail PORTALS!!!!! --- components/baseEditor.vue | 6 + components/story/create/storyForm.vue | 153 ++++++++++++++------------ 2 files changed, 88 insertions(+), 71 deletions(-) diff --git a/components/baseEditor.vue b/components/baseEditor.vue index f8dcbae..c86a695 100644 --- a/components/baseEditor.vue +++ b/components/baseEditor.vue @@ -19,6 +19,12 @@ (); + let w; + onMounted(() => { + w = window; + }); const dc = defaultChapter; // data: FormStory; - const data = defineModel("data", { + const sdata = defineModel("data", { required: true, }); let drag = false; @@ -54,114 +58,121 @@ const { values, setFieldValue, handleSubmit } = useForm({ keepValuesOnUnmount: true, validationSchema: storySchema, - initialValues: data.value, + initialValues: sdata.value, }); + // const { push, remove, move, fields } = useFieldArray("chapters"); const subCb = handleSubmit(onSubmit); + + const pushHOF = (push) => (e) => { + if (!Array.isArray(values.chapters)) { + // noinspection TypeScriptValidateTypes + setFieldValue("chapters", []); + } + const chaps = [...toRaw(values.chapters)]; + let lastIndex = chaps.length - 1; + if (lastIndex < 0) lastIndex = 0; + let lastChapter = chaps[lastIndex]; + // log.debug('chaptrs->', chaps); + // log.debug('lastIndex->', lastIndex, lastChapter); + let newChapter = Object.assign({}, defaultChapter, { + summary: lastChapter?.summary || "", + index: (lastChapter?.index || 0) + 1, + bands: lastChapter?.bands || [], + characters: lastChapter?.characters || [], + relationships: lastChapter?.relationships || [], + uuidKey: v4(), + genre: lastChapter?.genre || [], + }); + // console.debug("nc->", newChapter); + // console.debug("pushi -> ", push); + push(newChapter); + sdata.value.chapters.push(newChapter); + };