mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-10-05 17:42:27 -04:00
wire taxon search into useMyObservationsQuery
This commit is contained in:
1 parent
050227e3f3
commit
9c8ffc641a
2 files changed
+14
-10
No files matched your search
@@ -97,6 +97,7 @@ const MyObservationsResults = ( ) => {
|
||||
|
||||
const localObservationIds = useLocalObservationIds();
|
||||
const sortMyObservationsEnabled = useFeatureFlag( FeatureFlag.SortMyObservationsEnabled );
|
||||
const searchMyObservationsEnabled = useFeatureFlag( FeatureFlag.SearchMyObservationsEnabled );
|
||||
const {
|
||||
observationIds: queryObservationIds,
|
||||
isServerAuthoritative,
|
||||
@@ -104,9 +105,11 @@ const MyObservationsResults = ( ) => {
|
||||
fetchNextPage: fetchNextPageFromQuery,
|
||||
refetch: refetchFromQuery,
|
||||
} = useMyObservationsQuery( );
|
||||
// Only use server-ordered list when the flag is on and the selected sort requires it
|
||||
const useServerOrder = sortMyObservationsEnabled && isServerAuthoritative;
|
||||
const observationIds = sortMyObservationsEnabled
|
||||
// Only use server-ordered result when at least one of the features that needs it is enabled;
|
||||
// when neither is, we use the plain local list anyway
|
||||
const myObsQueryEnabled = sortMyObservationsEnabled || searchMyObservationsEnabled;
|
||||
const useServerOrder = myObsQueryEnabled && isServerAuthoritative;
|
||||
const observationIds = myObsQueryEnabled
|
||||
? queryObservationIds
|
||||
: localObservationIds;
|
||||
const {
|
||||
|
||||
@@ -23,9 +23,9 @@ interface UseMyObservationsQueryResult {
|
||||
}
|
||||
|
||||
// We want to preserve offline behavior for the default sort (created at, desc) so a user can see
|
||||
// and interact with their obs offline. This hook uses selected sort to determine whether Realm or
|
||||
// the server should be the authoritative source of a user's observations (unsynced obs
|
||||
// are always merged in at the top regardless of source).
|
||||
// and interact with their obs offline. This hook uses selected sort and/or an active taxon search
|
||||
// to determine whether Realm or the server should be the authoritative source of a user's
|
||||
// observations (unsynced obs are always merged in at the top regardless of source).
|
||||
//
|
||||
// Logged-out users can never have server-ordered observations, since they can't upload until
|
||||
// they log in, so a non-default sort is applied to their local observations instead.
|
||||
@@ -34,8 +34,9 @@ const useMyObservationsQuery = ( ): UseMyObservationsQueryResult => {
|
||||
const { state } = useMyObservations( );
|
||||
const currentUser = useCurrentUser( );
|
||||
const isDefaultSort = state.observationsSort === OBSERVATIONS_SORT.DATE_UPLOADED_NEWEST;
|
||||
const hasActiveSearch = !!state.searchedTaxon;
|
||||
const sortLocally = !isDefaultSort && !currentUser;
|
||||
const isServerAuthoritative = !isDefaultSort && !!currentUser;
|
||||
const isServerAuthoritative = ( !isDefaultSort || hasActiveSearch ) && !!currentUser;
|
||||
|
||||
const localObservationIds = useLocalObservationIds(
|
||||
sortLocally
|
||||
@@ -52,6 +53,7 @@ const useMyObservationsQuery = ( ): UseMyObservationsQueryResult => {
|
||||
refetch,
|
||||
} = useServerOrderedObservations( {
|
||||
sortBy: state.observationsSort,
|
||||
taxonId: state.searchedTaxon?.id,
|
||||
enabled: isServerAuthoritative,
|
||||
} );
|
||||
|
||||
@@ -77,15 +79,14 @@ const useMyObservationsQuery = ( ): UseMyObservationsQueryResult => {
|
||||
|
||||
// dedupe in case any locally unsynced obs also exist in the server results
|
||||
const observationIds = useMemo( ( ) => {
|
||||
if ( isDefaultSort || sortLocally ) return localObservationIds;
|
||||
if ( !isServerAuthoritative ) return localObservationIds;
|
||||
const unsyncedUuids = new Set( unsyncedObservationIds.map( o => o.uuid ) );
|
||||
return [
|
||||
...unsyncedObservationIds,
|
||||
...serverObservationIds.filter( o => !unsyncedUuids.has( o.uuid ) ),
|
||||
];
|
||||
}, [
|
||||
isDefaultSort,
|
||||
sortLocally,
|
||||
isServerAuthoritative,
|
||||
localObservationIds,
|
||||
unsyncedObservationIds,
|
||||
serverObservationIds,
|
||||
|
||||
Reference in new issue
Block a user