- Load the narrator list only when the audio dropdown is opened - Keep today's verse and devotional in memory for an hour (not saved) - Back off for a minute after 'allowance used up' or unreachable; keep 'nothing here' answers - Server shares one upstream call between identical simultaneous requests (nothing stored) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
26 lines
1.3 KiB
React
26 lines
1.3 KiB
React
// <option>s for IQ Bible's narrated Bibles, to add inside an audio narrator <select>. Playing a
|
|
// chapter this way uses one of the account's monthly audio streams, so the group says so.
|
|
import { useState } from 'react';
|
|
import { useIq, useIqAvailable } from '../../hooks/useIq.js';
|
|
import { listOf } from '../../utils/iqbible.js';
|
|
|
|
// `enabled` holds the request back until someone opens the list (or an IQ narration is already chosen).
|
|
export default function IqNarratorOptions({ enabled = true }) {
|
|
const on = useIqAvailable();
|
|
const { data } = useIq(on && enabled ? 'audio' : null);
|
|
const sets = listOf(data).filter((s) => s.active !== false);
|
|
if (!on || sets.length === 0) return null;
|
|
return (
|
|
<optgroup label="IQ Bible narrations (uses monthly streams)">
|
|
{sets.map((s) => <option key={s.audio_id} value={`iq:${s.audio_id}`}>{s.audio_id}{s.narrator ? ` · ${s.narrator}` : ''}</option>)}
|
|
</optgroup>
|
|
);
|
|
}
|
|
|
|
// For the <select> that holds these options: props to spread on it, and the `enabled` flag to pass along.
|
|
export function useLazyNarrators(value) {
|
|
const [opened, setOpened] = useState(false);
|
|
const open = () => setOpened(true);
|
|
return { enabled: opened || String(value ?? '').startsWith('iq:'), selectProps: { onFocus: open, onMouseDown: open, onTouchStart: open } };
|
|
}
|