next/pages/story/[id]/edit.vue

52 lines
1.7 KiB
Vue
Raw Normal View History

2023-10-11 16:46:57 -04:00
<script lang="ts" setup>
import { v4 } from "uuid";
import storyForm from "~/components/story/create/storyForm.vue";
import { FormChapter, FormStory } from "@client/types/form/story";
import { IStory } from "@models/stories";
import { IChapter } from "@models/stories/chapter";
import { storyEditMiddleware } from "@client/middleware";
2023-12-29 20:11:07 -05:00
import { IBand } from "@models/band";
import { IUser } from "@models/user";
2023-10-11 16:46:57 -04:00
const rtr = useRoute();
const { data: originalStory } = await useApiFetch<({ chapters: (IChapter & { text: string })[] } & IStory) | null>(`/story/${rtr.params.id}/full`);
if (originalStory.value === null) {
console.log("IT DOESN'T EXIST DAWG");
throw createError({
statusCode: 404,
message: "That story doesn't exist...",
});
2023-10-11 16:46:57 -04:00
}
definePageMeta({
2023-12-29 20:11:07 -05:00
middleware: ["auth", storyEditMiddleware],
2023-10-11 16:46:57 -04:00
});
const story: FormStory = ref<FormStory>({
title: originalStory.value!.title,
coAuthor: originalStory.value.coAuthor ? (originalStory.coAuthor as IUser)._id : null,
completed: originalStory.value!.completed,
chapters: originalStory.value!.chapters.map((a, i) => {
// delete
return {
...a,
chapterTitle: a.title,
id: a.id,
index: i + 1,
bands: (a.bands as IBand[]).map((a) => a._id),
content: a.text,
uuidKey: v4(),
pot: "pasteOrType",
} as FormChapter;
}),
});
useHead({
title: `Editing story: ${originalStory?.title}`,
});
2023-10-11 16:46:57 -04:00
</script>
<template>
2023-12-29 20:11:07 -05:00
<a-typography-title style="text-align: center"> Editing "{{ originalStory?.title }}" </a-typography-title>
<!-- <client-only>-->
<story-form :can-draft="false" v-model:data="story" :endpoint="`/story/${rtr.params.id}`" endpoint-method="put" />
<!-- </client-only>-->
2023-10-11 16:46:57 -04:00
</template>