mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-10-07 10:32:28 -04:00
remove hook that sets observations to viewed on foreground
This commit is contained in:
1 parent
92491d93bb
commit
5062231888
4 files changed
+1
-120
No files matched your search
@@ -1,14 +1,9 @@
|
||||
import {
|
||||
useIconicTaxa,
|
||||
useObservationUpdatesWhenFocused,
|
||||
} from "sharedHooks";
|
||||
import { useIconicTaxa } from "sharedHooks";
|
||||
|
||||
import useTaxonCommonNames from "./hooks/useTaxonCommonNames";
|
||||
import useWorkQueue from "./hooks/useWorkQueue";
|
||||
|
||||
const NetworkService = ( ) => {
|
||||
useObservationUpdatesWhenFocused( );
|
||||
|
||||
useIconicTaxa( { reload: true } );
|
||||
// This only runs when App updates... which is rarely. It works for Settings
|
||||
// b/c it generally updates currentUser
|
||||
|
||||
@@ -22,7 +22,6 @@ export { default as useLocalObservations } from "./useLocalObservations";
|
||||
export { default as useLocationPermission } from "./useLocationPermission";
|
||||
export { default as useNavigateToObsEdit } from "./useNavigateToObsEdit";
|
||||
export { default as useObservationsUpdates } from "./useObservationsUpdates";
|
||||
export { default as useObservationUpdatesWhenFocused } from "./useObservationUpdatesWhenFocused";
|
||||
export { default as useQuery } from "./useQuery";
|
||||
export { default as useRemoteObservation } from "./useRemoteObservation";
|
||||
export { default as useScrollToOffset } from "./useScrollToOffset";
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
// @flow
|
||||
|
||||
import { RealmContext } from "providers/contexts";
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { AppState } from "react-native";
|
||||
import safeRealmWrite from "sharedHelpers/safeRealmWrite";
|
||||
|
||||
const { useRealm } = RealmContext;
|
||||
|
||||
const useObservationUpdatesWhenFocused = () => {
|
||||
const realm = useRealm();
|
||||
|
||||
const setObservationUpdatesViewedRealm = useCallback( () => {
|
||||
// Set all observations to viewed
|
||||
const observations = realm
|
||||
.objects( "Observation" )
|
||||
.filtered( "comments_viewed == false OR identifications_viewed == false" );
|
||||
if ( observations.length === 0 ) { return; }
|
||||
safeRealmWrite( realm, () => {
|
||||
observations.forEach( observation => {
|
||||
observation.comments_viewed = true;
|
||||
observation.identifications_viewed = true;
|
||||
} );
|
||||
}, "setting comments_viewed and ids_viewed to true in useObservationsUpdatesWhenFocused" );
|
||||
}, [realm] );
|
||||
|
||||
const onAppStateChange = useCallback(
|
||||
status => {
|
||||
// if the app is coming back from the background, set all observations to viewed
|
||||
if ( status === "active" ) {
|
||||
setObservationUpdatesViewedRealm();
|
||||
}
|
||||
},
|
||||
[setObservationUpdatesViewedRealm],
|
||||
);
|
||||
|
||||
useEffect( () => {
|
||||
// subscribe to app state changes
|
||||
const subscription = AppState.addEventListener(
|
||||
"change",
|
||||
onAppStateChange,
|
||||
);
|
||||
setObservationUpdatesViewedRealm();
|
||||
|
||||
// unsubscribe on unmount
|
||||
return () => subscription?.remove();
|
||||
}, [onAppStateChange, setObservationUpdatesViewedRealm] );
|
||||
};
|
||||
|
||||
export default useObservationUpdatesWhenFocused;
|
||||
Reference in new issue
Block a user