Added releases changed the way apis work underneath to give more room for caching, i.e remove unneeded crap when it is unneeded
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React from "react";
|
||||
import NavigationButtons from "@/components/NavigationButtons";
|
||||
import { Book, Chapter } from "@/lib/types";
|
||||
import { fetchBookById } from "@/lib/api";
|
||||
import { Chapter } from "@/lib/types";
|
||||
import {fetchChapterByBookId } from "@/lib/api";
|
||||
export type paramsType = Promise<{ bookId: string; chapterId: string }>;
|
||||
|
||||
export const metadata = {
|
||||
@@ -13,13 +13,12 @@ export const metadata = {
|
||||
export default async function ChapterPage(props: { params: paramsType}) {
|
||||
const { bookId, chapterId } = await props.params;
|
||||
|
||||
let book: Book;
|
||||
let chapters: Chapter[];
|
||||
try{
|
||||
book = await fetchBookById(bookId);
|
||||
chapters = await fetchChapterByBookId(bookId, chapterId);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
|
||||
return (
|
||||
<div className="prose dark:prose-invert mx-auto p-6 bg-white dark:bg-gray-800 shadow-md rounded-lg mt-4">
|
||||
<div dangerouslySetInnerHTML={{ __html: '<center><h1> Chapter not found !</h1></center>' }}></div>
|
||||
@@ -28,11 +27,10 @@ export default async function ChapterPage(props: { params: paramsType}) {
|
||||
)
|
||||
}
|
||||
|
||||
const chapters :Chapter[] = book.chapters;
|
||||
const sorted_chapters:Chapter[] = chapters.sort((a, b) => a.number - b.number);
|
||||
const current_chapter = sorted_chapters.find((chapter) => chapter.documentId === chapterId) || null;
|
||||
const next_chapter = current_chapter ? sorted_chapters.find((chapter) => chapter.number === current_chapter.number + 1)?.documentId || "" : "";
|
||||
const prev_chapter = current_chapter ? sorted_chapters.find((chapter) => chapter.number === current_chapter.number - 1)?.documentId || "" : "";
|
||||
const next_chapter = current_chapter ? sorted_chapters.find((chapter) => chapter.number === current_chapter.number + 1 && new Date(chapter.release_datetime).getTime() <= new Date().getTime())?.documentId || "" : "";
|
||||
const prev_chapter = current_chapter ? sorted_chapters.find((chapter) => chapter.number === current_chapter.number - 1 && new Date(chapter.release_datetime).getTime() <= new Date().getTime())?.documentId || "" : "";
|
||||
|
||||
if(current_chapter === null){
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user