Open History to see the last commit
1import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
2import { useAtomSet, useAtomValue } from "@effect/atom-react";
3import { AsyncResult } from "effect/reactivity";
4import { useSafeAreaInsets } from "react-native-safe-area-context";
5
6import { useGT } from "gt-react-native";
7import { useLanguagePreference } from "../../i18n/I18nProvider";
8import { SYSTEM_LANGUAGE, nativeLanguageName } from "@t3tools/client-runtime/locales";
9import { SUPPORTED_LOCALES } from "../../i18n/locales";
10import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
11import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
12import { SettingsRow } from "./components/SettingsRow";
13import { SettingsSection } from "./components/SettingsSection";
14import { SettingsScreen } from "./components/SettingsScreen";
15
16/** General's row that opens the language picker, showing the current choice. */
17export function LanguageSettingsSection() {
18 const gt = useGT();
19 const language = useLanguagePreference();
20 return (
21 <SettingsSection>
22 <SettingsRow
23 icon="globe"
24 label={gt("Language")}
25 value={
26 SUPPORTED_LOCALES.includes(language) ? nativeLanguageName(language) : gt("System default")
27 }
28 target="SettingsLanguage"
29 />
30 </SettingsSection>
31 );
32}
33
34export function SettingsLanguageRouteScreen() {
35 const gt = useGT();
36 const insets = useSafeAreaInsets();
37 const preferencesResult = useAtomValue(mobilePreferencesAtom);
38 const savePreferences = useAtomSet(updateMobilePreferencesAtom);
39 const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
40 const language = useLanguagePreference();
41 const options = [
42 { language: SYSTEM_LANGUAGE, label: gt("System default") },
43 ...SUPPORTED_LOCALES.map((locale) => ({ language: locale, label: nativeLanguageName(locale) })),
44 ];
45
46 return (
47 <SettingsScreen title={gt("Language")}>
48 <ScrollView
49 contentInsetAdjustmentBehavior="automatic"
50 showsVerticalScrollIndicator={false}
51 className="flex-1"
52 contentContainerClassName="gap-3 px-5 pt-4"
53 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
54 >
55 <SettingsSection>
56 {options.map((option, index) => (
57 <SettingsChoiceRow
58 key={option.language}
59 label={option.label}
60 selected={preferencesReady && language === option.language}
61 separated={index > 0}
62 disabled={!preferencesReady}
63 onPress={() => savePreferences({ language: option.language })}
64 />
65 ))}
66 </SettingsSection>
67 </ScrollView>
68 </SettingsScreen>
69 );
70}