/** * Component: Homepage - Audiobook Discovery * Documentation: documentation/frontend/components.md */ 'use client'; import { useState, useRef, useEffect } from 'react'; import { Header } from '@/components/layout/Header'; import { AudiobookGrid } from '@/components/audiobooks/AudiobookGrid'; import { useAudiobooks } from '@/lib/hooks/useAudiobooks'; import { ProtectedRoute } from '@/components/auth/ProtectedRoute'; import { UnifiedPagination } from '@/components/ui/UnifiedPagination'; import { SectionToolbar } from '@/components/ui/SectionToolbar'; import { usePreferences } from '@/contexts/PreferencesContext'; export default function HomePage() { const [popularPage, setPopularPage] = useState(1); const [newReleasesPage, setNewReleasesPage] = useState(1); const { cardSize, setCardSize, squareCovers, setSquareCovers, hideAvailable, setHideAvailable } = usePreferences(); // Refs for auto-scrolling to section tops const popularSectionRef = useRef(null); const newReleasesSectionRef = useRef(null); const footerRef = useRef(null); const { audiobooks: popular, isLoading: loadingPopular, totalPages: popularTotalPages, message: popularMessage, } = useAudiobooks('popular', 20, popularPage, hideAvailable); const { audiobooks: newReleases, isLoading: loadingNewReleases, totalPages: newReleasesTotalPages, message: newReleasesMessage, } = useAudiobooks('new-releases', 20, newReleasesPage, hideAvailable); // Reset to page 1 when hideAvailable changes (total pages may differ) useEffect(() => { setPopularPage(1); setNewReleasesPage(1); }, [hideAvailable]); // Handle page changes with auto-scroll to section top const handlePopularPageChange = (page: number) => { setPopularPage(page); popularSectionRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }); }; const handleNewReleasesPageChange = (page: number) => { setNewReleasesPage(page); newReleasesSectionRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }); }; return (
{/* Popular Audiobooks Section */}
{/* Sticky Section Header */}

Popular Audiobooks

{/* Section Content */}
{popularMessage && !loadingPopular && popular.length === 0 ? (

No popular audiobooks found

{popularMessage}

) : ( )}
{/* New Releases Section */}
{/* Sticky Section Header */}

New Releases

{/* Section Content */}
{newReleasesMessage && !loadingNewReleases && newReleases.length === 0 ? (

No new releases found

{newReleasesMessage}

) : ( )}
{/* Call to Action */}

Can't find what you're looking for?

Use our search to find any audiobook from Audible

Search Audiobooks
{/* Footer */}

ReadMeABook - Audiobook Library Management System

{/* Unified Pagination — single context-aware pill for both sections */} popularSectionRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }), }, { label: 'New Releases', accentColor: 'bg-emerald-500', currentPage: newReleasesPage, totalPages: newReleasesTotalPages, onPageChange: handleNewReleasesPageChange, sectionRef: newReleasesSectionRef, onScrollToSection: () => newReleasesSectionRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }), }, ]} />
); }