Skip to content

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

Update mobile app full offline mode scaffolding (#1404)

Leendert de Borst5c37217ce722
diff --git a/apps/mobile-app/app/(tabs)/_layout.tsx b/apps/mobile-app/app/(tabs)/_layout.tsx
index 3cb01b33c..3384ba54c 100644
--- a/apps/mobile-app/app/(tabs)/_layout.tsx
+++ b/apps/mobile-app/app/(tabs)/_layout.tsx
@@ -7,6 +7,7 @@ import emitter from '@/utils/EventEmitter';
import { useColors } from '@/hooks/useColorScheme';
+import { ServerSyncIndicator } from '@/components/ServerSyncIndicator';
import { ThemedText } from '@/components/themed/ThemedText';
import { IconSymbol } from '@/components/ui/IconSymbol';
import { IconSymbolName } from '@/components/ui/IconSymbolName';
@@ -72,71 +73,76 @@ export default function TabLayout() : React.ReactNode {
});
return (
- <Tabs
- screenListeners={{
- /**
- * Listener for the tab press event.
- * @param {Object} e - The event object.
- * @param {string} e.target - The target pathname.
- */
- tabPress: (e) => {
- const targetPathname = (e.target as string).split('-')[0];
- emitter.emit('tabPress', targetPathname);
- },
- }}
- screenOptions={{
- tabBarActiveTintColor: colors.tint,
- headerShown: false,
- tabBarBackground: TabBarBackground,
- tabBarStyle: Platform.select({
- ios: {
- position: 'absolute',
- },
- android: {
- backgroundColor: colors.tabBarBackground,
- },
- default: {},
- }),
- }}>
- <Tabs.Screen
- name="items"
- options={{
- title: t('navigation.vault'),
- /**
- * Icon for the vault tab.
- */
- tabBarIcon: ({ color }) => <IconSymbol size={28} name={IconSymbolName.Key} color={color} />,
- }}
- />
- <Tabs.Screen
- name="emails"
- options={{
- title: t('navigation.emails'),
+ <>
+ <Tabs
+ screenListeners={{
/**
- * Icon for the emails tab.
+ * Listener for the tab press event.
+ * @param {Object} e - The event object.
+ * @param {string} e.target - The target pathname.
*/
- tabBarIcon: ({ color }) => <IconSymbol size={28} name={IconSymbolName.Envelope} color={color} />,
- }}
- />
- <Tabs.Screen
- name="settings"
- options={{
- title: t('navigation.settings'),
- /**
- * Icon for the settings tab.
- */
- tabBarIcon: ({ color }) => (
- <View style={styles.iconContainer}>
- <IconSymbol size={28} name={IconSymbolName.Gear} color={color} />
- {authContext.shouldShowAutofillReminder && (
- <View style={styles.iconNotificationContainer}>
- <ThemedText style={styles.iconNotificationText}>1</ThemedText>
- </View>
- )}
- </View>
- )
+ tabPress: (e) => {
+ const targetPathname = (e.target as string).split('-')[0];
+ emitter.emit('tabPress', targetPathname);
+ },
}}
- />
- </Tabs>
+ screenOptions={{
+ tabBarActiveTintColor: colors.tint,
+ headerShown: false,
+ tabBarBackground: TabBarBackground,
+ tabBarStyle: Platform.select({
+ ios: {
+ position: 'absolute',
+ },
+ android: {
+ backgroundColor: colors.tabBarBackground,
+ },
+ default: {},
+ }),
+ }}>
+ <Tabs.Screen
+ name="items"
+ options={{
+ title: t('navigation.vault'),
+ /**
+ * Icon for the vault tab.
+ */
+ tabBarIcon: ({ color }) => <IconSymbol size={28} name={IconSymbolName.Key} color={color} />,
+ }}
+ />
+ <Tabs.Screen
+ name="emails"
+ options={{
+ title: t('navigation.emails'),
+ /**
+ * Icon for the emails tab.
+ */
+ tabBarIcon: ({ color }) => <IconSymbol size={28} name={IconSymbolName.Envelope} color={color} />,
+ }}
+ />
+ <Tabs.Screen
+ name="settings"
+ options={{
+ title: t('navigation.settings'),
+ /**
+ * Icon for the settings tab.
+ */
+ tabBarIcon: ({ color }) => (
+ <View style={styles.iconContainer}>
+ <IconSymbol size={28} name={IconSymbolName.Gear} color={color} />
+ {authContext.shouldShowAutofillReminder && (
+ <View style={styles.iconNotificationContainer}>
+ <ThemedText style={styles.iconNotificationText}>1</ThemedText>
+ </View>
+ )}
+ </View>
+ )
+ }}
+ />
+ </Tabs>
+
+ {/* Floating sync indicator - visible on all tabs */}
+ <ServerSyncIndicator />
+ </>
);
}
\ No newline at end of file
diff --git a/apps/mobile-app/app/(tabs)/items/add-edit.tsx b/apps/mobile-app/app/(tabs)/items/add-edit.tsx
index 803ea4c5a..bd2552e14 100644
--- a/apps/mobile-app/app/(tabs)/items/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/items/add-edit.tsx
@@ -36,7 +36,6 @@ import { ThemedContainer } from '@/components/themed/ThemedContainer';
import { ThemedText } from '@/components/themed/ThemedText';
import { AliasVaultToast } from '@/components/Toast';
import { RobustPressable } from '@/components/ui/RobustPressable';
-import { useAuth } from '@/context/AuthContext';
import { useDb } from '@/context/DbContext';
import { useWebApi } from '@/context/WebApiContext';
@@ -69,15 +68,15 @@ export default function AddEditItemScreen(): React.ReactNode {
const router = useRouter();
const colors = useColors();
const dbContext = useDb();
- const authContext = useAuth();
- const { executeVaultMutation, syncStatus } = useVaultMutate();
+ const { executeVaultMutation } = useVaultMutate();
const navigation = useNavigation();
const webApi = useWebApi();
const { t } = useTranslation();
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
const itemNameRef = useRef<ItemNameFieldRef>(null);
- const [isSyncing, setIsSyncing] = useState(false);
+ const [isSaving, setIsSaving] = useState(false);
+ const [saveStatus, setSaveStatus] = useState('');
const [isSaveDisabled, setIsSaveDisabled] = useState(false);
const [attachments, setAttachments] = useState<Attachment[]>([]);
const [originalAttachmentIds, setOriginalAttachmentIds] = useState<string[]>([]);
@@ -478,21 +477,11 @@ export default function AddEditItemScreen(): React.ReactNode {
*/
useEffect(() => {
/**
- * Initialize the component
+ * Initialize the component.
+ * Offline mode is fully supported - items can be added/edited locally
+ * and will sync when back online.
*/
const initializeComponent = async (): Promise<void> => {
- if (authContext.isOffline) {
- setTimeout(() => {
- Toast.show({
- type: 'error',
- text1: t('items.offlineMessage'),
- position: 'bottom'
- });
- }, 100);
- router.dismiss();
- return;
- }
-
// Load folders for folder selection
try {
const loadedFolders = await dbContext.sqliteClient!.folders.getAll();
@@ -547,7 +536,7 @@ export default function AddEditItemScreen(): React.ReactNode {
};
initializeComponent();
- }, [id, isEditMode, serviceUrl, itemTypeParam, loadExistingItem, authContext.isOffline, router, t, dbContext.sqliteClient]);
+ }, [id, isEditMode, serviceUrl, itemTypeParam, loadExistingItem, router, t, dbContext.sqliteClient]);
/**
* Auto-generate alias when alias fields are shown by default in create mode.
@@ -713,6 +702,7 @@ export default function AddEditItemScreen(): React.ReactNode {
/**
* Submit the form.
+ * Non-blocking for local saves. Only shows loading indicator when fetching favicon.
*/
const onSubmit = useCallback(async (): Promise<void> => {
if (isSaveDisabled || !item) {
@@ -721,7 +711,6 @@ export default function AddEditItemScreen(): React.ReactNode {
setIsSaveDisabled(true);
Keyboard.dismiss();
- setIsSyncing(true);
// Build the fields array from fieldValues
const fields: ItemField[] = [];
@@ -777,10 +766,16 @@ export default function AddEditItemScreen(): React.ReactNode {
UpdatedAt: new Date().toISOString()
};
- // Extract favicon from URL if present
+ // Extract favicon from URL if present (only show loading for this network operation)
const urlValue = fieldValues['login.url'];
const urlString = Array.isArray(urlValue) ? urlValue[0] : urlValue;
- if (urlString && urlString !== 'https://' && urlString !== 'http://') {
+ const shouldFetchFavicon = urlString && urlString !== 'https://' && urlString !== 'http://';
+
+ if (shouldFetchFavicon) {
+ // Only show loading indicator when fetching favicon
+ setIsSaving(true);
+ setSaveStatus(t('vault.savingChangesToVault'));
+
try {
const timeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error('Favicon extraction timed out')), 5000)
@@ -793,7 +788,7 @@ export default function AddEditItemScreen(): React.ReactNode {
itemToSave.Logo = decodedImage;
}
} catch {
- // Favicon extraction failed or timed out - not critical
+ // Favicon extraction failed or timed out - not critical, continue with save
}
}
@@ -828,7 +823,7 @@ export default function AddEditItemScreen(): React.ReactNode {
if (serviceUrl && !isEditMode) {
router.replace('/items/autofill-item-created');
} else {
- setIsSyncing(false);
+ setIsSaving(false);
setIsSaveDisabled(false);
router.dismiss();
@@ -861,7 +856,7 @@ export default function AddEditItemScreen(): React.ReactNode {
position: 'bottom'
});
console.error('Error saving item:', error.message);
- setIsSyncing(false);
+ setIsSaving(false);
setIsSaveDisabled(false);
}
});
@@ -892,8 +887,6 @@ export default function AddEditItemScreen(): React.ReactNode {
* Delete the item
*/
onPress: async (): Promise<void> => {
- setIsSyncing(true);
-
await executeVaultMutation(async () => {
await dbContext.sqliteClient!.items.trash(id);
});
@@ -908,7 +901,6 @@ export default function AddEditItemScreen(): React.ReactNode {
});
}, 200);
- setIsSyncing(false);
router.back();
router.back();
}
@@ -1227,8 +1219,8 @@ export default function AddEditItemScreen(): React.ReactNode {
return (
<>
<Stack.Screen options={{ title: isEditMode ? t('items.editItem') : t('items.addItem') }} />
- {(isSyncing) && (
- <LoadingOverlay status={syncStatus} />
+ {isSaving && (
+ <LoadingOverlay status={saveStatus} />
)}
<ThemedContainer style={styles.container}>
diff --git a/apps/mobile-app/app/(tabs)/items/deleted.tsx b/apps/mobile-app/app/(tabs)/items/deleted.tsx
index 0540828e3..3b0ebc019 100644
--- a/apps/mobile-app/app/(tabs)/items/deleted.tsx
+++ b/apps/mobile-app/app/(tabs)/items/deleted.tsx
@@ -19,7 +19,6 @@ import { useColors } from '@/hooks/useColorScheme';
import { useVaultMutate } from '@/hooks/useVaultMutate';
import { ConfirmDeleteModal } from '@/components/items/ConfirmDeleteModal';
-import LoadingOverlay from '@/components/LoadingOverlay';
import { ThemedContainer } from '@/components/themed/ThemedContainer';
import { ThemedScrollView } from '@/components/themed/ThemedScrollView';
import { ThemedText } from '@/components/themed/ThemedText';
@@ -46,7 +45,7 @@ export default function RecentlyDeletedScreen(): React.ReactNode {
const { t } = useTranslation();
const colors = useColors();
const dbContext = useDb();
- const { executeVaultMutation, isLoading, syncStatus } = useVaultMutate();
+ const { executeVaultMutation } = useVaultMutate();
const [items, setItems] = useState<ItemWithDeletedAt[]>([]);
const [isLoadingItems, setIsLoadingItems] = useState(true);
@@ -340,7 +339,6 @@ export default function RecentlyDeletedScreen(): React.ReactNode {
return (
<ThemedContainer>
- {isLoading && <LoadingOverlay status={syncStatus} />}
{isLoadingItems ? (
<View style={styles.loadingContainer}>
diff --git a/apps/mobile-app/app/(tabs)/items/folder/[id].tsx b/apps/mobile-app/app/(tabs)/items/folder/[id].tsx
index a1d2026a5..86282577c 100644
--- a/apps/mobile-app/app/(tabs)/items/folder/[id].tsx
+++ b/apps/mobile-app/app/(tabs)/items/folder/[id].tsx
@@ -22,7 +22,6 @@ import { useVaultSync } from '@/hooks/useVaultSync';
import { DeleteFolderModal } from '@/components/folders/DeleteFolderModal';
import { FolderModal } from '@/components/folders/FolderModal';
import { ItemCard } from '@/components/items/ItemCard';
-import LoadingOverlay from '@/components/LoadingOverlay';
import { ThemedContainer } from '@/components/themed/ThemedContainer';
import { ThemedText } from '@/components/themed/ThemedText';
import { ThemedView } from '@/components/themed/ThemedView';
@@ -49,8 +48,7 @@ export default function FolderViewScreen(): React.ReactNode {
const [folder, setFolder] = useState<Folder | null>(null);
const [isLoadingItems, setIsLoadingItems] = useMinDurationLoading(false, 200);
const [refreshing, setRefreshing] = useMinDurationLoading(false, 200);
- const { executeVaultMutation, isLoading, syncStatus } = useVaultMutate();
- const [isSyncing, setIsSyncing] = useState(false);
+ const { executeVaultMutation } = useVaultMutate();
// Search state (scoped to this folder)
const [searchQuery, setSearchQuery] = useState('');
@@ -170,19 +168,12 @@ export default function FolderViewScreen(): React.ReactNode {
}, 200);
},
/**
- * On offline.
+ * On offline - just set offline mode, ServerSyncIndicator shows status.
*/
onOffline: () => {
setRefreshing(false);
setIsLoadingItems(false);
authContext.setOfflineMode(true);
- setTimeout(() => {
- Toast.show({
- type: 'error',
- text1: t('items.offlineMessage'),
- position: 'bottom',
- });
- }, 200);
},
/**
* On error.
@@ -266,16 +257,14 @@ export default function FolderViewScreen(): React.ReactNode {
/**
* Delete an item (move to trash).
+ * Non-blocking: saves locally and syncs in background via ServerSyncIndicator.
*/
const onItemDelete = useCallback(async (itemId: string): Promise<void> => {
- setIsSyncing(true);
-
await executeVaultMutation(async () => {
await dbContext.sqliteClient!.items.trash(itemId);
- setIsSyncing(false);
});
- await new Promise(resolve => setTimeout(resolve, 250));
+ // Reload items to reflect the deletion
await loadItems();
}, [dbContext.sqliteClient, executeVaultMutation, loadItems]);
@@ -500,8 +489,6 @@ export default function FolderViewScreen(): React.ReactNode {
return (
<ThemedContainer style={styles.container}>
- {isSyncing && <LoadingOverlay status={syncStatus} />}
-
{/* FAB */}
<RobustPressable style={styles.fab} onPress={handleAddItem}>
<MaterialIcons name="add" style={styles.fabIcon} />
@@ -538,8 +525,6 @@ export default function FolderViewScreen(): React.ReactNode {
ListEmptyComponent={renderEmptyComponent() as React.ReactElement}
/>
- {isLoading && <LoadingOverlay status={syncStatus || t('items.deletingItem')} />}
-
{/* Folder modals */}
<FolderModal
isOpen={showEditFolderModal}
diff --git a/apps/mobile-app/app/(tabs)/items/index.tsx b/apps/mobile-app/app/(tabs)/items/index.tsx
index c266c868a..19bdec191 100644
--- a/apps/mobile-app/app/(tabs)/items/index.tsx
+++ b/apps/mobile-app/app/(tabs)/items/index.tsx
@@ -23,7 +23,6 @@ import Logo from '@/assets/images/logo.svg';
import { FolderModal } from '@/components/folders/FolderModal';
import { FolderPill, type FolderWithCount } from '@/components/folders/FolderPill';
import { ItemCard } from '@/components/items/ItemCard';
-import LoadingOverlay from '@/components/LoadingOverlay';
import { ThemedContainer } from '@/components/themed/ThemedContainer';
import { ThemedText } from '@/components/themed/ThemedText';
import { ThemedView } from '@/components/themed/ThemedView';
@@ -84,8 +83,7 @@ export default function ItemsScreen(): React.ReactNode {
const [isLoadingItems, setIsLoadingItems] = useMinDurationLoading(false, 200);
const [refreshing, setRefreshing] = useMinDurationLoading(false, 200);
const [serviceUrl, setServiceUrl] = useState<string | null>(null);
- const { executeVaultMutation, isLoading, syncStatus } = useVaultMutate();
- const [isSyncing, setIsSyncing] = useState(false);
+ const { executeVaultMutation } = useVaultMutate();
const [showFolderModal, setShowFolderModal] = useState(false);
// Search and filter state
@@ -287,19 +285,13 @@ export default function ItemsScreen(): React.ReactNode {
}, 200);
},
/**
- * On offline.
+ * On offline - just update state, ServerSyncIndicator shows offline status.
*/
- onOffline: () => {
+ onOffline: async () => {
setRefreshing(false);
setIsLoadingItems(false);
- authContext.setOfflineMode(true);
- setTimeout(() => {
- Toast.show({
- type: 'error',
- text1: t('items.offlineMessage'),
- position: 'bottom',
- });
- }, 200);
+ await dbContext.setIsOffline(true);
+ await dbContext.refreshSyncState();
},
/**
* On error.
@@ -335,7 +327,7 @@ export default function ItemsScreen(): React.ReactNode {
});
}
}
- }, [syncVault, loadItems, setIsLoadingItems, setRefreshing, authContext, router, t]);
+ }, [syncVault, loadItems, setIsLoadingItems, setRefreshing, authContext, dbContext, router, t]);
useEffect(() => {
if (!isAuthenticated || !isDatabaseAvailable) {
@@ -365,16 +357,14 @@ export default function ItemsScreen(): React.ReactNode {
/**
* Delete an item (move to trash).
+ * Non-blocking: saves locally and syncs in background via ServerSyncIndicator.
*/
const onItemDelete = useCallback(async (itemId: string): Promise<void> => {
- setIsSyncing(true);
-
await executeVaultMutation(async () => {
await dbContext.sqliteClient!.items.trash(itemId);
- setIsSyncing(false);
});
- await new Promise(resolve => setTimeout(resolve, 250));
+ // Reload items to reflect the deletion
await loadItems();
}, [dbContext.sqliteClient, executeVaultMutation, loadItems]);
@@ -860,7 +850,6 @@ export default function ItemsScreen(): React.ReactNode {
return (
<ThemedContainer style={styles.container}>
- {isSyncing && <LoadingOverlay status={syncStatus} />}
<CollapsibleHeader
title={t('items.title')}
scrollY={scrollY}
@@ -909,7 +898,6 @@ export default function ItemsScreen(): React.ReactNode {
ListEmptyComponent={renderEmptyComponent() as React.ReactElement}
/>
</ThemedView>
- {isLoading && <LoadingOverlay status={syncStatus || t('items.deletingItem')} />}
{/* Create folder modal */}
<FolderModal
diff --git a/apps/mobile-app/components/ServerSyncIndicator.tsx b/apps/mobile-app/components/ServerSyncIndicator.tsx
new file mode 100644
index 000000000..d7edc7cb6
--- /dev/null
+++ b/apps/mobile-app/components/ServerSyncIndicator.tsx
@@ -0,0 +1,188 @@
+import { Ionicons } from '@expo/vector-icons';
+import React, { useState } from 'react';
+import { ActivityIndicator, Platform, StyleSheet, View } from 'react-native';
+import { useSafeAreaInsets } from 'react-native-safe-area-context';
+import Toast from 'react-native-toast-message';
+
+import { useColors } from '@/hooks/useColorScheme';
+import { useTranslation } from '@/hooks/useTranslation';
+import { useVaultSync } from '@/hooks/useVaultSync';
+
+import { ThemedText } from '@/components/themed/ThemedText';
+import { RobustPressable } from '@/components/ui/RobustPressable';
+import { useApp } from '@/context/AppContext';
+import { useDb } from '@/context/DbContext';
+
+/**
+ * Floating sync status indicator component.
+ * Displays sync state badges for offline mode, syncing, and pending sync.
+ *
+ * Priority order (highest to lowest):
+ * 1. Offline (amber) - network unavailable
+ * 2. Syncing (green spinner) - sync in progress
+ * 3. Pending (blue spinner) - local changes waiting to be uploaded
+ * 4. Hidden - when synced
+ */
+export function ServerSyncIndicator(): React.ReactNode {
+ const { t } = useTranslation();
+ const colors = useColors();
+ const insets = useSafeAreaInsets();
+ const app = useApp();
+ const dbContext = useDb();
+ const { syncVault } = useVaultSync();
+ const [isRetrying, setIsRetrying] = useState(false);
+
+ // Only show when logged in AND vault is unlocked (dbAvailable)
+ if (!app.isLoggedIn || !dbContext.dbAvailable) {
+ return null;
+ }
+
+ /**
+ * Handle tap to force sync retry.
+ */
+ const handleRetry = async (): Promise<void> => {
+ if (isRetrying) {
+ return;
+ }
+
+ setIsRetrying(true);
+ dbContext.setIsSyncing(true);
+
+ try {
+ await syncVault({
+ onSuccess: async () => {
+ await dbContext.refreshSyncState();
+ if (dbContext.isOffline) {
+ // We were offline but now succeeded
+ Toast.show({
+ type: 'success',
+ text1: t('sync.backOnline'),
+ position: 'bottom',
+ });
+ }
+ setIsRetrying(false);
+ },
+ onOffline: () => {
+ Toast.show({
+ type: 'error',
+ text1: t('sync.stillOffline'),
+ position: 'bottom',
+ });
+ setIsRetrying(false);
+ },
+ onError: (error: string) => {
+ Toast.show({
+ type: 'error',
+ text1: t('sync.syncFailed'),
+ text2: error,
+ position: 'bottom',
+ });
+ setIsRetrying(false);
+ },
+ });
+ } catch {
+ setIsRetrying(false);
+ } finally {
+ dbContext.setIsSyncing(false);
+ await dbContext.refreshSyncState();
+ }
+ };
+
+ const styles = StyleSheet.create({
+ container: {
+ alignItems: 'center',
+ borderRadius: 24,
+ bottom: Platform.OS === 'ios' ? insets.bottom + 60 : 70,
+ elevation: 4,
+ flexDirection: 'row',
+ gap: 6,
+ left: 16,
+ paddingHorizontal: 14,
+ paddingVertical: 10,
+ position: 'absolute',
+ shadowColor: colors.black,
+ shadowOffset: { width: 0, height: 2 },
+ shadowOpacity: 0.25,
+ shadowRadius: 3.84,
+ zIndex: 999,
+ },
+ offline: {
+ backgroundColor: colors.warningBackground,
+ },
+ syncing: {
+ backgroundColor: colors.successBackground,
+ },
+ pending: {
+ backgroundColor: colors.infoBackground,
+ },
+ text: {
+ fontSize: 13,
+ fontWeight: '600',
+ },
+ offlineText: {
+ color: colors.warning,
+ },
+ syncingText: {
+ color: colors.success,
+ },
+ pendingText: {
+ color: colors.info,
+ },
+ });
+
+ // Priority 1: Offline indicator (tappable to retry)
+ // Shows both offline status and pending count if dirty
+ if (dbContext.isOffline) {
+ return (
+ <RobustPressable
+ style={[styles.container, styles.offline]}
+ onPress={handleRetry}
+ disabled={isRetrying}
+ >
+ {isRetrying ? (
+ <ActivityIndicator size="small" color={colors.warning} />
+ ) : (
+ <Ionicons name="cloud-offline" size={18} color={colors.warning} />
+ )}
+ <ThemedText style={[styles.text, styles.offlineText]}>
+ {dbContext.isDirty ? t('sync.offlineWithPending') : t('sync.offline')}
+ </ThemedText>
+ </RobustPressable>
+ );
+ }
+
+ // Priority 2: Syncing indicator (not tappable, shows progress)
+ if (dbContext.isSyncing) {
+ return (
+ <View style={[styles.container, styles.syncing]}>
+ <ActivityIndicator size="small" color={colors.success ?? '#16a34a'} />
+ <ThemedText style={[styles.text, styles.syncingText]}>
+ {t('sync.syncing')}
+ </ThemedText>
+ </View>
+ );
+ }
+
+ // Priority 3: Pending indicator (tappable to force sync)
+ if (dbContext.isDirty) {
+ return (
+ <RobustPressable
+ style={[styles.container, styles.pending]}
+ onPress={handleRetry}
+ disabled={isRetrying}
+ >
+ {isRetrying ? (
+ <ActivityIndicator size="small" color={colors.info} />
+ ) : (
+ <Ionicons name="cloud-upload" size={18} color={colors.info} />
+ )}
+ <ThemedText style={[styles.text, styles.pendingText]}>
+ {t('sync.pending')}
+ </ThemedText>
+ </RobustPressable>
+ );
+ }
+
+ // Synced - no indicator needed
+ return null;
+}
diff --git a/apps/mobile-app/components/ui/TitleContainer.tsx b/apps/mobile-app/components/ui/TitleContainer.tsx
index 1c3746980..36f0bffc0 100644
--- a/apps/mobile-app/components/ui/TitleContainer.tsx
+++ b/apps/mobile-app/components/ui/TitleContainer.tsx
@@ -1,7 +1,6 @@
import { Platform, StyleSheet, View } from 'react-native';
import Logo from '@/assets/images/logo.svg';
-import { OfflineBanner } from '@/components/OfflineBanner';
import { ThemedText } from '@/components/themed/ThemedText';
type TitleContainerProps = {
@@ -11,25 +10,19 @@ type TitleContainerProps = {
/**
* Title container component.
+ * Note: Offline/sync status is now shown via the floating ServerSyncIndicator in the tab layout.
*/
export function TitleContainer({ title, showLogo = true }: TitleContainerProps): React.ReactNode {
- // On Android, we don't show the title container as the native header is used, so we only return the offline banner.
+ // On Android, we don't show the title container as the native header is used
if (Platform.OS === 'android') {
- return (
- <>
- <OfflineBanner />
- </>
- );
+ return null;
}
return (
- <>
- <OfflineBanner />
- <View style={styles.titleContainer}>
- {showLogo && <Logo width={40} height={40} style={styles.logo} />}
- <ThemedText type="title">{title}</ThemedText>
- </View>
- </>
+ <View style={styles.titleContainer}>
+ {showLogo && <Logo width={40} height={40} style={styles.logo} />}
+ <ThemedText type="title">{title}</ThemedText>
+ </View>
);
}
diff --git a/apps/mobile-app/constants/Colors.ts b/apps/mobile-app/constants/Colors.ts
index c95c0413c..4f2c799b2 100644
--- a/apps/mobile-app/constants/Colors.ts
+++ b/apps/mobile-app/constants/Colors.ts
@@ -33,6 +33,11 @@ export const Colors = {
black: '#000000',
modalBackground: 'rgba(0, 0, 0, 0.5)',
success: '#10B981',
+ successBackground: '#dcfce7',
+ warning: '#d97706',
+ warningBackground: '#fef3c7',
+ info: '#2563eb',
+ infoBackground: '#dbeafe',
destructive: '#EF4444',
},
dark: {
@@ -64,6 +69,11 @@ export const Colors = {
black: '#000000',
modalBackground: 'rgba(88, 88, 88, 0.5)',
success: '#10B981',
+ successBackground: '#1a3d2b',
+ warning: '#f59e0b',
+ warningBackground: '#422006',
+ info: '#3b82f6',
+ infoBackground: '#1e3a5f',
destructive: '#EF4444',
},
} as const;
diff --git a/apps/mobile-app/context/DbContext.tsx b/apps/mobile-app/context/DbContext.tsx
index 5d4d34981..0389066ce 100644
--- a/apps/mobile-app/context/DbContext.tsx
+++ b/apps/mobile-app/context/DbContext.tsx
@@ -9,6 +9,13 @@ type DbContextType = {
sqliteClient: SqliteClient | null;
dbInitialized: boolean;
dbAvailable: boolean;
+ // Sync state tracking
+ isDirty: boolean;
+ isSyncing: boolean;
+ isOffline: boolean;
+ setIsSyncing: (syncing: boolean) => void;
+ setIsOffline: (offline: boolean) => Promise<void>;
+ refreshSyncState: () => Promise<void>;
storeEncryptionKey: (derivedKey: string) => Promise<void>;
storeEncryptionKeyDerivationParams: (keyDerivationParams: EncryptionKeyDerivationParams) => Promise<void>;
hasPendingMigrations: () => Promise<boolean>;
@@ -41,6 +48,21 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
*/
const [dbAvailable, setDbAvailable] = useState(false);
+ /**
+ * Sync state tracking - isDirty indicates local changes not yet uploaded to server.
+ */
+ const [isDirty, setIsDirty] = useState(false);
+
+ /**
+ * Sync state tracking - isSyncing indicates a sync operation is in progress.
+ */
+ const [isSyncing, setIsSyncingState] = useState(false);
+
+ /**
+ * Offline mode state - indicates network is unavailable.
+ */
+ const [isOffline, setIsOfflineState] = useState(false);
+
/**
* Unlock the vault in the native module which will decrypt the database using the stored encryption key
* and load it into memory.
@@ -142,6 +164,36 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
setDbAvailable(true);
}, []);
+ /**
+ * Refresh sync state from native layer. Call this after mutations or sync operations.
+ */
+ const refreshSyncState = useCallback(async (): Promise<void> => {
+ try {
+ const syncState = await NativeVaultManager.getSyncState();
+ setIsDirty(syncState.isDirty);
+ // Also refresh offline mode from native
+ const offline = await NativeVaultManager.getOfflineMode();
+ setIsOfflineState(offline);
+ } catch (error) {
+ console.error('Failed to refresh sync state:', error);
+ }
+ }, []);
+
+ /**
+ * Set syncing state - exposed for use by sync hooks.
+ */
+ const setIsSyncing = useCallback((syncing: boolean): void => {
+ setIsSyncingState(syncing);
+ }, []);
+
+ /**
+ * Set offline mode and persist to native layer.
+ */
+ const setIsOffline = useCallback(async (offline: boolean): Promise<void> => {
+ setIsOfflineState(offline);
+ await NativeVaultManager.setOfflineMode(offline);
+ }, []);
+
/**
* Get the current vault metadata directly from SQLite client
*/
@@ -177,6 +229,13 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
sqliteClient,
dbInitialized,
dbAvailable,
+ // Sync state
+ isDirty,
+ isSyncing,
+ isOffline,
+ setIsSyncing,
+ setIsOffline,
+ refreshSyncState,
hasPendingMigrations,
clearDatabase,
getVaultMetadata,
@@ -186,7 +245,7 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }
storeEncryptionKeyDerivationParams,
checkStoredVault,
setDatabaseAvailable,
- }), [sqliteClient, dbInitialized, dbAvailable, hasPendingMigrations, clearDatabase, getVaultMetadata, testDatabaseConnection, unlockVault, storeEncryptionKey, storeEncryptionKeyDerivationParams, checkStoredVault, setDatabaseAvailable]);
+ }), [sqliteClient, dbInitialized, dbAvailable, isDirty, isSyncing, isOffline, setIsSyncing, setIsOffline, refreshSyncState, hasPendingMigrations, clearDatabase, getVaultMetadata, testDatabaseConnection, unlockVault, storeEncryptionKey, storeEncryptionKeyDerivationParams, checkStoredVault, setDatabaseAvailable]);
return (
<DbContext.Provider value={contextValue}>
diff --git a/apps/mobile-app/hooks/useVaultMutate.ts b/apps/mobile-app/hooks/useVaultMutate.ts
index 4a5ed98d2..84367e883 100644
--- a/apps/mobile-app/hooks/useVaultMutate.ts
+++ b/apps/mobile-app/hooks/useVaultMutate.ts
@@ -87,54 +87,59 @@ export function useVaultMutate() : {
};
}, [dbContext, authContext, t]);
+ /**
+ * Trigger background sync without blocking the UI.
+ * This is fire-and-forget - the ServerSyncIndicator shows progress.
+ */
+ const triggerBackgroundSync = useCallback(async (options: VaultMutationOptions): Promise<void> => {
+ dbContext.setIsSyncing(true);
+
+ try {
+ await syncVault({
+ onSuccess: async () => {
+ // Register credential identities after successful sync
+ try {
+ await NativeVaultManager.registerCredentialIdentities();
+ } catch (error) {
+ console.warn('VaultMutate: Failed to register credential identities:', error);
+ }
+ await dbContext.refreshSyncState();
+ options.onSuccess?.();
+ },
+ onError: async (error) => {
+ await dbContext.refreshSyncState();
+ // Don't show error toast - the indicator shows offline/pending state
+ console.warn('Background sync failed:', error);
+ options.onError?.(new Error(error));
+ },
+ onOffline: async () => {
+ // Local change is saved and isDirty is set - will sync when back online
+ await dbContext.refreshSyncState();
+ options.onSuccess?.();
+ }
+ });
+ } finally {
+ dbContext.setIsSyncing(false);
+ await dbContext.refreshSyncState();
+ }
+ }, [syncVault, dbContext]);
+
/**
* Execute the provided operation (e.g. create/update/delete credential)
- *
- * Implements the mutation pattern from OFFLINE_MODE.md (matching browser extension):
- * 1. Apply mutation to local database (via beginTransaction/commitTransaction)
- * 2. commitTransaction atomically: exports, encrypts, stores vault AND marks dirty + increments mutation sequence
- * 3. Call syncVault() which handles everything: check isDirty, merge if needed, upload
- *
- * Note: The dirty flag and mutation sequence are now set atomically in native commitTransaction(),
- * so we don't need to call markVaultDirty() separately.
*/
const executeMutateOperation = useCallback(async (
operation: () => Promise<void>,
options: VaultMutationOptions
): Promise<void> => {
- setSyncStatus(t('vault.savingChangesToVault'));
-
- // Execute the provided operation (e.g. create/update/delete credential)
- // The operation wraps its changes in beginTransaction/commitTransaction
- // commitTransaction atomically persists vault AND marks dirty + increments mutation sequence
await operation();
- // Sync vault - this handles everything:
- // - Checks if server has newer vault
- // - Merges if isDirty and server has updates
- // - Uploads local changes
- // - Handles race detection and retries
- setSyncStatus(t('vault.syncingVault'));
- await syncVault({
- onStatus: (message) => setSyncStatus(message),
- onSuccess: async () => {
- // Register credential identities after successful sync
- try {
- await NativeVaultManager.registerCredentialIdentities();
- } catch (error) {
- console.warn('VaultMutate: Failed to register credential identities:', error);
- }
- options.onSuccess?.();
- },
- onError: (error) => {
- options.onError?.(new Error(error));
- },
- onOffline: () => {
- // Local change is saved and isDirty is set - will sync when back online
- options.onSuccess?.();
- }
- });
- }, [t, syncVault]);
+ // Refresh sync state to show "Pending" indicator immediately
+ await dbContext.refreshSyncState();
+
+ // Trigger background sync - fire-and-forget, don't await
+ // The ServerSyncIndicator will show syncing/pending/offline state
+ void triggerBackgroundSync(options);
+ }, [dbContext, triggerBackgroundSync]);
/**
* Execute the provided operation (e.g. create/update/delete credential)
@@ -245,23 +250,12 @@ export function useVaultMutate() : {
/**
* Hook to execute a vault mutation which uploads a new encrypted vault to the server.
- *
- * Follows the pattern from OFFLINE_MODE.md - no pre-sync needed because:
- * 1. LWW merge resolves conflicts - even if mutating a stale vault, merge picks latest
- * 2. Popup open triggers sync - vault is reasonably fresh when user starts interacting
- * 3. Simpler mental model - Mutation = save locally + sync, that's it
*/
const executeVaultMutation = useCallback(async (
operation: () => Promise<void>,
options: VaultMutationOptions = {}
) => {
try {
- setIsLoading(true);
-
- // Execute the mutation operation, which:
- // 1. Runs the operation (beginTransaction + SQL + commitTransaction)
- // 2. commitTransaction atomically stores vault + marks dirty + increments mutation sequence
- // 3. Calls syncVault() which handles merge/upload
await executeMutateOperation(operation, options);
} catch (error) {
console.error('Error during vault mutation:', error);
@@ -271,9 +265,6 @@ export function useVaultMutate() : {
position: 'bottom'
});
options.onError?.(error instanceof Error ? error : new Error(t('common.errors.unknownError')));
- } finally {
- setIsLoading(false);
- setSyncStatus('');
}
}, [executeMutateOperation, t]);
diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.json
index afe88db5b..cd341d1ab 100644
--- a/apps/mobile-app/i18n/locales/en.json
+++ b/apps/mobile-app/i18n/locales/en.json
@@ -694,6 +694,16 @@
"INTERNAL_SERVER_ERROR": "Internal server error.",
"VAULT_ERROR": "The local vault is not up-to-date. Please synchronize your vault by refreshing the page and try again."
},
+ "sync": {
+ "offline": "Offline",
+ "offlineWithPending": "Offline (pending)",
+ "syncing": "Syncing...",
+ "pending": "Pending sync",
+ "retrySync": "Tap to retry",
+ "backOnline": "Back online",
+ "stillOffline": "Still offline",
+ "syncFailed": "Sync failed"
+ },
"app": {
"status": {
"unlockingVault": "Unlocking vault",
@@ -702,13 +712,13 @@
"retryingConnection": "Retrying connection..."
},
"offline": {
- "banner": "Offline mode (read-only)",
+ "banner": "Offline - changes will sync when online",
"backOnline": "Back online",
"stillOffline": "Still offline"
},
"alerts": {
"syncIssue": "No Connection",
- "syncIssueMessage": "The AliasVault server could not be reached and your vault could not be synced. Would you like to open your local vault in read-only mode or retry the connection?",
+ "syncIssueMessage": "The AliasVault server could not be reached and your vault could not be synced. Would you like to open your local vault or retry the connection?",
"openLocalVault": "Open Local Vault",
"retrySync": "Retry Sync"
},
diff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.cs
index 13cd55092..d89daf9fe 100644
--- a/apps/server/AliasVault.Client/Services/ItemService.cs
+++ b/apps/server/AliasVault.Client/Services/ItemService.cs
@@ -277,10 +277,7 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
var typeChanged = existingItem.ItemType != item.ItemType;
// Update basic item info only if values changed
- var itemLevelChanged = existingItem.Name != item.Name ||
- existingItem.ItemType != item.ItemType ||
- existingItem.LogoId != item.LogoId ||
- existingItem.FolderId != item.FolderId;
+ var itemLevelChanged = existingItem.Name != item.Name || existingItem.ItemType != item.ItemType || existingItem.LogoId != item.LogoId || existingItem.FolderId != item.FolderId;
if (itemLevelChanged)
{