(timer) play and pause w…

This commit is contained in:
2020-07-25 13:48:56 +02:00
parent cdb9995b05
commit 2c96b30272

View File

@@ -1,4 +1,10 @@
import { ref, computed, watch } from '@vue/composition-api'
import {
ref,
computed,
watch,
onMounted,
onUnmounted
} from '@vue/composition-api'
import { StopwatchState } from '@/types/StopwatchState'
import { notify } from '@/utils/notification'
import { useInterval } from './useInterval'
@@ -84,6 +90,23 @@ export const useTimer = () => {
isDev1Turn.value = true
}
const handleSpacebar = (event: KeyboardEvent) => {
if (event.target !== document.body) {
return
}
if (event.charCode === 32) {
timeState.value === 'started' ? pause() : start()
}
}
onMounted(() => {
window.addEventListener('keypress', handleSpacebar)
})
onUnmounted(() => {
window.removeEventListener('keypress', handleSpacebar)
})
return {
interval,
start,