diff --git a/package-lock.json b/package-lock.json index abbdf68..27ea672 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1204,9 +1204,9 @@ "integrity": "sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg==" }, "@eliranmal/react-hooks": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/@eliranmal/react-hooks/-/react-hooks-0.1.2.tgz", - "integrity": "sha512-xcxht0QN+MUTLGDDY7P2LaakgsjCXOsxQlYQMVfeeXEIo27QqXc2p+F4unfqwHTbY4Ss/457zDUkpi9OZ8kiUg==" + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@eliranmal/react-hooks/-/react-hooks-0.3.0.tgz", + "integrity": "sha512-JIBVfIZp08Z7cL8cj9TdakawBrjYFp0oGCRx6/s+v7jUojMfees1DznMCg++ENsMklGZA+ctDXdkczquGBCvsQ==" }, "@eslint/eslintrc": { "version": "0.4.3", diff --git a/package.json b/package.json index 96bc888..05d1190 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/timer/Timer.js b/src/components/timer/Timer.js index 3e584c6..dc27569 100644 --- a/src/components/timer/Timer.js +++ b/src/components/timer/Timer.js @@ -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' @@ -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',