Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add loading overlay component (#771)

Leendert de Borst866dd1c9194e
diff --git a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
index 997ad604f..919df57d2 100644
--- a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
@@ -21,6 +21,8 @@ import { ValidatedFormField } from '@/components/ValidatedFormField';
import { Resolver, useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import { credentialSchema } from '@/utils/validationSchema';
+import LoadingIndicator from '@/components/LoadingIndicator';
+import LoadingOverlay from '@/components/LoadingOverlay';
type CredentialMode = 'random' | 'manual';
@@ -466,17 +468,6 @@ export default function AddEditCredentialScreen() {
height: 100,
textAlignVertical: 'top',
},
- loadingOverlay: {
- position: 'absolute',
- top: 0,
- left: 0,
- right: 0,
- bottom: 0,
- backgroundColor: 'rgba(0,0,0,0.5)',
- justifyContent: 'center',
- alignItems: 'center',
- zIndex: 1000,
- },
syncStatus: {
marginTop: 16,
textAlign: 'center',
@@ -524,120 +515,42 @@ export default function AddEditCredentialScreen() {
});
return (
- <ThemedSafeAreaView style={styles.container}>
- <ThemedView style={styles.content}>
- {(isLoading || syncStatus) && (
- <View style={styles.loadingOverlay}>
- <ActivityIndicator size="large" color={colors.primary} />
- {syncStatus && (
- <ThemedText style={styles.syncStatus}>{syncStatus}</ThemedText>
+ <>
+ {(isLoading) && (
+ <LoadingOverlay status={syncStatus} />
+ )}
+ <ThemedSafeAreaView style={styles.container}>
+ <ThemedView style={styles.content}>
+ <ScrollView>
+ {!isEditMode && (
+ <View style={styles.modeSelector}>
+ <TouchableOpacity
+ style={[styles.modeButton, mode === 'random' && styles.modeButtonActive]}
+ onPress={() => setMode('random')}
+ >
+ <ThemedText style={[styles.modeButtonText, mode === 'random' && styles.modeButtonTextActive]}>
+ Random Alias
+ </ThemedText>
+ </TouchableOpacity>
+ <TouchableOpacity
+ style={[styles.modeButton, mode === 'manual' && styles.modeButtonActive]}
+ onPress={() => setMode('manual')}
+ >
+ <ThemedText style={[styles.modeButtonText, mode === 'manual' && styles.modeButtonTextActive]}>
+ Manual
+ </ThemedText>
+ </TouchableOpacity>
+ </View>
)}
- </View>
- )}
- <ScrollView>
- {!isEditMode && (
- <View style={styles.modeSelector}>
- <TouchableOpacity
- style={[styles.modeButton, mode === 'random' && styles.modeButtonActive]}
- onPress={() => setMode('random')}
- >
- <ThemedText style={[styles.modeButtonText, mode === 'random' && styles.modeButtonTextActive]}>
- Random Alias
- </ThemedText>
- </TouchableOpacity>
- <TouchableOpacity
- style={[styles.modeButton, mode === 'manual' && styles.modeButtonActive]}
- onPress={() => setMode('manual')}
- >
- <ThemedText style={[styles.modeButtonText, mode === 'manual' && styles.modeButtonTextActive]}>
- Manual
- </ThemedText>
- </TouchableOpacity>
- </View>
- )}
-
- <View style={styles.section}>
- <ThemedText style={styles.sectionTitle}>Service</ThemedText>
-
- <ValidatedFormField
- control={control}
- name="ServiceName"
- label="Service Name"
- required
- autoCapitalize="none"
- autoComplete="off"
- autoCorrect={false}
- />
-
- <ValidatedFormField
- control={control}
- name="ServiceUrl"
- label="Service URL"
- autoCapitalize="none"
- autoComplete="off"
- autoCorrect={false}
- />
- </View>
-
- {(mode === 'manual' || isEditMode) && (
- <>
- <View style={styles.section}>
- <ThemedText style={styles.sectionTitle}>Login credentials</ThemedText>
-
- <ValidatedFormField
- control={control}
- name="Username"
- label="Username"
- autoCapitalize="none"
- autoComplete="off"
- autoCorrect={false}
- buttons={[
- {
- icon: "refresh",
- onPress: generateRandomUsername
- }
- ]}
- />
-
- <ValidatedFormField
- control={control}
- name="Password"
- label="Password"
- secureTextEntry={!isPasswordVisible}
- buttons={[
- {
- icon: isPasswordVisible ? "visibility-off" : "visibility",
- onPress: () => setIsPasswordVisible(!isPasswordVisible)
- },
- {
- icon: "refresh",
- onPress: generateRandomPassword
- }
- ]}
- />
-
- <TouchableOpacity style={styles.generateButton} onPress={generateRandomAlias}>
- <MaterialIcons name="auto-fix-high" size={20} color="#fff" />
- <ThemedText style={styles.generateButtonText}>Generate Random Alias</ThemedText>
- </TouchableOpacity>
-
- <ValidatedFormField
- control={control}
- name="Alias.Email"
- label="Email"
- autoCapitalize="none"
- autoComplete="off"
- autoCorrect={false}
- />
- </View>
<View style={styles.section}>
- <ThemedText style={styles.sectionTitle}>Alias</ThemedText>
+ <ThemedText style={styles.sectionTitle}>Service</ThemedText>
<ValidatedFormField
control={control}
- name="Alias.FirstName"
- label="First Name"
+ name="ServiceName"
+ label="Service Name"
+ required
autoCapitalize="none"
autoComplete="off"
autoCorrect={false}
@@ -645,72 +558,147 @@ export default function AddEditCredentialScreen() {
<ValidatedFormField
control={control}
- name="Alias.LastName"
- label="Last Name"
- autoCapitalize="none"
- autoComplete="off"
- autoCorrect={false}
- />
-
- <ValidatedFormField
- control={control}
- name="Alias.NickName"
- label="Nick Name"
- autoCapitalize="none"
- autoComplete="off"
- autoCorrect={false}
- />
-
- <ValidatedFormField
- control={control}
- name="Alias.Gender"
- label="Gender"
- autoCapitalize="none"
- autoComplete="off"
- autoCorrect={false}
- />
-
- <ValidatedFormField
- control={control}
- name="Alias.BirthDate"
- label="Birth Date"
- placeholder="YYYY-MM-DD"
- autoCapitalize="none"
- autoComplete="off"
- autoCorrect={false}
- />
- </View>
-
- <View style={styles.section}>
- <ThemedText style={styles.sectionTitle}>Metadata</ThemedText>
-
- <ValidatedFormField
- control={control}
- name="Notes"
- label="Notes"
- multiline
- numberOfLines={4}
- textAlignVertical="top"
+ name="ServiceUrl"
+ label="Service URL"
autoCapitalize="none"
autoComplete="off"
autoCorrect={false}
/>
- {/* TODO: Add TOTP management */}
</View>
- {isEditMode && (
- <TouchableOpacity
- style={styles.deleteButton}
- onPress={handleDelete}
- >
- <ThemedText style={styles.deleteButtonText}>Delete Credential</ThemedText>
- </TouchableOpacity>
+ {(mode === 'manual' || isEditMode) && (
+ <>
+ <View style={styles.section}>
+ <ThemedText style={styles.sectionTitle}>Login credentials</ThemedText>
+
+ <ValidatedFormField
+ control={control}
+ name="Username"
+ label="Username"
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect={false}
+ buttons={[
+ {
+ icon: "refresh",
+ onPress: generateRandomUsername
+ }
+ ]}
+ />
+
+ <ValidatedFormField
+ control={control}
+ name="Password"
+ label="Password"
+ secureTextEntry={!isPasswordVisible}
+ buttons={[
+ {
+ icon: isPasswordVisible ? "visibility-off" : "visibility",
+ onPress: () => setIsPasswordVisible(!isPasswordVisible)
+ },
+ {
+ icon: "refresh",
+ onPress: generateRandomPassword
+ }
+ ]}
+ />
+
+ <TouchableOpacity style={styles.generateButton} onPress={generateRandomAlias}>
+ <MaterialIcons name="auto-fix-high" size={20} color="#fff" />
+ <ThemedText style={styles.generateButtonText}>Generate Random Alias</ThemedText>
+ </TouchableOpacity>
+
+ <ValidatedFormField
+ control={control}
+ name="Alias.Email"
+ label="Email"
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect={false}
+ />
+ </View>
+
+ <View style={styles.section}>
+ <ThemedText style={styles.sectionTitle}>Alias</ThemedText>
+
+ <ValidatedFormField
+ control={control}
+ name="Alias.FirstName"
+ label="First Name"
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect={false}
+ />
+
+ <ValidatedFormField
+ control={control}
+ name="Alias.LastName"
+ label="Last Name"
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect={false}
+ />
+
+ <ValidatedFormField
+ control={control}
+ name="Alias.NickName"
+ label="Nick Name"
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect={false}
+ />
+
+ <ValidatedFormField
+ control={control}
+ name="Alias.Gender"
+ label="Gender"
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect={false}
+ />
+
+ <ValidatedFormField
+ control={control}
+ name="Alias.BirthDate"
+ label="Birth Date"
+ placeholder="YYYY-MM-DD"
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect={false}
+ />
+ </View>
+
+ <View style={styles.section}>
+ <ThemedText style={styles.sectionTitle}>Metadata</ThemedText>
+
+ <ValidatedFormField
+ control={control}
+ name="Notes"
+ label="Notes"
+ multiline
+ numberOfLines={4}
+ textAlignVertical="top"
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect={false}
+ />
+ {/* TODO: Add TOTP management */}
+ </View>
+
+ {isEditMode && (
+ <TouchableOpacity
+ style={styles.deleteButton}
+ onPress={handleDelete}
+ >
+ <ThemedText style={styles.deleteButtonText}>Delete Credential</ThemedText>
+ </TouchableOpacity>
+ )}
+ </>
)}
- </>
- )}
- </ScrollView>
- </ThemedView>
- <AliasVaultToast />
- </ThemedSafeAreaView>
+ </ScrollView>
+ </ThemedView>
+ <AliasVaultToast />
+ </ThemedSafeAreaView>
+ </>
);
}
\ No newline at end of file
diff --git a/apps/mobile-app/app/_layout.tsx b/apps/mobile-app/app/_layout.tsx
index 53c7be509..68b35d33a 100644
--- a/apps/mobile-app/app/_layout.tsx
+++ b/apps/mobile-app/app/_layout.tsx
@@ -10,11 +10,11 @@ import 'react-native-reanimated';
import 'react-native-get-random-values';
import { useColors, useColorScheme } from '@/hooks/useColorScheme';
-import { LoadingProvider } from '@/context/LoadingContext';
import { DbProvider } from '@/context/DbContext';
import { AuthProvider } from '@/context/AuthContext';
import { WebApiProvider } from '@/context/WebApiContext';
import { AliasVaultToast } from '@/components/Toast';
+import LoadingIndicator from '@/components/LoadingIndicator';
// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();
@@ -87,9 +87,7 @@ export default function RootLayout() {
<DbProvider>
<AuthProvider>
<WebApiProvider>
- <LoadingProvider>
- <RootLayoutNav />
- </LoadingProvider>
+ <RootLayoutNav />
</WebApiProvider>
</AuthProvider>
</DbProvider>
diff --git a/apps/mobile-app/app/index.tsx b/apps/mobile-app/app/index.tsx
index 5e1b4ac1d..744720663 100644
--- a/apps/mobile-app/app/index.tsx
+++ b/apps/mobile-app/app/index.tsx
@@ -6,5 +6,4 @@ export default function AppIndex() {
install();
return <Redirect href={'/sync'} />
-
}
\ No newline at end of file
diff --git a/apps/mobile-app/components/LoadingOverlay.tsx b/apps/mobile-app/components/LoadingOverlay.tsx
new file mode 100644
index 000000000..8d0913c7b
--- /dev/null
+++ b/apps/mobile-app/components/LoadingOverlay.tsx
@@ -0,0 +1,38 @@
+import { StyleSheet, View } from 'react-native';
+import { useColors } from '@/hooks/useColorScheme';
+import LoadingIndicator from './LoadingIndicator';
+
+interface LoadingOverlayProps {
+ status: string;
+}
+
+/**
+ * LoadingOverlay component
+ *
+ * This component displays a loading indicator overlay over the entire screen.
+ * It is used to indicate that a process is in progress and the user should wait.
+ *
+ */
+export default function LoadingOverlay({ status }: LoadingOverlayProps) {
+ const colors = useColors();
+
+ const styles = StyleSheet.create({
+ container: {
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0,
+ backgroundColor: 'rgba(0,0,0,0.5)',
+ justifyContent: 'center',
+ alignItems: 'center',
+ zIndex: 1000,
+ },
+ });
+
+ return (
+ <View style={styles.container}>
+ <LoadingIndicator status={status} />
+ </View>
+ );
+}
\ No newline at end of file
diff --git a/apps/mobile-app/context/LoadingContext.tsx b/apps/mobile-app/context/LoadingContext.tsx
deleted file mode 100644
index 18eb8a46e..000000000
--- a/apps/mobile-app/context/LoadingContext.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-import React, { createContext, useContext, useState, useMemo } from 'react';
-
-type LoadingContextType = {
- isLoading: boolean;
- showLoading: () => void;
- hideLoading: () => void;
- isInitialLoading: boolean;
- setIsInitialLoading: (isInitialLoading: boolean) => void;
-}
-
-/**
- * Loading context.
- * TODO: can we remove this context for the mobile apps? Probably not needed.
- */
-const LoadingContext = createContext<LoadingContextType | undefined>(undefined);
-
-/**
- * Loading provider
- */
-export const LoadingProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
- /**
- * Initial loading state for when extension is first loaded. This initial loading state is
- * hidden by the component that is rendered when the extension is first loaded to prevent
- * multiple loading spinners from being shown.
- */
- const [isInitialLoading, setIsInitialLoading] = useState(true);
-
- /**
- * Loading state that can be used by other components during normal operation.
- */
- const [isLoading, setIsLoading] = useState(false);
-
- /**
- * Show loading spinner
- */
- const showLoading = (): void => setIsLoading(true);
-
- /**
- * Hide loading spinner
- */
- const hideLoading = (): void => setIsLoading(false);
-
- const value = useMemo(
- () => ({
- isLoading,
- showLoading,
- hideLoading,
- isInitialLoading,
- setIsInitialLoading,
- }),
- [isLoading, isInitialLoading]
- );
-
- return (
- <LoadingContext.Provider value={value}>
- {children}
- </LoadingContext.Provider>
- );
-};
-
-/**
- * Hook to use loading state
- */
-export const useLoading = (): LoadingContextType => {
- const context = useContext(LoadingContext);
- if (context === undefined) {
- throw new Error('useLoading must be used within a LoadingProvider');
- }
- return context;
-};
\ No newline at end of file