2023-10-11 16:46:57 -04:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { v4 } from "uuid";
|
2023-12-30 17:04:18 -05:00
|
|
|
import storyForm from "~/components/story/create/storyForm.vue";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { FormStory } from "@client/types/form/story";
|
|
|
|
import { IStory } from "@models/stories";
|
|
|
|
import { IChapter } from "@models/stories/chapter";
|
2023-12-09 17:15:07 -05:00
|
|
|
|
2023-12-20 17:23:31 -05:00
|
|
|
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: { value: originalStory },
|
2023-12-29 20:11:07 -05:00
|
|
|
} = await useApiFetch<({ chapters: (IChapter & { text: string })[] } & IStory) | null>(`/story/${rtr.params.id}/full`);
|
2023-12-09 17:15:07 -05:00
|
|
|
if (originalStory === 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 = {
|
|
|
|
title: originalStory!.title,
|
2023-12-29 20:11:07 -05:00
|
|
|
coAuthor: originalStory?.coAuthor ? (originalStory.coAuthor as IUser)._id : null,
|
2023-10-11 16:46:57 -04:00
|
|
|
completed: originalStory!.completed,
|
|
|
|
chapters: originalStory!.chapters.map((a, i) => ({
|
2023-12-09 17:15:07 -05:00
|
|
|
...a,
|
2023-10-11 16:46:57 -04:00
|
|
|
id: a.id,
|
|
|
|
chapterTitle: a.title,
|
|
|
|
index: i + 1,
|
2023-12-29 20:11:07 -05:00
|
|
|
bands: (a.bands as IBand[]).map((a) => a._id),
|
2023-10-11 16:46:57 -04:00
|
|
|
content: a.text,
|
|
|
|
uuidKey: v4(),
|
|
|
|
})),
|
|
|
|
};
|
2023-12-09 17:15:07 -05:00
|
|
|
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>
|
|
|
|
<story-form :can-draft="false" :data="story" :endpoint="`/story/${rtr.params.id}`" endpoint-method="put"> </story-form>
|
2023-10-11 16:46:57 -04:00
|
|
|
</template>
|