Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update mobile app identity generator settings UI to move language selection to subview (#1566)
Leendert de Borstd94a4f51159d
diff --git a/apps/mobile-app/app/(tabs)/settings/_layout.tsx b/apps/mobile-app/app/(tabs)/settings/_layout.tsxindex 47f78bc03..83c31f4fd 100644--- a/apps/mobile-app/app/(tabs)/settings/_layout.tsx+++ b/apps/mobile-app/app/(tabs)/settings/_layout.tsx@@ -79,6 +79,15 @@ export default function SettingsLayout(): React.ReactNode {name="identity-generator"options={{title: t('settings.identityGenerator'),+ headerBackTitle: t('settings.title'),+ ...defaultHeaderOptions,+ }}+ />+ <Stack.Screen+ name="identity-generator-language"+ options={{+ title: t('settings.identityGeneratorSettings.languageSection'),+ headerBackTitle: t('settings.identityGenerator'),...defaultHeaderOptions,}}/>diff --git a/apps/mobile-app/app/(tabs)/settings/identity-generator-language.tsx b/apps/mobile-app/app/(tabs)/settings/identity-generator-language.tsxnew file mode 100644index 000000000..918073b6c--- /dev/null+++ b/apps/mobile-app/app/(tabs)/settings/identity-generator-language.tsx@@ -0,0 +1,156 @@+import { Ionicons } from '@expo/vector-icons';+import { useFocusEffect, useRouter } from 'expo-router';+import { useState, useCallback, useRef, useEffect } from 'react';+import { useTranslation } from 'react-i18next';+import { StyleSheet, View, TouchableOpacity } from 'react-native';++import { getAvailableLanguages, ILanguageOption } from '@/utils/dist/core/identity-generator';++import { useColors } from '@/hooks/useColorScheme';+import { useVaultMutate } from '@/hooks/useVaultMutate';++import { ThemedContainer } from '@/components/themed/ThemedContainer';+import { ThemedScrollView } from '@/components/themed/ThemedScrollView';+import { ThemedText } from '@/components/themed/ThemedText';+import { useDb } from '@/context/DbContext';+import { useDialog } from '@/context/DialogContext';++/**+ * Identity Generator Language Selection screen.+ * Allows users to select the language used for generating identities.+ */+export default function IdentityGeneratorLanguageScreen(): React.ReactNode {+ const colors = useColors();+ const { t } = useTranslation();+ const router = useRouter();+ const dbContext = useDb();+ const { showAlert } = useDialog();+ const { executeVaultMutation } = useVaultMutate();++ const [language, setLanguage] = useState<string>('en');+ const [languageOptions, setLanguageOptions] = useState<ILanguageOption[]>([]);++ // Store pending changes and initial values+ const pendingChanges = useRef<{ language?: string }>({});+ const initialValue = useRef<string>('en');++ // Load available languages on mount+ useEffect(() => {+ const languages = getAvailableLanguages();+ setLanguageOptions(languages);+ }, []);++ useFocusEffect(+ useCallback(() => {+ /**+ * Load the current language setting on focus.+ */+ const loadSettings = async (): Promise<void> => {+ try {+ const currentLanguage = await dbContext.sqliteClient!.getEffectiveIdentityLanguage();+ setLanguage(currentLanguage);+ initialValue.current = currentLanguage;+ pendingChanges.current = {};+ } catch (error) {+ console.error('Error loading identity generator language:', error);+ showAlert(t('common.error'), t('common.errors.unknownError'));+ }+ };++ loadSettings();++ // Save changes when screen loses focus (navigating away)+ return (): void => {+ /**+ * Save pending changes to the database.+ */+ const saveChanges = async (): Promise<void> => {+ if (pendingChanges.current.language === undefined) {+ return;+ }++ try {+ await executeVaultMutation(async () => {+ await dbContext.sqliteClient!.updateSetting('DefaultIdentityLanguage', pendingChanges.current.language!);+ });+ pendingChanges.current = {};+ } catch (error) {+ console.error('Error saving identity generator language:', error);+ }+ };++ saveChanges();+ };+ }, [dbContext.sqliteClient, showAlert, t, executeVaultMutation])+ );++ /**+ * Handle language selection+ */+ const handleLanguageSelect = useCallback((newLanguage: string): void => {+ setLanguage(newLanguage);+ pendingChanges.current.language = newLanguage;+ // Navigate back after selection+ router.back();+ }, [router]);++ const styles = StyleSheet.create({+ descriptionText: {+ color: colors.textMuted,+ fontSize: 14,+ lineHeight: 20,+ marginBottom: 16,+ },+ option: {+ alignItems: 'center',+ borderBottomColor: colors.accentBorder,+ borderBottomWidth: StyleSheet.hairlineWidth,+ flexDirection: 'row',+ paddingHorizontal: 16,+ paddingVertical: 14,+ },+ optionContainer: {+ backgroundColor: colors.accentBackground,+ borderRadius: 10,+ },+ optionLast: {+ borderBottomWidth: 0,+ },+ optionText: {+ color: colors.text,+ flex: 1,+ fontSize: 16,+ },+ selectedIcon: {+ color: colors.primary,+ marginLeft: 8,+ },+ });++ return (+ <ThemedContainer>+ <ThemedScrollView>+ <ThemedText style={styles.descriptionText}>+ {t('settings.identityGeneratorSettings.languageDescription')}+ </ThemedText>+ <View style={styles.optionContainer}>+ {languageOptions.map((option, index) => {+ const isLast = index === languageOptions.length - 1;+ return (+ <TouchableOpacity+ key={option.value}+ style={[styles.option, isLast && styles.optionLast]}+ onPress={() => handleLanguageSelect(option.value)}+ >+ <ThemedText style={styles.optionText}>{option.flag} {option.label}</ThemedText>+ {language === option.value && (+ <Ionicons name="checkmark" size={20} style={styles.selectedIcon} />+ )}+ </TouchableOpacity>+ );+ })}+ </View>+ </ThemedScrollView>+ </ThemedContainer>+ );+}diff --git a/apps/mobile-app/app/(tabs)/settings/identity-generator.tsx b/apps/mobile-app/app/(tabs)/settings/identity-generator.tsxindex f43542c3a..09c92c702 100644--- a/apps/mobile-app/app/(tabs)/settings/identity-generator.tsx+++ b/apps/mobile-app/app/(tabs)/settings/identity-generator.tsx@@ -1,5 +1,5 @@import { Ionicons } from '@expo/vector-icons';-import { useFocusEffect } from 'expo-router';+import { useFocusEffect, useRouter } from 'expo-router';import { useState, useCallback, useRef, useEffect } from 'react';import { useTranslation } from 'react-i18next';import { StyleSheet, View, TouchableOpacity } from 'react-native';@@ -21,6 +21,7 @@ import { useDialog } from '@/context/DialogContext';export default function IdentityGeneratorSettingsScreen(): React.ReactNode {const colors = useColors();const { t } = useTranslation();+ const router = useRouter();const dbContext = useDb();const { showAlert } = useDialog();const { executeVaultMutation } = useVaultMutate();@@ -31,9 +32,9 @@ export default function IdentityGeneratorSettingsScreen(): React.ReactNode {const [languageOptions, setLanguageOptions] = useState<ILanguageOption[]>([]);const [ageRangeOptions, setAgeRangeOptions] = useState<IAgeRangeOption[]>([]);- // Store pending changes and initial values- const pendingChanges = useRef<{ language?: string; gender?: string; ageRange?: string }>({});- const initialValues = useRef<{ language: string; gender: string; ageRange: string }>({ language: 'en', gender: 'random', ageRange: 'random' });+ // Store pending changes and initial values (language is managed in subview)+ const pendingChanges = useRef<{ gender?: string; ageRange?: string }>({});+ const initialValues = useRef<{ gender: string; ageRange: string }>({ gender: 'random', ageRange: 'random' });const GENDER_OPTIONS = [{ label: t('settings.identityGeneratorSettings.genderOptions.random'), value: 'random' },@@ -65,8 +66,8 @@ export default function IdentityGeneratorSettingsScreen(): React.ReactNode {setLanguage(currentLanguage);setGender(currentGender);setAgeRange(currentAgeRange);- // Store initial values- initialValues.current = { language: currentLanguage, gender: currentGender, ageRange: currentAgeRange };+ // Store initial values (language is managed in subview)+ initialValues.current = { gender: currentGender, ageRange: currentAgeRange };// Clear pending changes when screen loadspendingChanges.current = {};} catch (error) {@@ -91,11 +92,8 @@ export default function IdentityGeneratorSettingsScreen(): React.ReactNode {}try {- // Save all pending changes in a single vault mutation+ // Save all pending changes in a single vault mutation (language is managed in subview)await executeVaultMutation(async () => {- if (pendingChanges.current.language !== undefined) {- await dbContext.sqliteClient!.updateSetting('DefaultIdentityLanguage', pendingChanges.current.language);- }if (pendingChanges.current.gender !== undefined) {await dbContext.sqliteClient!.updateSetting('DefaultIdentityGender', pendingChanges.current.gender);}@@ -119,12 +117,19 @@ export default function IdentityGeneratorSettingsScreen(): React.ReactNode {);/**- * Handle language change+ * Navigate to language selection subview*/- const handleLanguageChange = useCallback((newLanguage: string): void => {- setLanguage(newLanguage);- pendingChanges.current.language = newLanguage;- }, []);+ const handleLanguagePress = useCallback((): void => {+ router.push('/(tabs)/settings/identity-generator-language');+ }, [router]);++ /**+ * Get the display label for the current language+ */+ const getLanguageDisplayLabel = useCallback((): string => {+ const option = languageOptions.find(opt => opt.value === language);+ return option ? `${option.flag} ${option.label}` : language;+ }, [language, languageOptions]);/*** Handle gender change@@ -143,6 +148,10 @@ export default function IdentityGeneratorSettingsScreen(): React.ReactNode {}, []);const styles = StyleSheet.create({+ chevron: {+ color: colors.textMuted,+ marginLeft: 8,+ },descriptionText: {color: colors.textMuted,fontSize: 14,@@ -153,6 +162,24 @@ export default function IdentityGeneratorSettingsScreen(): React.ReactNode {fontSize: 13,marginBottom: 8,},+ navRow: {+ alignItems: 'center',+ backgroundColor: colors.accentBackground,+ borderRadius: 10,+ flexDirection: 'row',+ marginTop: 8,+ paddingHorizontal: 16,+ paddingVertical: 14,+ },+ navRowLabel: {+ color: colors.text,+ flex: 1,+ fontSize: 16,+ },+ navRowValue: {+ color: colors.textMuted,+ fontSize: 16,+ },option: {alignItems: 'center',borderBottomColor: colors.accentBorder,@@ -198,23 +225,11 @@ export default function IdentityGeneratorSettingsScreen(): React.ReactNode {<ThemedText style={styles.descriptionText}>{t('settings.identityGeneratorSettings.languageDescription')}</ThemedText>- <View style={styles.optionContainer}>- {languageOptions.map((option, index) => {- const isLast = index === languageOptions.length - 1;- return (- <TouchableOpacity- key={option.value}- style={[styles.option, isLast && styles.optionLast]}- onPress={() => handleLanguageChange(option.value)}- >- <ThemedText style={styles.optionText}>{option.flag} {option.label}</ThemedText>- {language === option.value && (- <Ionicons name="checkmark" size={20} style={styles.selectedIcon} />- )}- </TouchableOpacity>- );- })}- </View>+ <TouchableOpacity style={styles.navRow} onPress={handleLanguagePress}>+ <ThemedText style={styles.navRowLabel}>{t('settings.identityGeneratorSettings.languageSection')}</ThemedText>+ <ThemedText style={styles.navRowValue}>{getLanguageDisplayLabel()}</ThemedText>+ <Ionicons name="chevron-forward" size={20} style={styles.chevron} />+ </TouchableOpacity><ThemedText style={styles.sectionTitle}>{t('settings.identityGeneratorSettings.genderSection')}</ThemedText><ThemedText style={styles.descriptionText}>