diff --git a/src/frontend/dash/circlePacker.ts b/src/frontend/dash/circlePacker.ts index 008b06f..d5ed515 100644 --- a/src/frontend/dash/circlePacker.ts +++ b/src/frontend/dash/circlePacker.ts @@ -141,26 +141,38 @@ export class ClockCircle extends Circle{ let timeElemsWest = document.querySelectorAll('.bustime.west') let timeElemsEast = document.querySelectorAll('.bustime.east') - arrivals[busSigns[0]].forEach((v,i)=>{ - if(i>=2) {return} // only set first 2 arrivals - let minutesTill = Math.max(0,Math.round((v - Date.now())/1000/60)); - timeElemsEast[i].innerHTML = minutesTill + ' min' - if(minutesTill <= 5) { - timeElemsEast[i].classList.add('soonish') - } else { - timeElemsEast[i].classList.remove('soonish') - } - }) - arrivals[busSigns[1]].forEach((v,i)=>{ - if(i>=2) {return} // only set first 2 arrivals - let minutesTill = Math.max(0,Math.round((v - Date.now())/1000/60)); - timeElemsWest[i].innerHTML = minutesTill + ' min' - if(minutesTill <= 5) { - timeElemsWest[i].classList.add('soonish') - } else { - timeElemsWest[i].classList.remove('soonish') - } - }) + let minutesTillEastFirst = Math.max(0,Math.round((arrivals[busSigns[0]][0] - Date.now())/1000/60)); + timeElemsEast[0].innerHTML = minutesTillEastFirst + ' min' + if(minutesTillEastFirst <= 5) { + timeElemsEast[0].classList.add('soonish') + } else { + timeElemsEast[0].classList.remove('soonish') + } + + let minutesTillEastSecond = Math.max(0,Math.round((arrivals[busSigns[0]][1] - Date.now())/1000/60)); + timeElemsEast[1].innerHTML = minutesTillEastSecond + ' min' + if(minutesTillEastSecond <= 5) { + timeElemsEast[1].classList.add('soonish') + } else { + timeElemsEast[1].classList.remove('soonish') + } + + let minutesTillWestFirst = Math.max(0,Math.round((arrivals[busSigns[1]][0] - Date.now())/1000/60)); + timeElemsWest[0].innerHTML = minutesTillWestFirst + ' min' + if(minutesTillEastFirst <= 5) { + timeElemsWest[0].classList.add('soonish') + } else { + timeElemsWest[0].classList.remove('soonish') + } + + let minutesTillWestSecond = Math.max(0,Math.round((arrivals[busSigns[1]][1] - Date.now())/1000/60)); + timeElemsWest[1].innerHTML = minutesTillWestSecond + ' min' + if(minutesTillWestSecond <= 5) { + timeElemsWest[1].classList.add('soonish') + } else { + timeElemsWest[1].classList.remove('soonish') + } + })(); }, 15000); diff --git a/src/frontend/dash/index.ts b/src/frontend/dash/index.ts index 12ed10b..dbc9250 100644 --- a/src/frontend/dash/index.ts +++ b/src/frontend/dash/index.ts @@ -15,12 +15,11 @@ setInterval(regenCircles, 10) // chnage panel every 1 minutes let prevTime = Date.now(); -function regenCircles(loggedin?: LoggedIn) { - if(loggedin===undefined) {loggedin = loggedInCache} +function regenCircles() { const now = Date.now() - const loginEntries = Object.entries(loggedin) + const loginEntries = Object.entries(loggedInCache) .filter(entry => members.find(member => member.name == entry[0])) ; @@ -51,7 +50,6 @@ function update() { // return if there's no change if (JSON.stringify(loggedInCache) == JSON.stringify(loggedin)) { return } loggedInCache = loggedin - regenCircles(loggedin) })); } @@ -61,9 +59,6 @@ async function start() { placedCircles.push(new ClockCircle()); update() - setInterval(() => { - regenCircles(loggedInCache) - }, 1000 * 60); setInterval(() => { update() }, 1000 * 3);