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

36 lines
996 B
Vue

<script setup lang="ts">
import { IChapter } from "@models/stories/chapter";
import { IStory } from "@models/stories";
import { storyEditMiddleware } from "@client/middleware";
import { SingleChapterResult } from "@client/types/slightlyDifferentStory";
import SingleChapter from "~/components/story/create/singleChapter.vue";
import { toFormChapter } from "@client/types/form/story";
definePageMeta({
middleware: ["auth", storyEditMiddleware],
});
const rtr = useRoute();
const {
data: { value: originalStory },
} = await useApiFetch<SingleChapterResult | null>(
`/story/${rtr.params.id}/${rtr.params.cidx}`,
);
if (originalStory === null) {
throw createError({
statusCode: 404,
message: "That story doesn't exist...",
});
}
useHead({
title: `Editing chapter: ${originalStory.currentChapter.title}`,
});
</script>
<template>
<single-chapter
:data="toFormChapter(originalStory!.currentChapter)"
:name="originalStory!.currentChapter.title"
/>
</template>