Keep app awake during bulk uploads (#1898)

* Keep app awake while uploading; closes #1893

* Only activate keep awake during manual sync, not automatic sync
This commit is contained in:
Amanda Bullington
2024-07-31 12:17:25 -07:00
committed by GitHub
parent 1679f2f24a
commit 283b59cb45
4 changed files with 27 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
import {
useNetInfo
} from "@react-native-community/netinfo";
import { deactivateKeepAwake } from "@sayem314/react-native-keep-awake";
import { INatApiError } from "api/error";
import { deleteRemoteObservation } from "api/observations";
import { RealmContext } from "providers/contexts";
@@ -162,6 +163,8 @@ const useSyncObservations = ( currentUserId, uploadObservations ): Object => {
// being offline, so we're not checking internet connectivity here
if ( loggedIn ) {
await uploadObservations( );
} else {
deactivateKeepAwake( );
}
completeSync( );
}, [

View File

@@ -1,5 +1,4 @@
import { useNavigation } from "@react-navigation/native";
import { deactivateKeepAwake } from "@sayem314/react-native-keep-awake";
import { RealmContext } from "providers/contexts";
import {
useCallback, useEffect
@@ -197,7 +196,6 @@ export default useUploadObservations = canUpload => {
// fully stop uploads when cancel upload button is tapped
if ( uploadStatus === UPLOAD_CANCELLED ) {
abortController.abort( );
deactivateKeepAwake( );
}
}, [abortController, uploadStatus] );

View File

@@ -1,4 +1,4 @@
import { activateKeepAwake, deactivateKeepAwake } from "@sayem314/react-native-keep-awake";
import { activateKeepAwake } from "@sayem314/react-native-keep-awake";
import { StateCreator } from "zustand";
export const SYNC_PENDING = "sync-pending";
@@ -76,21 +76,15 @@ const createSyncObservationsSlice: StateCreator<SyncObservationsSlice> = set =>
syncingStatus: BEGIN_MANUAL_SYNC
} );
} ),
startAutomaticSync: ( ) => set( ( ) => {
activateKeepAwake( );
return ( {
syncingStatus: BEGIN_AUTOMATIC_SYNC
} );
} ),
completeSync: ( ) => set( ( ) => {
deactivateKeepAwake( );
return ( {
currentDeleteCount: 1,
deleteError: null,
deleteQueue: [],
syncingStatus: SYNC_PENDING
} );
} )
startAutomaticSync: ( ) => set( ( ) => ( {
syncingStatus: BEGIN_AUTOMATIC_SYNC
} ) ),
completeSync: ( ) => set( ( ) => ( {
currentDeleteCount: 1,
deleteError: null,
deleteQueue: [],
syncingStatus: SYNC_PENDING
} ) )
} );
export default createSyncObservationsSlice;

View File

@@ -1,3 +1,4 @@
import { deactivateKeepAwake } from "@sayem314/react-native-keep-awake";
import _ from "lodash";
import { RealmObservation } from "realmModels/types.d.ts";
import { StateCreator } from "zustand";
@@ -106,10 +107,19 @@ const createUploadObservationsSlice: StateCreator<UploadObservationsSlice> = set
},
multiError: error
} ) ),
stopAllUploads: ( ) => set( { ...DEFAULT_STATE, uploadStatus: UPLOAD_CANCELLED } ),
completeUploads: ( ) => set( ( ) => ( {
uploadStatus: UPLOAD_COMPLETE
} ) ),
stopAllUploads: ( ) => set( ( ) => {
deactivateKeepAwake( );
return ( {
...DEFAULT_STATE,
uploadStatus: UPLOAD_CANCELLED
} );
} ),
completeUploads: ( ) => set( ( ) => {
deactivateKeepAwake( );
return ( {
uploadStatus: UPLOAD_COMPLETE
} );
} ),
updateTotalUploadProgress: ( uuid, increment ) => set( state => {
const {
currentUpload,