From 3d742b968b88b384726b437d2b119324195343d5 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?= <i.am.the.tablet@proton.me> Date: Wed, 11 Oct 2023 16:46:57 -0400 Subject: [PATCH] feat(pages): create story editing page --- pages/story/[id]/edit.vue | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 pages/story/[id]/edit.vue diff --git a/pages/story/[id]/edit.vue b/pages/story/[id]/edit.vue new file mode 100644 index 0000000..0e8df2d --- /dev/null +++ b/pages/story/[id]/edit.vue @@ -0,0 +1,62 @@ +<script lang="ts" setup> + import { v4 } from "uuid"; + import storyForm from "~/components/story/create/storyform.vue"; + import { FormStory } from "~/lib/client/types/form/story"; + import { IStory } from "~/models/stories"; + import { IChapter } from "~/models/stories/chapter"; + const rtr = useRoute(); + const { + data: { value: originalStory }, + } = await useApiFetch<{ chapters: (IChapter & { text: string })[] } & IStory>( + `/story/${rtr.params.id}/full`, + ); + if (!originalStory) { + await navigateTo("/not-found"); + } + definePageMeta({ + middleware: [ + (from, to) => { + const { data: curu } = useAuth(); + if ( + curu.value?.user?._id !== originalStory?.author._id && + curu.value?.user?._id !== originalStory?.coAuthor._id + ) { + return navigateTo("/403"); + } + }, + ], + }); + const story: FormStory = { + title: originalStory!.title, + coAuthor: originalStory?.coAuthor._id, + completed: originalStory!.completed, + chapters: originalStory!.chapters.map((a, i) => ({ + id: a.id, + chapterTitle: a.title, + index: i + 1, + summary: a.summary, + notes: a.notes, + genre: a.genre, + bands: a.bands.map((a) => a._id), + characters: a.characters, + relationships: a.relationships, + nsfw: a.nsfw, + loggedInOnly: a.loggedInOnly, + hidden: a.hidden, + content: a.text, + uuidKey: v4(), + })), + }; +</script> +<template> + <a-typography-title style="text-align: center"> + Editing "{{ originalStory!.title }}" + </a-typography-title> + <story-form + :can-draft="false" + :data="story" + :endpoint="`/story/${rtr.params.id}`" + endpoint-method="put" + > + </story-form> +</template>