import { gql, useQuery } from '@apollo/client'; import { PaginatedListSkeleton } from '@app/client/components/PaginatedListSkeleton'; import { Pagination } from '@app/client/components/Pagination'; import { WorkingProgressStatusBadge } from '@app/client/components/WorkingProgressStatusBadge'; import { WorkingRatingBadge } from '@app/client/components/WorkingRatingBadge'; import { WorkingReviewsBadge } from '@app/client/components/WorkingReviewsTotalBadge'; import { bookChapterFragment, bookFragment } from '@app/client/fragments'; import { toFormattedDate } from '@app/client/helpers'; import { usePaginatedQuery } from '@app/client/hooks/usePaginatedQuery'; import { BookOne } from '@app/client/interfaces'; import { Heading, HStack, Skeleton, SkeletonCircle, SkeletonText, Stack, Text } from '@chakra-ui/react'; import { BookChapterListQuery, BookOverviewQuery } from '@generated/types'; import { createFileRoute, Link } from '@tanstack/react-router'; import { useState } from 'react'; export const Route = createFileRoute('/work/book/$bookId')({ component: RouteComponent }); function RouteComponent() { const { bookId: id } = Route.useParams(); const { data: bookData } = useQuery(bookQuery, { variables: { id } }); return ( {bookData != null ? : } ); } function BookOverview({ id, title, description, author, progressStatus, createdAt, updatedAt, wordsTotal, chaptersTotal, reviewsTotal, ratingTotal }: BookOne) { return ( {title} by: {author.username} created at: {toFormattedDate({ value: createdAt })} last updated: {toFormattedDate({ value: updatedAt })} chapters: {chaptersTotal} words: {wordsTotal} {description} ); } function BookChapterList({ id }: { readonly id: string }) { const [chaptersListPage, setChaptersListPage] = useState(1); const [chaptersListPageSize, setChaptersListPageSize] = useState(10); const startIndex = (chaptersListPage - 1) * chaptersListPageSize; const { data } = usePaginatedQuery({ query: bookChapterListQuery, input: { bookId: id, filter: { offset: startIndex, size: chaptersListPageSize } } }); return ( {data != null ? ( <> ...chapters {data.bookChapterMany.total > chaptersListPageSize && ( )} ) : ( )} ); } function BookOverviewSkeleton() { return ( ); } const bookQuery = gql` query BookOverview($id: ID!) { bookOne(id: $id) { ...Book } } ${bookFragment} `; const bookChapterListQuery = gql` query BookChapterList($input: BookChapterManyInput!) { bookChapterMany(input: $input) { items { ...BookChapter } total } } ${bookChapterFragment} `;