From 42cdbaab4fc5a9b27b8e85d1515576ba37079414 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 2 Feb 2021 18:36:46 +0100 Subject: [PATCH] tweak(dial/nui): useContext instead of Consumer --- .../apps/dialer/components/DialPadGrid.tsx | 42 +++++++++---------- .../apps/dialer/components/DialerInput.tsx | 28 ++++++------- phone/src/modal/hooks/state.ts | 2 +- 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/phone/src/apps/dialer/components/DialPadGrid.tsx b/phone/src/apps/dialer/components/DialPadGrid.tsx index d0482b0..daff0e6 100644 --- a/phone/src/apps/dialer/components/DialPadGrid.tsx +++ b/phone/src/apps/dialer/components/DialPadGrid.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useContext } from 'react'; import { Box, Button, Grid } from '@material-ui/core'; import { makeStyles, Theme } from '@material-ui/core/styles'; import { DialInputCtx } from '../context/InputContext'; @@ -27,28 +27,26 @@ const ButtonItem = ({ label, onClick }: IBtnItem) => { }; export const DialGrid = () => { + const { add, removeOne, clear} = useContext(DialInputCtx) + return ( - - {({ add, removeOne, clear }) => ( - - - add(1)} /> - add(2)} /> - add(3)} /> - add(4)} /> - add(5)} /> - add(6)} /> - add(7)} /> - add(8)} /> - add(9)} /> - - add(0)} /> - - add('-')} /> - - - )} - + + + add(1)} /> + add(2)} /> + add(3)} /> + add(4)} /> + add(5)} /> + add(6)} /> + add(7)} /> + add(8)} /> + add(9)} /> + + add(0)} /> + + add('-')} /> + + ); }; diff --git a/phone/src/apps/dialer/components/DialerInput.tsx b/phone/src/apps/dialer/components/DialerInput.tsx index 4b45268..4fe1822 100644 --- a/phone/src/apps/dialer/components/DialerInput.tsx +++ b/phone/src/apps/dialer/components/DialerInput.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useContext } from 'react'; import { Box, IconButton, InputBase, Paper } from '@material-ui/core'; import { makeStyles, Theme } from '@material-ui/core/styles'; import PhoneIcon from '@material-ui/icons/Phone'; @@ -27,6 +27,8 @@ const useStyles = makeStyles((theme: Theme) => ({ export const DialerInput = () => { const classes = useStyles(); + const { inputVal } = useContext(DialInputCtx) + const handleCall = (number: string) => { Nui.send('phone:beginCall', { number, @@ -34,19 +36,15 @@ export const DialerInput = () => { }; return ( - - {({ inputVal, add }) => ( - - - - handleCall(inputVal)} /> - - - )} - + + + + handleCall(inputVal)} /> + + ); }; diff --git a/phone/src/modal/hooks/state.ts b/phone/src/modal/hooks/state.ts index 674eacc..ea43d96 100644 --- a/phone/src/modal/hooks/state.ts +++ b/phone/src/modal/hooks/state.ts @@ -7,7 +7,7 @@ export const callerState = { }), callModal: atom({ key: 'callingModal', - default: true + default: false }), callDuration: atom({ key: 'callDuration',