Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add identity generator settings scaffolding to app (#974)
Leendert de Borst361ea77ab7a8
diff --git a/apps/mobile-app/app/(tabs)/settings/_layout.tsx b/apps/mobile-app/app/(tabs)/settings/_layout.tsxindex 6da4a1c57..1ddf26db0 100644--- a/apps/mobile-app/app/(tabs)/settings/_layout.tsx+++ b/apps/mobile-app/app/(tabs)/settings/_layout.tsx@@ -56,6 +56,13 @@ export default function SettingsLayout(): React.ReactNode {...defaultHeaderOptions,}}/>+ <Stack.Screen+ name="identity-generator"+ options={{+ title: 'Identity Generator Settings',+ ...defaultHeaderOptions,+ }}+ /><Stack.Screenname="security/index"options={{diff --git a/apps/mobile-app/app/(tabs)/settings/identity-generator.tsx b/apps/mobile-app/app/(tabs)/settings/identity-generator.tsxnew file mode 100644index 000000000..3fe64354e--- /dev/null+++ b/apps/mobile-app/app/(tabs)/settings/identity-generator.tsx@@ -0,0 +1,237 @@+import { Ionicons } from '@expo/vector-icons';+import { router, useFocusEffect } from 'expo-router';+import { useRef, useState, useCallback } from 'react';+import { StyleSheet, View, ScrollView, Alert, Animated, Platform, TouchableOpacity } from 'react-native';++import { useColors } from '@/hooks/useColorScheme';+import { useMinDurationLoading } from '@/hooks/useMinDurationLoading';+import { useVaultMutate } from '@/hooks/useVaultMutate';++import { ThemedContainer } from '@/components/themed/ThemedContainer';+import { ThemedText } from '@/components/themed/ThemedText';+import { CollapsibleHeader } from '@/components/ui/CollapsibleHeader';+import { TitleContainer } from '@/components/ui/TitleContainer';+import { useDb } from '@/context/DbContext';++const LANGUAGE_OPTIONS = [+ { label: 'English', value: 'en' },+ { label: 'Dutch', value: 'nl' }+];++const GENDER_OPTIONS = [+ { label: 'Random', value: 'random' },+ { label: 'Male', value: 'male' },+ { label: 'Female', value: 'female' }+];++/**+ * Identity Generator Settings screen.+ */+export default function IdentityGeneratorSettingsScreen(): React.ReactNode {+ const colors = useColors();+ const dbContext = useDb();+ const { executeVaultMutation } = useVaultMutate();+ const scrollY = useRef(new Animated.Value(0)).current;+ const scrollViewRef = useRef<ScrollView>(null);++ const [language, setLanguage] = useState<string>('en');+ const [gender, setGender] = useState<string>('random');+ const [isFirstLoad, setIsFirstLoad] = useMinDurationLoading(true, 100);++ useFocusEffect(+ useCallback(() => {+ /**+ * Load the identity generator settings.+ */+ const loadSettings = async (): Promise<void> => {+ try {+ const [currentLanguage, currentGender] = await Promise.all([+ dbContext.sqliteClient!.getDefaultIdentityLanguage(),+ dbContext.sqliteClient!.getDefaultIdentityGender()+ ]);++ setLanguage(currentLanguage);+ setGender(currentGender);+ setIsFirstLoad(false);+ } catch (error) {+ console.error('Error loading identity generator settings:', error);+ Alert.alert('Error', 'Failed to load identity generator settings.');+ setIsFirstLoad(false);+ }+ };++ loadSettings();+ }, [dbContext.sqliteClient, setIsFirstLoad])+ );++ /**+ * Handle language change.+ */+ const handleLanguageChange = useCallback(async (newLanguage: string): Promise<void> => {+ try {+ executeVaultMutation(async () => {+ // Update the default language setting+ await dbContext.sqliteClient!.updateSetting('DefaultIdentityLanguage', newLanguage);+ console.log('Updated default language setting to:', newLanguage);+ });+ setLanguage(newLanguage);+ } catch (error) {+ console.error('Error updating language setting:', error);+ Alert.alert('Error', 'Failed to update language setting.');+ }+ }, [executeVaultMutation, dbContext.sqliteClient]);++ /**+ * Handle gender change.+ */+ const handleGenderChange = useCallback(async (newGender: string): Promise<void> => {+ try {+ executeVaultMutation(async () => {+ await dbContext.sqliteClient!.updateSetting('DefaultIdentityGender', newGender);+ console.log('Updated default gender setting to:', newGender);+ });+ setGender(newGender);+ } catch (error) {+ console.error('Error updating gender setting:', error);+ Alert.alert('Error', 'Failed to update gender setting.');+ }+ }, [executeVaultMutation, dbContext.sqliteClient]);++ const styles = StyleSheet.create({+ descriptionText: {+ color: colors.textMuted,+ fontSize: 14,+ lineHeight: 20,+ marginTop: 8,+ },+ headerText: {+ color: colors.textMuted,+ fontSize: 13,+ marginBottom: 8,+ },+ loadingContainer: {+ alignItems: 'center',+ flex: 1,+ justifyContent: 'center',+ },+ option: {+ alignItems: 'center',+ borderBottomColor: colors.accentBorder,+ borderBottomWidth: StyleSheet.hairlineWidth,+ flexDirection: 'row',+ paddingHorizontal: 16,+ paddingVertical: 14,+ },+ optionContainer: {+ backgroundColor: colors.accentBackground,+ borderRadius: 10,+ marginTop: 8,+ },+ optionLast: {+ borderBottomWidth: 0,+ },+ optionText: {+ color: colors.text,+ flex: 1,+ fontSize: 16,+ },+ scrollContent: {+ paddingBottom: 40,+ paddingTop: Platform.OS === 'ios' ? 42 : 16,+ },+ scrollView: {+ flex: 1,+ },+ sectionTitle: {+ color: colors.text,+ fontSize: 18,+ fontWeight: '600',+ marginBottom: 8,+ marginTop: 24,+ },+ selectedIcon: {+ color: colors.primary,+ marginLeft: 8,+ },+ });++ if (isFirstLoad) {+ return (+ <ThemedContainer>+ <CollapsibleHeader+ title="Identity Generator Settings"+ scrollY={scrollY}+ showBackButton={true}+ onBackPress={() => router.back()}+ />+ <View style={styles.loadingContainer}>+ <ThemedText>Loading...</ThemedText>+ </View>+ </ThemedContainer>+ );+ }++ return (+ <ThemedContainer>+ <Animated.ScrollView+ ref={scrollViewRef}+ onScroll={Animated.event(+ [{ nativeEvent: { contentOffset: { y: scrollY } } }],+ { useNativeDriver: true }+ )}+ scrollEventThrottle={16}+ contentContainerStyle={styles.scrollContent}+ scrollIndicatorInsets={{ bottom: 40 }}+ style={styles.scrollView}+ >+ <ThemedText style={styles.headerText}>+ Configure the default language and gender preferences for generating new identities.+ </ThemedText>++ <ThemedText style={styles.sectionTitle}>Language</ThemedText>+ <ThemedText style={styles.descriptionText}>+ Set the language that will be used when generating new identities.+ </ThemedText>+ <View style={styles.optionContainer}>+ {LANGUAGE_OPTIONS.map((option, index) => {+ const isLast = index === LANGUAGE_OPTIONS.length - 1;+ return (+ <TouchableOpacity+ key={option.value}+ style={[styles.option, isLast && styles.optionLast]}+ onPress={() => handleLanguageChange(option.value)}+ >+ <ThemedText style={styles.optionText}>{option.label}</ThemedText>+ {language === option.value && (+ <Ionicons name="checkmark" size={20} style={styles.selectedIcon} />+ )}+ </TouchableOpacity>+ );+ })}+ </View>++ <ThemedText style={styles.sectionTitle}>Gender</ThemedText>+ <ThemedText style={styles.descriptionText}>+ Set the gender preference for generating new identities.+ </ThemedText>+ <View style={styles.optionContainer}>+ {GENDER_OPTIONS.map((option, index) => {+ const isLast = index === GENDER_OPTIONS.length - 1;+ return (+ <TouchableOpacity+ key={option.value}+ style={[styles.option, isLast && styles.optionLast]}+ onPress={() => handleGenderChange(option.value)}+ >+ <ThemedText style={styles.optionText}>{option.label}</ThemedText>+ {gender === option.value && (+ <Ionicons name="checkmark" size={20} style={styles.selectedIcon} />+ )}+ </TouchableOpacity>+ );+ })}+ </View>+ </Animated.ScrollView>+ </ThemedContainer>+ );+}\ No newline at end of filediff --git a/apps/mobile-app/app/(tabs)/settings/index.tsx b/apps/mobile-app/app/(tabs)/settings/index.tsxindex 5c4c8b9d0..441894e4b 100644--- a/apps/mobile-app/app/(tabs)/settings/index.tsx+++ b/apps/mobile-app/app/(tabs)/settings/index.tsx@@ -134,6 +134,13 @@ export default function SettingsScreen() : React.ReactNode {router.push('/(tabs)/settings/android-autofill');};+ /**+ * Handle the identity generator settings press.+ */+ const handleIdentityGeneratorPress = () : void => {+ router.push('/(tabs)/settings/identity-generator');+ };+const styles = StyleSheet.create({scrollContent: {paddingBottom: 40,@@ -329,6 +336,19 @@ export default function SettingsScreen() : React.ReactNode {<Ionicons name="chevron-forward" size={20} color={colors.textMuted} /></View></TouchableOpacity>+ <View style={styles.separator} />+ <TouchableOpacity+ style={styles.settingItem}+ onPress={handleIdentityGeneratorPress}+ >+ <View style={styles.settingItemIcon}>+ <Ionicons name="person-outline" size={20} color={colors.text} />+ </View>+ <View style={styles.settingItemContent}>+ <ThemedText style={styles.settingItemText}>Identity Generator Settings</ThemedText>+ <Ionicons name="chevron-forward" size={20} color={colors.textMuted} />+ </View>+ </TouchableOpacity></View><View style={styles.section}>diff --git a/apps/mobile-app/utils/SqliteClient.tsx b/apps/mobile-app/utils/SqliteClient.tsxindex fa9315a0b..f1dfd3448 100644--- a/apps/mobile-app/utils/SqliteClient.tsx+++ b/apps/mobile-app/utils/SqliteClient.tsx@@ -431,6 +431,27 @@ class SqliteClient {return this.getSetting('DefaultIdentityGender', 'random');}+ /**+ * Update a setting in the database.+ * @param key The setting key+ * @param value The setting value+ */+ public async updateSetting(key: string, value: string): Promise<void> {+ await NativeVaultManager.beginTransaction();++ const currentDateTime = new Date().toISOString()+ .replace('T', ' ')+ .replace('Z', '')+ .substring(0, 23);++ const query = `+ INSERT OR REPLACE INTO Settings (Key, Value, CreatedAt, UpdatedAt, IsDeleted)+ VALUES (?, ?, ?, ?, ?)`;++ await this.executeUpdate(query, [key, value, currentDateTime, currentDateTime, 0]);+ await NativeVaultManager.commitTransaction();+ }+/*** Get the password settings from the database.*/