Make fewer IQ Bible calls
- 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>
This commit is contained in:
1 parent
d29a66f984
commit
31ac6b9179
7 files changed
+129
-17
No files matched your search
@@ -1,11 +1,13 @@
|
||||
// <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';
|
||||
|
||||
export default function IqNarratorOptions() {
|
||||
// `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 ? 'audio' : null);
|
||||
const { data } = useIq(on && enabled ? 'audio' : null);
|
||||
const sets = listOf(data).filter((s) => s.active !== false);
|
||||
if (!on || sets.length === 0) return null;
|
||||
return (
|
||||
@@ -14,3 +16,10 @@ export default function IqNarratorOptions() {
|
||||
</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 } };
|
||||
}
|
||||
Reference in new issue
Block a user