Skip to content

Commit a8a0e97

Browse files
committed
make the interval calls to fetch notifications 'silent' so they don't cause 'isLoading' to flash on the NotificationsSection
1 parent 931d0dc commit a8a0e97

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/notifications/domain/hooks/useNotifications.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,37 @@ export function useNotifications(
1717
const [error, setError] = useState<string | null>(null)
1818
const { user } = useSession()
1919

20-
const fetchNotifications = useCallback(async () => {
21-
try {
22-
setIsLoading(true)
23-
const fetched = await getAllNotificationsByUser(repository, paginationInfo)
24-
setError(null)
25-
setPaginationInfo(
26-
new NotificationsPaginationInfo(
27-
paginationInfo.page,
28-
paginationInfo.pageSize,
29-
fetched.totalItemCount
20+
const fetchNotifications = useCallback(
21+
async (silent = false) => {
22+
if (!silent) setIsLoading(true)
23+
try {
24+
const fetched = await getAllNotificationsByUser(repository, paginationInfo)
25+
setError(null)
26+
setPaginationInfo(
27+
new NotificationsPaginationInfo(
28+
paginationInfo.page,
29+
paginationInfo.pageSize,
30+
fetched.totalItemCount
31+
)
3032
)
31-
)
32-
setNotifications(fetched.items)
33-
} catch (err) {
34-
const message = err instanceof Error ? err.message : 'Failed to fetch notifications'
35-
setError(message)
36-
} finally {
37-
setIsLoading(false)
38-
}
39-
}, [repository, paginationInfo.page, paginationInfo.pageSize])
33+
setNotifications(fetched.items)
34+
} catch (err) {
35+
const message = err instanceof Error ? err.message : 'Failed to fetch notifications'
36+
setError(message)
37+
} finally {
38+
if (!silent) setIsLoading(false)
39+
}
40+
},
41+
[repository, paginationInfo.page, paginationInfo.pageSize]
42+
)
4043

4144
useEffect(() => {
4245
if (!user) return
4346

44-
void fetchNotifications()
47+
void fetchNotifications(false)
4548

4649
const interval = setInterval(() => {
47-
void fetchNotifications()
50+
void fetchNotifications(true)
4851
}, POLLING_NOTIFICATIONS_INTERVAL_TIME)
4952

5053
return () => clearInterval(interval)

0 commit comments

Comments
 (0)