File tree Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -166,9 +166,34 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
166
166
fetchNotifications ( { auth, settings } ) ;
167
167
} , [ auth . accounts , settings . filterReasons , settings . hideBots ] ) ;
168
168
169
- useInterval ( ( ) => {
170
- fetchNotifications ( { auth, settings } ) ;
171
- } , Constants . FETCH_NOTIFICATIONS_INTERVAL ) ;
169
+ useEffect ( ( ) => {
170
+ let timeout : NodeJS . Timeout ;
171
+
172
+ const resetTimeout = ( ) => {
173
+ if ( timeout ) {
174
+ clearTimeout ( timeout ) ;
175
+ }
176
+ timeout = setTimeout ( ( ) => {
177
+ fetchNotifications ( { auth, settings } ) ;
178
+ } , Constants . FETCH_NOTIFICATIONS_INTERVAL ) ;
179
+ } ;
180
+
181
+ const handleActivity = ( ) => {
182
+ console . log ( 'Activity detected' ) ;
183
+ resetTimeout ( ) ;
184
+ } ;
185
+
186
+ window . addEventListener ( 'mousedown' , handleActivity ) ;
187
+ window . addEventListener ( 'keydown' , handleActivity ) ;
188
+
189
+ resetTimeout ( ) ;
190
+
191
+ return ( ) => {
192
+ clearTimeout ( timeout ) ;
193
+ window . removeEventListener ( 'mousedown' , handleActivity ) ;
194
+ window . removeEventListener ( 'keydown' , handleActivity ) ;
195
+ } ;
196
+ } , [ auth , settings , fetchNotifications ] ) ;
172
197
173
198
useInterval ( ( ) => {
174
199
for ( const account of auth . accounts ) {
You can’t perform that action at this time.
0 commit comments