Added setupListeners to store.ts in order to make fetched data be refetched automatically when the user's internet connection is restored
Added the same refetching code that is used for the other api files to notificationApi
Refactored out the internet connection code in NetworkDetector into its own hook
Refactored out the infinite loading functionality in useLiveNotifications into its own hook and made it generic. The original useInfiniteLoading hook has been replaced by this hook.
Purpose
Offline detection is now more deeply integrated
Notes
Multiple duplicate key warnings will be shown for the unread notifications view if the user reconnects and they received notifications while they were offline. However, the user won't experience any issues since the clear method inside of the useInfiniteLoading hook will eventually be called.
I found that the resetApiState() call was only necessary for the notification functionality. So, that's why the useInfiniteLoading hook has an optional resetApiStateFunction argument.
Testing Steps
Pull in the changes to your local copy of this branch and run it alongside the dj_starter_demo repo.
Use Developer Tools in order to make the app go offline
Create another admin and log in via a separate browser
Create a new farm
Reconnect the original app instance to the internet. Data should be refetched and you shouldn't experience any visual issues.
Changes
setupListeners
to store.ts in order to make fetched data be refetched automatically when the user's internet connection is restorednotificationApi
NetworkDetector
into its own hookuseLiveNotifications
into its own hook and made it generic. The originaluseInfiniteLoading
hook has been replaced by this hook.Purpose
Notes
useInfiniteLoading
hook will eventually be called.resetApiState()
call was only necessary for the notification functionality. So, that's why the useInfiniteLoading hook has an optional resetApiStateFunction argument.Testing Steps
Demo
Old Demo
https://user-images.githubusercontent.com/2876874/214456956-e56411e6-7e00-4acb-bece-331318606418.mov