Suppress data checking until previous call is done.

main
Joshua Sigona 3 years ago
parent 59ef65bfc3
commit 9d009ae0c0
  1. 59
      src/App.js

@ -156,35 +156,42 @@ function App() {
useEffect(()=>{ useEffect(()=>{
var notificationLastUpdate = new Date(new Date()-(NOTIFICATIONTIMEOUT*1000)) var notificationLastUpdate = new Date(new Date()-(NOTIFICATIONTIMEOUT*1000))
var largestNotificationID = -1 var largestNotificationID = -1
var dataCheck=true
const interval = setInterval(()=>{ const interval = setInterval(()=>{
notificationLastUpdate = new Date(new Date()-(NOTIFICATIONTIMEOUT*1000)) if (dataCheck) {
axios.get(BACKEND_URL+"/getNotifications?date="+encodeURIComponent(LZ(4,notificationLastUpdate.getUTCFullYear())+"-"+LZ(2,notificationLastUpdate.getUTCMonth()+1)+"-"+LZ(2,notificationLastUpdate.getUTCDate())+" "+LZ(2,notificationLastUpdate.getUTCHours())+":"+LZ(2,notificationLastUpdate.getUTCMinutes())+":"+LZ(2,notificationLastUpdate.getUTCSeconds())+"."+LZ(3,notificationLastUpdate.getUTCMilliseconds())+"+00")) dataCheck=false
.then((data)=>{ notificationLastUpdate = new Date(new Date()-(NOTIFICATIONTIMEOUT*1000))
if (data.data.length>0) { axios.get(BACKEND_URL+"/getNotifications?date="+encodeURIComponent(LZ(4,notificationLastUpdate.getUTCFullYear())+"-"+LZ(2,notificationLastUpdate.getUTCMonth()+1)+"-"+LZ(2,notificationLastUpdate.getUTCDate())+" "+LZ(2,notificationLastUpdate.getUTCHours())+":"+LZ(2,notificationLastUpdate.getUTCMinutes())+":"+LZ(2,notificationLastUpdate.getUTCSeconds())+"."+LZ(3,notificationLastUpdate.getUTCMilliseconds())+"+00"))
console.log("New notification array: "+JSON.stringify(data.data)) .then((data)=>{
setNotifications(data.data) if (data.data.length>0) {
var completion=false console.log("New notification array: "+JSON.stringify(data.data))
var largestID = -1 setNotifications(data.data)
for (var dat of data.data) { var completion=false
if (dat.id>largestNotificationID && dat.operation==="FINISH") { var largestID = -1
completion=true for (var dat of data.data) {
largestID=Math.max(dat.id,largestID) if (dat.id>largestNotificationID && dat.operation==="FINISH") {
break completion=true
} else largestID=Math.max(dat.id,largestID)
if (dat.id>largestNotificationID) break
{ } else
largestID=Math.max(dat.id,largestID) if (dat.id>largestNotificationID)
{
largestID=Math.max(dat.id,largestID)
}
}
if (largestID!==-1) {
largestNotificationID = largestID
if (completion) {progress2.play()} else {progress1.play()}
} }
} }
if (largestID!==-1) { })
largestNotificationID = largestID .catch((err)=>{
if (completion) {progress2.play()} else {progress1.play()} console.log(err.message)
} })
} .then(()=>{
}) dataCheck=true
.catch((err)=>{ })
console.log(err.message) }
})
},1000) },1000)
return ()=>clearInterval(interval) return ()=>clearInterval(interval)
},[]) },[])

Loading…
Cancel
Save