Skip to content

Commit

Permalink
feat: adding drop function to remove bad laps
Browse files Browse the repository at this point in the history
  • Loading branch information
eviden-simon-hill committed Aug 30, 2023
1 parent 4c84eff commit fea2c3d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
| Reset | R |
| Clear | T |
| Squeeze | Y |
| Drop | D |
4 changes: 4 additions & 0 deletions public/timer.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ html {
color: #ddd;
}

.btn_drop {
color: #93e;
}

.limiter {
font-size: 6vw;
position: fixed;
Expand Down
19 changes: 19 additions & 0 deletions public/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ class Timer {
this.start();
}

drop() {
console.log(`running drop`);
if (this.records.length == 0) {
return;
}
console.log(`drop ${this.results.lastChild.innerText}`);
this.results.removeChild(this.results.lastChild);
// update bestlap
this.records.splice(this.records.length - 1, 1);
this.sorted = this.records.slice();
this.sorted.sort(compare);
this.bestlap.innerText = this.format(this.sorted[0]);
}

format(times) {
return `${lpad(times[0], 2)}:${lpad(times[1], 2)}.${lpad(Math.floor(times[2]), 3)}`;
}
Expand Down Expand Up @@ -265,6 +279,9 @@ function exec(name) {
case 'squeeze':
timer.squeeze();
break;
case 'drop':
timer.drop();
break;
}
}

Expand All @@ -275,6 +292,7 @@ let key_map = {
'82': 'reset', // r
'84': 'clear', // t
'89': 'squeeze', // y
'68': 'drop', // d
};

document.addEventListener('keydown', function (event) {
Expand All @@ -294,3 +312,4 @@ document.getElementById('btn_pause').addEventListener('click', btn_listener);
document.getElementById('btn_passed').addEventListener('click', btn_listener);
document.getElementById('btn_reset').addEventListener('click', btn_listener);
document.getElementById('btn_clear').addEventListener('click', btn_listener);
document.getElementById('btn_drop').addEventListener('click', btn_listener);
1 change: 1 addition & 0 deletions src/http/get-timer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ exports.handler = async function http(req) {
<a href="#" id="btn_passed" class="button btn_passed">Passed</a>
<a href="#" id="btn_reset" class="button btn_reset">Reset</a>
<a href="#" id="btn_clear" class="button btn_clear">Clear</a>
<a href="#" id="btn_drop" class="button btn_drop">Drop</a>
</nav>
<div class="limiter"></div>
<div class="display"></div>
Expand Down
1 change: 1 addition & 0 deletions views/timer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<a href="#" id="btn_passed" class="button btn_passed">Passed</a>
<a href="#" id="btn_reset" class="button btn_reset">Reset</a>
<a href="#" id="btn_clear" class="button btn_clear">Clear</a>
<a href="#" id="btn_drop" class="button btn_drop">Drop</a>
</nav>
<div class="limiter"></div>
<div class="display"></div>
Expand Down

0 comments on commit fea2c3d

Please sign in to comment.