Skip to content

Commit

Permalink
refactor: reuse
Browse files Browse the repository at this point in the history
update useKeyboard to point at external lib
  • Loading branch information
eliranmal committed Dec 5, 2021
1 parent ea0350c commit fe9a4ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"homepage": "https://eliranmal.github.io/countdown/",
"dependencies": {
"@eliranmal/react-hooks": "^0.1.2",
"@eliranmal/react-hooks": "^0.3.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
Expand Down
36 changes: 18 additions & 18 deletions src/components/timer/Timer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React, {useRef, useState, useEffect} from 'react'
import useLocalStorage from 'use-local-storage'
import {useAnimationFrame} from '@eliranmal/react-hooks'
import {
useAnimationFrame,
useKeyboard,
mapKeyboardEvents,
} from '@eliranmal/react-hooks'
import ReactTooltip from 'react-tooltip'

import useKeyboard from '../../hooks/useKeyboard'
import useAnimationEvent from '../../hooks/useAnimationEvent'
import timer from '../../lib/timer'
import {flatMap as colors} from '../../lib/colors'
import {mapAsDuration, durationAsString} from '../../lib/util'
import useAnimationEvent from '../../hooks/useAnimationEvent'

import Button from '../button/Button'

Expand Down Expand Up @@ -60,21 +63,18 @@ const Timer = ({initialTime, lapThreshold, direction}) => {
{...props}
/>)

// todo - move keybinding into Button
useKeyboard(({code}) => {
switch (code) {
case 32: // spacebar
countdownTimer.lap()
patchUnmarshalledTimerState()
break
case 8: // backspace
countdownTimer.abortLap()
patchUnmarshalledTimerState()
break
default:
break
}
})
useKeyboard(mapKeyboardEvents([
// spacebar
[32, () => {
countdownTimer.lap()
patchUnmarshalledTimerState()
}],
// backspace
[8, () => {
countdownTimer.abortLap()
patchUnmarshalledTimerState()
}],
]))

useAnimationEvent(
'pulse',
Expand Down

0 comments on commit fe9a4ca

Please sign in to comment.