diff --git a/src/app/books/[bookId]/page.tsx b/src/app/books/[bookId]/page.tsx index e542e06..52a61e1 100644 --- a/src/app/books/[bookId]/page.tsx +++ b/src/app/books/[bookId]/page.tsx @@ -1,5 +1,5 @@ import { fetchBookById } from "@/lib/api"; -import { Book } from "@/lib/types"; +import { Book, Chapter } from "@/lib/types"; import { formatDateToMonthDayYear } from "@/lib/utils"; import ChapterDropdown from "@/components/ChapterDropdown"; import { Ad } from "@/lib/types"; @@ -26,8 +26,10 @@ export default async function BookPage(props: { params: paramsType }) { } const { title, author, description, chapters, cover } = book; + const sorted_chapters:Chapter[] = chapters.sort((a, b) => a.number - b.number); + const cover_media = cover?.at(0); - const recentChapters = chapters.length > 6 ? chapters.slice(chapters.length - 6, chapters.length) : chapters; + const recentChapters = sorted_chapters.length > 6 ? sorted_chapters.slice(sorted_chapters.length - 6, sorted_chapters.length) : sorted_chapters; return (
@@ -74,9 +76,9 @@ export default async function BookPage(props: { params: paramsType }) {

All Chapters

- +
- {chapters.map((chapter) => ( + {sorted_chapters.map((chapter) => (
  • ( * Populates optional fields like Chapters or Editors based on requirements. */ export async function fetchBooks(): Promise { - const data = await fetchFromAPI<{ data: Book[] }>("/api/books?populate=*"); + const data = await fetchFromAPI<{ data: Book[] }>("/api/books?populate=*&chapters.sort=number:desc"); return data.data; } @@ -72,6 +72,7 @@ export async function fetchBookById(bookId: string): Promise { const data = await fetchFromAPI<{ data: Book }>( `/api/books/${bookId}?populate[chapters][filters][release_datetime][$lte]=${currentDateTime}&populate=cover` ); + data.data.chapters = data.data.chapters.sort((a, b) => a.number - b.number); return data.data; }