Misc fixes for time pointer
continuous-integration/drone/pr Build encountered an error Details

This commit is contained in:
Charles E. Lehner 2021-06-07 22:29:04 -04:00
parent 1e68d971c8
commit 05e101f9e8
Signed by untrusted user: cel
GPG Key ID: C28D95BB012367EA
1 changed files with 6 additions and 4 deletions

View File

@ -54,7 +54,7 @@ let currentRangeI = 0;
function getCurrentRange(now) { function getCurrentRange(now) {
for (i = currentRangeI; i < ranges.length; i++) { for (i = currentRangeI; i < ranges.length; i++) {
const range = ranges[i]; const range = ranges[i];
if (!range) return; if (!range) continue;
const rangeStart = range.startTime; const rangeStart = range.startTime;
if (rangeStart <= now && (rangeStart + halfHour) > now) { if (rangeStart <= now && (rangeStart + halfHour) > now) {
return range; return range;
@ -81,7 +81,7 @@ if (!pointer) {
pointer.id = 'pointer'; pointer.id = 'pointer';
} }
let prevRange; let prevRange = getCurrentRange(new Date().getTime());
function updatePointer(d) { function updatePointer(d) {
// Find current cell // Find current cell
const range = getCurrentRange(d.getTime()); const range = getCurrentRange(d.getTime());
@ -89,15 +89,17 @@ function updatePointer(d) {
// Done with schedule. Remove pointer. Need to refresh. // Done with schedule. Remove pointer. Need to refresh.
if (prevRange) { if (prevRange) {
prevRange.cell.removeChild(pointer); prevRange.cell.removeChild(pointer);
prevRange.cell.classList.remove('active');
prevRange = null; prevRange = null;
} }
return;
} }
// Move pointer to different cell if changed cell. // Move pointer to different cell if changed cell.
if (range !== prevRange) { if (range !== prevRange) {
const prevCell = prevRange && prevRange.cell if (prevRange) prevRange.cell.classList.remove('active');
if (prevCell) prevCell.classList.remove('active');
range.cell.classList.add('active'); range.cell.classList.add('active');
range.cell.appendChild(pointer); range.cell.appendChild(pointer);
prevRange = range;
} }
// Move pointer based on time in current cell. // Move pointer based on time in current cell.
const progress = (d.getTime() - range.startTime) / halfHour; const progress = (d.getTime() - range.startTime) / halfHour;