retrigger notification query on effect rather than new query (#3573)

* retrigger notification query on effect rather than new query

* move unviewedObs refetch to effect

* fix test

* Remove trailing whitespaces

---------

Co-authored-by: Johannes Klein <johannes.t.klein@gmail.com>
This commit is contained in:
Ryan Stelly
2026-04-28 13:28:02 -05:00
committed by GitHub
parent 4fce2f4889
commit 3e5c85f9b8
3 changed files with 11 additions and 8 deletions

View File

@@ -23,9 +23,6 @@ const NotificationsTab = ( { id, text }: TabComponentProps ) => {
[
"NotificationsTab",
"notificationsCount",
// We want to check for notifications when the user views an
// observation, because that might make the indicator go away
observationMarkedAsViewedAt,
id,
],
( optsWithAuth: ApiOpts ) => fetchUnviewedObservationUpdatesCount(
@@ -41,6 +38,10 @@ const NotificationsTab = ( { id, text }: TabComponentProps ) => {
},
);
useEffect( () => {
refetch();
}, [observationMarkedAsViewedAt, refetch] );
useEffect( ( ) => {
const listener = EventRegister.addEventListener(
NOTIFICATIONS_REFRESHED,

View File

@@ -1,6 +1,6 @@
import { fetchUnviewedObservationUpdatesCount } from "api/observations";
import NotificationsIcon from "navigation/BottomTabNavigator/NotificationsIcon";
import React from "react";
import React, { useEffect } from "react";
import {
useAuthenticatedQuery,
useCurrentUser,
@@ -23,12 +23,9 @@ const NotificationsIconContainer = ( {
// TODO: enable fields if it makes sense
// https://linear.app/inaturalist/issue/MOB-1362/enable-fields-for-unviewed-updates-count-in-notificationsicon
const { data: unviewedUpdatesCount } = useAuthenticatedQuery(
const { data: unviewedUpdatesCount, refetch } = useAuthenticatedQuery(
[
"notificationsCount",
// We want to check for notifications when the user views an
// observation, because that might make the indicator go away
observationMarkedAsViewedAt,
],
optsWithAuth => fetchUnviewedObservationUpdatesCount( {}, optsWithAuth ),
{
@@ -39,6 +36,10 @@ const NotificationsIconContainer = ( {
},
);
useEffect( () => {
refetch();
}, [observationMarkedAsViewedAt, refetch] );
const hasUnread = ( unviewedUpdatesCount ?? 0 ) > 0;
return (

View File

@@ -27,6 +27,7 @@ jest.mock( "sharedHooks/useAuthenticatedQuery", () => ( {
__esModule: true,
default: () => ( {
data: 0,
refetch: () => undefined,
} ),
} ) );