diff --git a/app/phone-calls/components/keypad.tsx b/app/phone-calls/components/keypad.tsx new file mode 100644 index 0000000..cba7afe --- /dev/null +++ b/app/phone-calls/components/keypad.tsx @@ -0,0 +1,90 @@ +import type { FunctionComponent } from "react"; +import type { PressHookProps } from "@react-aria/interactions"; +import { usePress } from "@react-aria/interactions"; + +type Props = { + onDigitPressProps: (digit: string) => PressHookProps; + onZeroPressProps: PressHookProps; +}; + +const Keypad: FunctionComponent = ({ children, onDigitPressProps, onZeroPressProps }) => { + return ( +
+ + + + ABC + + + DEF + + + + + GHI + + + JKL + + + MNO + + + + + PQRS + + + TUV + + + WXYZ + + + + + + + + {typeof children !== "undefined" ? {children} : null} +
+ ); +}; + +export default Keypad; + +const Row: FunctionComponent = ({ children }) => ( +
{children}
+); + +const DigitLetters: FunctionComponent = ({ children }) =>
{children}
; + +type DigitProps = { + digit: string; + onPressProps: Props["onDigitPressProps"]; +}; + +const Digit: FunctionComponent = ({ children, digit, onPressProps }) => { + const { pressProps } = usePress(onPressProps(digit)); + + return ( +
+ {digit} + {children} +
+ ); +}; + +type ZeroDigitProps = { + onPressProps: Props["onZeroPressProps"]; +}; + +const ZeroDigit: FunctionComponent = ({ onPressProps }) => { + const { pressProps } = usePress(onPressProps); + + return ( +
+ 0 + +
+ ); +}; diff --git a/app/phone-calls/pages/keypad.tsx b/app/phone-calls/pages/keypad.tsx index 18d7e20..b0af68d 100644 --- a/app/phone-calls/pages/keypad.tsx +++ b/app/phone-calls/pages/keypad.tsx @@ -1,83 +1,22 @@ import type { BlitzPage } from "blitz"; import { Link, Routes } from "blitz"; -import type { FunctionComponent } from "react"; import { useRef } from "react"; import { atom, useAtom } from "jotai"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faBackspace, faPhoneAlt as faPhone } from "@fortawesome/pro-solid-svg-icons"; -import { usePress } from "@react-aria/interactions"; import Layout from "../../core/layouts/layout"; +import Keypad from "../components/keypad"; import useRequireOnboarding from "../../core/hooks/use-require-onboarding"; -const Keypad: BlitzPage = () => { +const KeypadPage: BlitzPage = () => { useRequireOnboarding(); const phoneNumber = useAtom(phoneNumberAtom)[0]; const pressBackspace = useAtom(pressBackspaceAtom)[1]; - - return ( -
-
- {phoneNumber} -
- -
- - - - ABC - - - DEF - - - - - GHI - - - JKL - - - MNO - - - - - PQRS - - - TUV - - - WXYZ - - - - - - - - - - - - - -
- -
-
-
-
- ); -}; - -const ZeroDigit: FunctionComponent = () => { const timeoutRef = useRef | null>(null); const pressDigit = useAtom(pressDigitAtom)[1]; const longPressDigit = useAtom(longPressDigitAtom)[1]; - const { pressProps } = usePress({ + const onZeroPressProps = { onPressStart() { pressDigit("0"); timeoutRef.current = setTimeout(() => { @@ -89,33 +28,33 @@ const ZeroDigit: FunctionComponent = () => { clearTimeout(timeoutRef.current); } }, + }; + const onDigitPressProps = (digit: string) => ({ + onPress() { + pressDigit(digit); + }, }); return ( -
- 0 + +
+
+ {phoneNumber} +
+ + + + + + + +
+ +
+
); }; -const Row: FunctionComponent = ({ children }) => ( -
{children}
-); - -const Digit: FunctionComponent<{ digit: string }> = ({ children, digit }) => { - const pressDigit = useAtom(pressDigitAtom)[1]; - const onClick = () => pressDigit(digit); - - return ( -
- {digit} - {children} -
- ); -}; - -const DigitLetters: FunctionComponent = ({ children }) =>
{children}
; - const phoneNumberAtom = atom(""); const pressDigitAtom = atom(null, (get, set, digit: string) => { if (get(phoneNumberAtom).length > 17) { @@ -139,8 +78,8 @@ const pressBackspaceAtom = atom(null, (get, set) => { set(phoneNumberAtom, (prevState) => prevState.slice(0, -1)); }); -Keypad.getLayout = (page) => {page}; +KeypadPage.getLayout = (page) => {page}; -Keypad.authenticate = { redirectTo: Routes.SignIn() }; +KeypadPage.authenticate = { redirectTo: Routes.SignIn() }; -export default Keypad; +export default KeypadPage;