import { Badge } from '@/components/ui/badge' import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, } from '@/components/ui/pagination' import { Author, Book, Genre } from '@/payload-types' import { Avatar } from '../avatar' import { PaginatedDocs } from 'payload' import Link from 'next/link' import Image from 'next/image' type Props = { books: PaginatedDocs } const makeAuthorsLabel = (book: Book) => { const authors = book.authors as Author[] // TODO: endure this type safety const translators = authors?.filter((a) => a.role === 'Translator').map((t) => t.lf) const editors = authors?.filter((a) => a.role === 'Editor').map((e) => e.lf) const actualAuthors = authors ?.filter((a) => !editors.includes(a.lf) && !translators.includes(a.lf)) .map((a) => a.lf) return ( ) } const makeGenreBadges = (book: Book) => { return (book.genre as Genre[])?.map((g) => ( {g.name} )) } export default function BookList(props: Props) { const { docs, hasNextPage, hasPrevPage, limit, totalPages, page, prevPage, nextPage, totalDocs } = props.books const currentPage = page || 0 const books = docs return (
{hasPrevPage && currentPage > totalPages / 2 && ( )} {prevPage && ( {prevPage} )} {currentPage} {nextPage && ( {nextPage} )} {hasNextPage && currentPage < totalPages / 2 && ( )}

viewing {currentPage * limit - limit + 1}-{currentPage * limit} of {totalDocs}

) }