/** * Component: Requests Page * Documentation: documentation/frontend/components.md */ 'use client'; import { useState } from 'react'; import { Header } from '@/components/layout/Header'; import { RequestCard } from '@/components/requests/RequestCard'; import { useRequests } from '@/lib/hooks/useRequests'; import { useAuth } from '@/contexts/AuthContext'; import { usePreferences } from '@/contexts/PreferencesContext'; import { cn } from '@/lib/utils/cn'; type FilterStatus = 'all' | 'active' | 'waiting' | 'completed' | 'failed' | 'cancelled'; export default function RequestsPage() { const { user } = useAuth(); const { squareCovers } = usePreferences(); const [filter, setFilter] = useState('all'); // Always fetch only the current user's requests (even for admins) // This ensures "My Requests" truly shows only the user's own requests // Admins can see all requests in the admin panel const { requests, isLoading } = useRequests(undefined, 50, true); // Filter requests client-side based on selected filter const filteredRequests = filter === 'all' ? requests : filter === 'active' ? requests.filter((r: any) => ['pending', 'searching', 'downloading', 'processing'].includes(r.status)) : filter === 'waiting' ? requests.filter((r: any) => ['awaiting_search', 'awaiting_import'].includes(r.status)) : filter === 'completed' ? requests.filter((r: any) => ['available', 'downloaded'].includes(r.status)) : requests.filter((r: any) => r.status === filter); const filterOptions: { value: FilterStatus; label: string }[] = [ { value: 'all', label: 'All' }, { value: 'active', label: 'Active' }, { value: 'waiting', label: 'Waiting' }, { value: 'completed', label: 'Completed' }, { value: 'failed', label: 'Failed' }, { value: 'cancelled', label: 'Cancelled' }, ]; // Redirect to login if not authenticated if (!user) { return (

Authentication Required

Please log in to view your audiobook requests

); } return (
{/* Page Header */}

My Requests

Track the status of your audiobook requests in real-time

{/* Filter Tabs */}
{filterOptions.map((option) => ( ))}
{/* Loading State */} {isLoading && (
{[1, 2, 3].map((i) => (
))}
)} {/* Requests List */} {!isLoading && filteredRequests.length > 0 && (
{filteredRequests.map((request: any) => ( ))}
)} {/* Empty State */} {!isLoading && filteredRequests.length === 0 && (

{filter === 'all' ? 'No requests yet' : `No ${filter} requests`}

{filter === 'all' ? 'Start by searching for audiobooks and requesting them' : `You don't have any ${filter} requests at the moment` }

{filter === 'all' && ( )}
)} {/* Auto-refresh indicator */} {!isLoading && filteredRequests.length > 0 && (
Auto-refreshing every 5 seconds
)}
); }