✨ (timer) play and pause w…
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user