feat: Add continuous Bible reading mode, backend-driven translation API integration, localized book names, and preference caching

This commit is contained in:
Adolfo Reyna
2026-02-25 18:13:53 -05:00
parent fc6f740fd2
commit 9da5874977
8 changed files with 460 additions and 56 deletions

View File

@@ -2,11 +2,14 @@ import React, { useMemo, useState } from "react";
import { StyleSheet, Text, View } from "react-native";
import { ActivityIndicator, Chip } from "react-native-paper";
import { useNavigation } from "@react-navigation/native";
import { extractBibleReferences, fetchBiblePassage } from "../utils/bibleReferences.js";
import { extractBibleReferences, fetchBiblePassage, translateBibleReference } from "../utils/bibleReferences.js";
import GlobalState from "../contexts/GlobalState.js";
import { useSnapshot } from "valtio";
import i18n from "../i18nMessages.js";
const BibleEmbeddedView = ({ content = "", compact = false, openChapterOnPress = false }) => {
const navigation = useNavigation();
const gState = useSnapshot(GlobalState);
const references = useMemo(() => extractBibleReferences(content), [content]);
const [selectedRef, setSelectedRef] = useState("");
const [byReference, setByReference] = useState({});
@@ -24,7 +27,8 @@ const BibleEmbeddedView = ({ content = "", compact = false, openChapterOnPress =
setByReference((prev) => ({ ...prev, [reference]: { loading: true } }));
try {
const data = await fetchBiblePassage(reference, i18n.locale);
const preferredTranslation = GlobalState.me?.data?.bibleTranslation || "";
const data = await fetchBiblePassage(reference, i18n.locale, preferredTranslation);
setByReference((prev) => ({ ...prev, [reference]: { loading: false, ...data } }));
} catch (_error) {
setByReference((prev) => ({ ...prev, [reference]: { loading: false, error: true } }));
@@ -46,7 +50,7 @@ const BibleEmbeddedView = ({ content = "", compact = false, openChapterOnPress =
style={styles.chip}
onPress={() => handleSelectReference(reference)}
>
{reference}
{translateBibleReference(reference, i18n.locale)}
</Chip>
))}
</View>
@@ -55,7 +59,7 @@ const BibleEmbeddedView = ({ content = "", compact = false, openChapterOnPress =
<View style={styles.previewBox}>
<Text style={styles.previewText}>{selectedData.text.slice(0, compact ? 160 : 280)}</Text>
<Text style={styles.previewMeta}>
{selectedData.reference} ({selectedData.translation})
{translateBibleReference(selectedData.reference, i18n.locale)} ({selectedData.translation})
</Text>
</View>
) : null}