import type { BlitzPage } from "blitz"; import type { FunctionComponent } 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 Layout from "../../core/layouts/layout"; import useRequireOnboarding from "../../core/hooks/use-require-onboarding"; const pageTitle = "Keypad"; const Keypad: 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 = () => { // TODO: long press, convert + to 0 const pressDigit = useAtom(pressDigitAtom)[1]; const onClick = () => pressDigit("0"); return (
0 +
); }; 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) => { if (get(phoneNumberAtom).length > 17) { return; } set(phoneNumberAtom, (prevState) => prevState + digit); }); const pressBackspaceAtom = atom(null, (get, set) => { if (get(phoneNumberAtom).length === 0) { return; } set(phoneNumberAtom, (prevState) => prevState.slice(0, -1)); }); export default Keypad;