Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions formulus/src/database/repositories/WatermelonDBRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,16 @@ export class WatermelonDBRepo implements LocalRepoInterface {
}

/**
* Get pending changes from the local database
* @returns Promise resolving to an array of pending changes
* Get pending changes from the local database (unsynced or updated after last sync).
* Includes new, updated, and soft-deleted records so sync can push them to the server.
* synced_at can be null or 0 when never synced depending on storage.
*/
getPendingChanges(): Promise<Observation[]> {
return this.observationsCollection
.query(
Q.or(
Q.where('synced_at', Q.eq(null)),
Q.where('synced_at', 0),
Q.where('updated_at', Q.gt(Q.column('synced_at'))),
),
)
Expand Down
9 changes: 9 additions & 0 deletions formulus/src/screens/SyncScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ActivityIndicator,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useFocusEffect } from '@react-navigation/native';
import Icon from '@react-native-vector-icons/material-design-icons';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { formatRelativeTime } from '../utils/dateUtils';
Expand Down Expand Up @@ -314,6 +315,14 @@ const SyncScreen = () => {
updateProgress,
]);

// Refresh pending count whenever the Sync screen gains focus so it stays in sync after creating observations
useFocusEffect(
useCallback(() => {
updatePendingUploads();
updatePendingObservations();
}, [updatePendingUploads, updatePendingObservations]),
);

useEffect(() => {
if (!syncState.progress || !syncState.isActive) {
Animated.timing(animatedProgress, {
Expand Down
Loading