Update 'src/components/timer.vue'

practiced-songs
mahuntington 1 year ago
parent 819decca07
commit 5241492be5

@ -6,16 +6,13 @@
const { proxy } = getCurrentInstance();
onMounted(()=>{
let started = false
window.addEventListener('keydown', (event)=>{
if(event.key === 'ArrowDown' && !started){
if(event.key === 'ArrowDown'){
event.preventDefault()
proxy.start()
started = true
} else if (event.key === 'ArrowUp' && started){
} else if (event.key === 'ArrowUp'){
event.preventDefault()
proxy.stop()
started = false
}
})
})
@ -78,6 +75,7 @@
},
start(event){
if(this.running === false){
this.startTime = Date.now();
this.running = true;
this.intervalID = setInterval(()=>{
@ -105,6 +103,7 @@
this.setManualTime(this.totalSeconds)
window.localStorage.setItem('lastTotalSeconds', this.totalSeconds);
}, 1000);
}
},
setManualTime(seconds){
const timeObj = createTimeObj(this.totalSeconds)
@ -117,9 +116,11 @@
this.setManualTime(this.totalSeconds)
},
stop(event){
if(this.running === true){
this.running = false;
this.savedPreviousSeconds += getAccumulatedSeconds(Date.now(), this.startTime);
clearInterval(this.intervalID);
}
},
reset(event){
this.savedPreviousSeconds = 0;

Loading…
Cancel
Save