@@ -39,7 +39,9 @@ import FireList from './FireList.jsx'
3939const ShouldNotify = {
4040 MIN_INTERVAL_SECONDS : 30 ,
4141 MAX_RECENT_NOTIFICATIONS : 2 ,
42- MAX_RECENT_SECONDS : 5 * 60
42+ MAX_RECENT_SECONDS : 5 * 60 ,
43+ // XXX: Used to instantiate empty Notification to track window activity.
44+ NO_NOTIFICATION : { }
4345}
4446
4547const TIMESTAMP_LIMIT = 2 * Duration . HOUR
@@ -60,7 +62,7 @@ export default function PotentialFireList(props) {
6062 const [ indexOfOldFires , setIndexOfOldFires ] = useState ( - 1 )
6163 const [ region , setRegion ] = useState ( null )
6264 const [ shouldNotify , setShouldNotify ] = useState ( false )
63- const [ notification , setNotification ] = useState ( null )
65+ const [ notification , setNotification ] = useState ( ShouldNotify . NO_NOTIFICATION )
6466
6567 const allFiresRef = useRef ( [ ] )
6668 const eventSourceRef = useRef ( )
@@ -79,6 +81,10 @@ export default function PotentialFireList(props) {
7981 } , [ ] )
8082
8183 const handleNotification = useCallback ( ( ) => {
84+ if ( ! shouldNotify ) {
85+ return setNotification ( ShouldNotify . NO_NOTIFICATION )
86+ }
87+
8288 const { current : allFires } = allFiresRef
8389 const fire = allFires [ 0 ]
8490 const {
@@ -97,16 +103,16 @@ export default function PotentialFireList(props) {
97103 const mru = notifiedFires . length > 0 ? notifiedFires [ 0 ] . timestamp : 0
98104
99105 // At least MIN_INTERVAL_SECONDS between notifications.
100- if ( timestamp - mru > ShouldNotify . MIN_INTERVAL_SECONDS ) {
101- return
106+ if ( timestamp - mru <= ShouldNotify . MIN_INTERVAL_SECONDS ) {
107+ return setNotification ( ShouldNotify . NO_NOTIFICATION )
102108 }
103109
104110 const timestampLimit = timestamp - ShouldNotify . MAX_RECENT_SECONDS
105111 const recentlyNotifiedFires = notifiedFires . filter ( ( x ) => x . timestamp > timestampLimit )
106112
107113 // At most MAX_RECENT_NOTIFICATIONS every MAX_RECENT_SECONDS.
108114 if ( recentlyNotifiedFires . length >= ShouldNotify . MAX_RECENT_NOTIFICATIONS ) {
109- return
115+ return setNotification ( ShouldNotify . NO_NOTIFICATION )
110116 }
111117
112118 // -------------------------------------------------------------------------
@@ -122,7 +128,7 @@ export default function PotentialFireList(props) {
122128 tag : `${ timestamp } `
123129 }
124130 } )
125- } , [ ] )
131+ } , [ shouldNotify ] )
126132
127133 const handleToggleAllFires = useCallback ( ( ) => {
128134 const shouldIncludeAllFires = ! includesAllFires
@@ -169,15 +175,15 @@ export default function PotentialFireList(props) {
169175 allFires . sort ( ( a , b ) => b . sortId - a . sortId )
170176
171177 const first = allFires [ 0 ]
172- if ( shouldNotify && first != null && first . isRealTime ) {
173- if ( first . timestamp === timestamp && first . cameraID === cameraID ) {
178+ if ( first != null ) {
179+ if ( first . isRealTime && first . timestamp === timestamp && first . cameraID === cameraID ) {
174180 handleNotification ( )
175181 }
176182 }
177183
178184 updateFires ( includesAllFires )
179185 }
180- } , [ handleNotification , includesAllFires , region , shouldNotify , updateFires ] )
186+ } , [ handleNotification , includesAllFires , region , updateFires ] )
181187
182188 useEffect ( ( ) => {
183189 const searchParams = new URLSearchParams ( window . location . search )
@@ -225,7 +231,7 @@ export default function PotentialFireList(props) {
225231
226232 return 0 ,
227233 < >
228- { shouldNotify && notification && < Notification disableActiveWindow { ...notification } /> }
234+ < Notification disableActiveWindow title = "" { ...notification } />
229235 < FireList
230236 fires = { fires }
231237 firesByKey = { firesByKeyRef . current }
0 commit comments