tried to dix the nap logic

This commit is contained in:
John Shaver 2018-12-12 19:28:49 -08:00
parent da848f6800
commit ffd9778e32

View file

@ -24,7 +24,7 @@ let state = {
updateColorState();
let updateStateInterval = setInterval(updateColorState, 1000);
let updateColorStateInterval = setInterval(updateColorState, 1000);
let renderInterval = setInterval(render, 50);
@ -42,6 +42,7 @@ function updateColorState() {
let newColor = state.color;
switch(state.napTime) {
case true:
console.log("Nap time until :", state.napEnd);
if(Date.now() < state.napEnd) {
newColor = "red";
break;
@ -52,16 +53,18 @@ function updateColorState() {
};
}
case false:
console.log("NO NAP!");
let time = getTime();
let timing = timings.find(x => x.start <= time && x.end > time);
newColor = timing.color
}
if(newColor !== state.color) {
console.log("setting color to", newcolor);
state = { ...state,
color: timing.color
color: newColor,
};
}
}
function render() {