Audio Hooks
useMediaSession
Integrates with the browser’s Media Session API for system-level media controls. Location:src/hooks/use-media-session.ts:19
Reference to the audio element
Current playlist array
Index of currently playing track
Current playback state
Callback when play action triggered
Callback when pause action triggered
Callback when next track action triggered
Callback when previous track action triggered
- Sets media metadata (title, artist, artwork)
- Handles system media controls (play, pause, next, previous)
- Updates position state every second
- Automatically cleans up on unmount
useSleepTimer
Manages a sleep timer that pauses playback after a specified duration. Location:src/hooks/use-sleep-timer.ts:3
Function to pause playback when timer expires
Remaining time in seconds, or null if no timer is active
Start a sleep timer. Pass number for minutes, or
'end' for 120 minutesCancel the active sleep timer
- Real-time countdown with 1-second updates
- Automatic cleanup on unmount
- Supports both fixed durations and “until end” mode
- Pauses playback when timer expires
State Management Hooks
useFavorites
Manages favorite reciters with local storage and real-time sync. Location:src/hooks/use-favorites.ts:11
Parameters: None
Array of favorite reciter IDs
Global favorite counts for all reciters (from GunDB)
Add or remove a reciter from favorites
Filter state for showing only favorites
Toggle favorites-only filter
- Syncs with GunDB for global favorite counts
- Real-time updates via subscription
- Persists to local storage via Jotai atom
useFilterSort
Provides filtering and sorting logic for reciter lists. Location:src/hooks/use-filter-sort.ts:19
Array of all reciters to filter/sort
Array of favorite reciter IDs
Whether to show only favorites
Global favorite counts for sorting
View counts for sorting
Current search query
Update search query
Currently selected riwaya filter
Change riwaya filter
Current sort mode
Change sort mode
Filtered and sorted reciter array
Available riwaya options with localized labels
- Search by normalized Arabic text
- Filter by riwaya type
- Filter by favorites
- Sort by popularity, alphabetical, or views
- Automatically updates when inputs change
- Internationalized riwaya labels
UI Hooks
useKeyboardNavigation
Enables keyboard navigation through a list with arrow keys. Location:src/hooks/use-keyboard-navigation.ts:3
Total number of navigable items
Currently focused item index
Manually set focused index
Array ref for storing element references
Ref for search input (focused on ESC)
- Arrow Up/Down navigation with wraparound
- ESC to unfocus and return to search
- Auto-scroll focused item into view
- Smooth scrolling behavior
useDirection
Determines text direction (LTR/RTL) based on current locale. Location:src/hooks/use-direction.ts:3
Parameters: None
true if current locale is Arabic (RTL), false otherwise- Uses react-intl locale context
- Simple boolean output for conditional rendering
Data Fetching Hooks
useReciters
Fetches and manages the list of available Quran reciters from the MP3 Quran API. Location:src/hooks/use-reciters.ts:11
Parameters: None (uses locale from react-intl context)
Array of available reciters with their moshaf details
true while fetching data, false when completeError message if fetch failed,
null otherwise- Automatically fetches based on current locale (Arabic/English)
- Manages loading and error states
- Updates selected reciter if it changes
- Cleans up on unmount to prevent memory leaks
UI Hooks
useEscapeKey
Listens for the Escape key and triggers a callback when pressed. Location:src/hooks/use-escape-key-hook.ts:6
Callback function to execute when Escape key is pressed
- Uses
useLayoutEffectfor immediate DOM updates - Automatically cleans up event listener on unmount
- Commonly used for closing modals and dialogs