/** * Component: Homepage - Audiobook Discovery * Documentation: documentation/frontend/components.md */ 'use client'; import { useState, useRef, useMemo } from 'react'; import { Header } from '@/components/layout/Header'; import { AudiobookGrid } from '@/components/audiobooks/AudiobookGrid'; import { useAudiobooks, Audiobook } from '@/lib/hooks/useAudiobooks'; import { ProtectedRoute } from '@/components/auth/ProtectedRoute'; import { StickyPagination } from '@/components/ui/StickyPagination'; 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); const { audiobooks: newReleases, isLoading: loadingNewReleases, totalPages: newReleasesTotalPages, message: newReleasesMessage, } = useAudiobooks('new-releases', 20, newReleasesPage); // Filter out available titles when hideAvailable is enabled const filteredPopular = useMemo( () => hideAvailable ? popular.filter((b: Audiobook) => !b.isAvailable && b.requestStatus !== 'completed') : popular, [popular, hideAvailable] ); const filteredNewReleases = useMemo( () => hideAvailable ? newReleases.filter((b: Audiobook) => !b.isAvailable && b.requestStatus !== 'completed') : newReleases, [newReleases, 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

{/* Sticky Pagination Controls */}
); }