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

80 lines
2.9 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { SingleChapterResult } from "@client/types/slightlyDifferentStory";
import { theme } from "ant-design-vue";
import { storyMiddleware } from "@client/middleware";
import forChapter from "~/components/reviews/forChapter.vue";
import storyInfo from "~/components/story/view/storyInfo.vue";
import chapterPicker from "~/components/story/view/chapterPicker.vue";
import { IUser } from "@models/user";
import { recordView } from "@client/science";
const { useToken } = theme;
const { token } = useToken();
definePageMeta({
middleware: [storyMiddleware],
});
const rtr = useRoute();
2023-12-29 20:53:29 -05:00
const { data: story, error } = await useApiFetch<SingleChapterResult>(`/story/${rtr.params.id}/${rtr.params.cidx}`);
provide<SingleChapterResult | null>("story", story.value);
console.log("storyyy", story.value?.currentChapter);
console.log(rtr);
let dark = inject<boolean>("dark");
const and = computed(() => {
return story.value.coAuthor ? ` and ${story.value.coAuthor.username}` : "";
});
useHead({
title: `"${story.value.title}" by ${story.value.author.username}${and.value}`,
});
await recordView(story.value._id!);
</script>
<template>
<a-typography-title>
{{ story?.title }}
</a-typography-title>
<story-info />
<div>
<a-card
:style="{
backgroundColor: dark ? 'rgb(191, 54, 67)' : token.colorError,
display: 'flow-root',
color: '#fff',
}"
>
<div>
<a-typography-title :level="2"> Disclaimer </a-typography-title>
<a-divider style="background-color: #fff" />
{{ (story.author as IUser).profile.disclaimer }}
</div>
</a-card>
<a-typography-title :level="3">
{{ story.currentChapter.title }}
</a-typography-title>
<chapter-picker v-if="story.totalChapters > 1" />
<div style="display: flow-root">
<a-divider />
</div>
<div v-html="story?.currentChapter.text"></div>
<a-divider style="background-color: #fff" />
<a-button-group size="large" v-if="story.totalChapters > 1">
2023-12-29 20:53:29 -05:00
<a-button v-if="parseInt(rtr.params.cidx as string) > 1" @click="() => navigateTo(`/story/${rtr.params.id}/1`)"> First </a-button>
<a-button v-if="parseInt(rtr.params.cidx as string) > 1" @click="() => navigateTo(`/story/${rtr.params.id}/${parseInt(rtr.params.cidx as string) - 1}`)">
Previous
</a-button>
<a-button
2023-12-29 20:53:29 -05:00
v-if="parseInt(rtr.params.cidx as string) < story.chapterNames.length - 1"
@click="() => navigateTo(`/story/${rtr.params.id}/${parseInt(rtr.params.cidx as string) + 1}`)"
>
Next
</a-button>
<a-button
2023-12-29 20:53:29 -05:00
@click="() => navigateTo(`/story/${rtr.params.id}/${story.chapterNames.length}`)"
v-if="parseInt(rtr.params.cidx as string) < story.chapterNames.length - 1"
>
Last
</a-button>
</a-button-group>
2023-12-29 20:53:29 -05:00
<a-typography-title style="text-align: center" :level="2"> Reviews </a-typography-title>
<for-chapter :endpoint="`/story/${rtr.params.id}/${rtr.params.cidx}`" />
</div>
</template>