"use client"; import { clearList, resetList, deleteBook } from "@/lib/features/bookSlice"; import { useAppDispatch, useAppSelector } from "@/lib/hooks"; const Books = () => { const { books } = useAppSelector((store) => store.books); const dispatch = useAppDispatch(); const handleClear = () => { dispatch(clearList()); }; const reset = () => { dispatch(resetList()); }; const remove = (id: any) => { dispatch(deleteBook(id)); }; return (
{/* Header Section */}
Advanced Web Development

Books by J.K. Rowling

Total Available:{" "} {books.length}

{/* Action Buttons */}
{books.length > 0 ? ( ) : ( )}
{/* Book Grid / Empty State */} {books.length > 0 ? (
{books.map((book) => { const { id, volumeInfo, saleInfo } = book; const thumbnail = volumeInfo.imageLinks?.thumbnail; const price = saleInfo.listPrice?.amount ? `${saleInfo.listPrice.amount} ${saleInfo.listPrice.currencyCode}` : "Not for Sale"; return (
{/* Top Row: Category & Rating */}
{volumeInfo.categories?.[0] || "General"} {volumeInfo.averageRating && (
★ {volumeInfo.averageRating}
)}
{/* Book Thumbnail & Info */}
{thumbnail ? ( {volumeInfo.title} ) : (
No Cover
)}

{volumeInfo.title}

{volumeInfo.authors?.join(", ")}

{volumeInfo.publishedDate?.split("-")[0]} •{" "} {volumeInfo.publisher}

{/* Description Snippet */} {volumeInfo.description && (

{volumeInfo.description}

)}
{/* Card Footer */}
{price} Preview Book
); })}
) : ( /* Empty State Alert */
{/* books emoji character unicode code point: U+1F4DA */}
📚

No Books to Display

You cleared the list of books. Click below to restore the Google Books dataset.

)}
); }; export default Books;