From 8ca8b1b5feda5e54d662bcf81a7a546e3e8a5f42 Mon Sep 17 00:00:00 2001 From: Taso Date: Sat, 3 Apr 2021 18:02:47 -0400 Subject: [PATCH] tweak(phone/call-modal): Tweaked appearance of call modal (#178) Correct actions will now display if calling another player. Also added ringing flavor text when the person calling is the transmitter. --- .../apps/contacts/components/ContactsApp.tsx | 3 +- phone/src/apps/contacts/hooks/useContacts.ts | 13 +++- .../apps/settings/utils/getBackgroundPath.ts | 3 + phone/src/locale/en.json | 7 ++ .../call/components/CallContactContainer.tsx | 48 +++++++++++++ phone/src/os/call/components/CallControls.tsx | 69 +++++++++++-------- phone/src/os/call/components/CallModal.tsx | 44 ++++++++---- .../os/call/components/CallNotification.tsx | 2 +- phone/src/os/call/components/CallTimer.tsx | 66 ++++-------------- phone/src/os/call/components/RingingText.tsx | 26 +++++++ phone/src/os/call/hooks/useCallService.tsx | 41 +++++------ phone/src/os/call/hooks/useDuration.ts | 11 --- phone/src/os/call/hooks/useTimer.ts | 45 ++++++++++++ phone/src/ui/components/AppContent.tsx | 4 +- phone/src/ui/interface/InterfaceUI.ts | 2 +- 15 files changed, 248 insertions(+), 136 deletions(-) create mode 100644 phone/src/apps/settings/utils/getBackgroundPath.ts create mode 100644 phone/src/os/call/components/CallContactContainer.tsx create mode 100644 phone/src/os/call/components/RingingText.tsx delete mode 100644 phone/src/os/call/hooks/useDuration.ts create mode 100644 phone/src/os/call/hooks/useTimer.ts diff --git a/phone/src/apps/contacts/components/ContactsApp.tsx b/phone/src/apps/contacts/components/ContactsApp.tsx index e1373f5..bc4f685 100644 --- a/phone/src/apps/contacts/components/ContactsApp.tsx +++ b/phone/src/apps/contacts/components/ContactsApp.tsx @@ -46,7 +46,8 @@ InjectDebugData([ { id: 3, display: 'Chip', - number: '111-1111', + number: '603-275-8373', + avatar: 'http://i.tasoagc.dev/2QYV', }, { id: 4, diff --git a/phone/src/apps/contacts/hooks/useContacts.ts b/phone/src/apps/contacts/hooks/useContacts.ts index b0ded22..e1381a6 100644 --- a/phone/src/apps/contacts/hooks/useContacts.ts +++ b/phone/src/apps/contacts/hooks/useContacts.ts @@ -9,10 +9,11 @@ interface IUseContacts { getDisplayByNumber: (number: string) => string; getContactByNumber: (number: string) => Contact | null; getContact: (id: number) => Contact | null; + getPictureByNumber: (number: string) => string | null; } export const useContacts = (): IUseContacts => { - const contacts = useRecoilValue(contactsState.contacts); + const contacts = useRecoilValue(contactsState.contacts); const getDisplayByNumber = useCallback( (number: string) => { @@ -22,6 +23,14 @@ export const useContacts = (): IUseContacts => { [contacts], ); + const getPictureByNumber = useCallback( + (number: string) => { + const found = contacts.find((contact) => contact.number === number); + return found ? found.avatar : null; + }, + [contacts], + ); + const getContactByNumber = useCallback( (number: string): Contact | null => { for (const contact of contacts) { @@ -42,5 +51,5 @@ export const useContacts = (): IUseContacts => { [contacts], ); - return { contacts, getDisplayByNumber, getContact, getContactByNumber }; + return { contacts, getDisplayByNumber, getContact, getContactByNumber, getPictureByNumber }; }; diff --git a/phone/src/apps/settings/utils/getBackgroundPath.ts b/phone/src/apps/settings/utils/getBackgroundPath.ts new file mode 100644 index 0000000..4603bc2 --- /dev/null +++ b/phone/src/apps/settings/utils/getBackgroundPath.ts @@ -0,0 +1,3 @@ +const getBackgroundPath = (bg: string) => `media/backgrounds/${bg}`; + +export default getBackgroundPath; diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index d08a9dd..17c4850 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -2,6 +2,13 @@ "translation": { "DATE_FORMAT": "MM/DD/YYYY", "DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A", + "CALLS": { + "MESSAGES": { + "RINGING": "Ringing", + "OUTGOING": "Outgoing call", + "INCOMING": "Incoming call" + } + }, "SETTINGS": { "CATEGORY": { "APPEARANCE": "Appearance", diff --git a/phone/src/os/call/components/CallContactContainer.tsx b/phone/src/os/call/components/CallContactContainer.tsx new file mode 100644 index 0000000..e2cd528 --- /dev/null +++ b/phone/src/os/call/components/CallContactContainer.tsx @@ -0,0 +1,48 @@ +import React from 'react'; +import { Avatar, Box, Typography } from '@material-ui/core'; +import { makeStyles } from '@material-ui/core/styles'; +import { useContacts } from '../../../apps/contacts/hooks/useContacts'; +import { useCall } from '../hooks/useCall'; +import { useTranslation } from 'react-i18next'; + +const useStyles = makeStyles({ + image: { + width: 80, + height: 80, + }, +}); + +const CallContactContainer = () => { + const { t } = useTranslation(); + const { call } = useCall(); + const classes = useStyles(); + + const { getDisplayByNumber, getPictureByNumber } = useContacts(); + + const getDisplayOrNumber = () => + call.isTransmitter ? getDisplayByNumber(call?.receiver) : getDisplayByNumber(call?.transmitter); + + return ( + + + + {call.isTransmitter + ? t('CALLS.MESSAGES.OUTGOING').toUpperCase() + : t('CALLS.MESSAGES.INCOMING').toUpperCase()} + + {getDisplayOrNumber()} + + + + ); +}; + +export default CallContactContainer; diff --git a/phone/src/os/call/components/CallControls.tsx b/phone/src/os/call/components/CallControls.tsx index 16468ae..fe7ae23 100644 --- a/phone/src/os/call/components/CallControls.tsx +++ b/phone/src/os/call/components/CallControls.tsx @@ -10,24 +10,24 @@ import { useHistory } from 'react-router-dom'; const useStyles = makeStyles((theme) => ({ icon: { color: theme.palette.secondary.contrastText, + boxShadow: '0 .5rem 3rem -.25em rgba(0,0,0,.3)', + }, + iconWrapper: { + height: 60, + width: 60, + }, + smallIconWrapper: { + height: 40, + width: 40, }, })); -const SIZES_SPACING = { - small: 1, - medium: 3, -}; - -export const CallControls = ({ size }: { size?: 'small' | 'medium' }) => { +export const CallControls = ({ isSmall }: { isSmall?: boolean }) => { const classes = useStyles(); const history = useHistory(); const { setModal } = useCallModal(); const { call, endCall, acceptCall, rejectCall } = useCall(); - if (!call) { - return null; - } - const handleAcceptCall = (e) => { e.stopPropagation(); history.push('/call'); @@ -46,27 +46,40 @@ export const CallControls = ({ size }: { size?: 'small' | 'medium' }) => { endCall(); }; - const { accepted, isTransmitter } = call; - - if (accepted || isTransmitter) { + // We display only the hang up if the call is accepted + // or we are the one calling + if (call.accepted || call.isTransmitter) return ( - - - - ); - } - return ( - <> - - + + - - - - - - + ); + + return ( + + + + + + + + ); }; diff --git a/phone/src/os/call/components/CallModal.tsx b/phone/src/os/call/components/CallModal.tsx index 9cb6035..6889d99 100644 --- a/phone/src/os/call/components/CallModal.tsx +++ b/phone/src/os/call/components/CallModal.tsx @@ -2,29 +2,45 @@ import React from 'react'; import { AppWrapper } from '../../../ui/components/AppWrapper'; import { AppContent } from '../../../ui/components/AppContent'; import { useCall } from '../hooks/useCall'; -import useStyles from './modal.styles'; -import CallTimer from './CallTimer'; +import { CallTimer } from './CallTimer'; import { CallControls } from './CallControls'; import { Box } from '@material-ui/core'; -import { useSimcard } from '../../simcard/hooks/useSimcard'; +import { useSettings } from '../../../apps/settings/hooks/useSettings'; +import getBackgroundPath from '../../../apps/settings/utils/getBackgroundPath'; +import CallContactContainer from './CallContactContainer'; +import { makeStyles } from '@material-ui/core/styles'; +import RingingText from './RingingText'; + +const useStyles = makeStyles({ + root: { + height: '100%', + backdropFilter: 'blur(20px) brightness(0.6)', + display: 'flex', + flexDirection: 'column', + justifyContent: 'space-between', + }, +}); export const CallModal = () => { - const classes = useStyles(); + const [settings] = useSettings(); const { call } = useCall(); - const { number: myNumber } = useSimcard(); + + const classes = useStyles(); return ( - - -

- {myNumber === call?.transmitter ? call?.receiver : call?.transmitter} -

- + + + + + {call.accepted ? : call.isTransmitter && } + + -
- -
); diff --git a/phone/src/os/call/components/CallNotification.tsx b/phone/src/os/call/components/CallNotification.tsx index eac42c6..685ab45 100644 --- a/phone/src/os/call/components/CallNotification.tsx +++ b/phone/src/os/call/components/CallNotification.tsx @@ -24,7 +24,7 @@ export const CallNotification = ({ children }: { children: React.ReactNode }) =>
{children} - +
); diff --git a/phone/src/os/call/components/CallTimer.tsx b/phone/src/os/call/components/CallTimer.tsx index 20c39ce..787143e 100644 --- a/phone/src/os/call/components/CallTimer.tsx +++ b/phone/src/os/call/components/CallTimer.tsx @@ -1,58 +1,16 @@ -import React, { useEffect, useRef } from 'react'; -import { useDuration } from '../hooks/useDuration'; +import React from 'react'; +import { Box, Typography } from '@material-ui/core'; +import useTimer from '../hooks/useTimer'; -const runTimer = (updatedTime, setDuration) => { - let newTime = { ...updatedTime.current }; - if (newTime.m >= 60) { - newTime = { ...newTime, h: newTime.h + 1, m: 0 }; - } - if (newTime.s >= 60) { - newTime = { ...newTime, m: newTime.m + 1, s: 0 }; - } - if (newTime.ms >= 100) { - newTime = { ...newTime, s: newTime.s + 1, ms: 0 }; - } - - newTime = { ...newTime, ms: newTime.ms + 1 }; - updatedTime.current = newTime; - setDuration(newTime); -}; - -function CallTimer({ isAccepted }) { - const { duration, setDuration } = useDuration(); - const updatedTime = useRef({ ms: 0, s: 0, m: 0, h: 0 }); - const timer = useRef(null); - - useEffect(() => { - if (isAccepted) { - runTimer(updatedTime, setDuration); - timer.current = setInterval(() => { - runTimer(updatedTime, setDuration); - }, 10); - } else { - clearInterval(timer.current); - timer.current = null; - } - return () => clearInterval(timer.current); - }, [isAccepted, setDuration]); - - if (!duration || !isAccepted) return null; +const formatTime = (time: number) => (time < 10 ? `0${time}` : time); +export const CallTimer = () => { + const { seconds, hours, minutes } = useTimer(); return ( -
- {duration.h >= 10 ? duration.h : '0' + duration.h} -  :  - {duration.m >= 10 ? duration.m : '0' + duration.m} -  :  - {duration.s >= 10 ? duration.s : '0' + duration.s}  -
+ + + {`${formatTime(hours)}:${formatTime(minutes)}:${formatTime(seconds)}`} + + ); -} - -export default CallTimer; +}; diff --git a/phone/src/os/call/components/RingingText.tsx b/phone/src/os/call/components/RingingText.tsx new file mode 100644 index 0000000..ed6046b --- /dev/null +++ b/phone/src/os/call/components/RingingText.tsx @@ -0,0 +1,26 @@ +import React, { useState, useEffect } from 'react'; +import { Typography } from '@material-ui/core'; +import { useTranslation } from 'react-i18next'; + +const RingingText = () => { + const { t } = useTranslation(); + const [text, setText] = useState(t('CALLS.MESSAGES.RINGING')); + const [step, setStep] = useState(0); + + useEffect(() => { + const id = setInterval(() => { + if (step < 3) { + setStep(step + 1); + setText(text + '.'); + } else { + setText(t('CALLS.MESSSAGES.RINGING')); + setStep(0); + } + }, 500); + return () => clearInterval(id); + }, [step, text, t]); + + return {text}; +}; + +export default RingingText; diff --git a/phone/src/os/call/hooks/useCallService.tsx b/phone/src/os/call/hooks/useCallService.tsx index 3f307e8..0611d98 100644 --- a/phone/src/os/call/hooks/useCallService.tsx +++ b/phone/src/os/call/hooks/useCallService.tsx @@ -3,31 +3,30 @@ import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent'; import { useSetRecoilState } from 'recoil'; import { useCall } from './useCall'; import { CallEvents, CallProps } from '../../../../../typings/call'; -import InjectDebugData from '../../debug/InjectDebugData'; +// import InjectDebugData from '../../debug/InjectDebugData'; import { useCallModal } from './useCallModal'; import { useHistory, useLocation } from 'react-router-dom'; import { callerState } from './state'; import { useCallNotifications } from './useCallNotifications'; -import { useDuration } from './useDuration'; -InjectDebugData([ - /* { - app: 'CALL', - method: 'setCaller', - data: { - accepted: true, - isTransmitter: false, - transmitter: 'Chip', - receiver: 'Taso', - active: true, - }, - }, - { - app: 'CALL', - method: 'callModal', - data: true, - }, */ -]); +// InjectDebugData([ +// { +// app: 'CALL', +// method: CallEvents.SET_CALLER, +// data: { +// accepted: true, +// isTransmitter: false, +// transmitter: '603-275-8373', +// receiver: '603-275-4747', +// active: true, +// }, +// }, +// { +// app: 'CALL', +// method: CallEvents.SET_CALL_MODAL, +// data: true, +// }, +// ]); export const useCallService = () => { const { modal } = useCallModal(); @@ -35,7 +34,6 @@ export const useCallService = () => { const { pathname } = useLocation(); const { call, setCall } = useCall(); - const { resetDuration } = useDuration(); const { setNotification } = useCallNotifications(); @@ -57,7 +55,6 @@ export const useCallService = () => { }, [history, modal, pathname, modalHasBeenOpenedThisCall]); const _setCall = (_call: CallProps) => { - resetDuration(); setCall(_call); setNotification(_call); }; diff --git a/phone/src/os/call/hooks/useDuration.ts b/phone/src/os/call/hooks/useDuration.ts deleted file mode 100644 index 706143e..0000000 --- a/phone/src/os/call/hooks/useDuration.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useCallback } from 'react'; -import { useRecoilState } from 'recoil'; -import { callerState } from './state'; - -export const useDuration = () => { - const [duration, setDuration] = useRecoilState(callerState.callDuration); - - const resetDuration = useCallback(() => setDuration({ ms: 0, s: 0, m: 0, h: 0 }), [setDuration]); - - return { duration, setDuration, resetDuration }; -}; diff --git a/phone/src/os/call/hooks/useTimer.ts b/phone/src/os/call/hooks/useTimer.ts new file mode 100644 index 0000000..706dbc3 --- /dev/null +++ b/phone/src/os/call/hooks/useTimer.ts @@ -0,0 +1,45 @@ +import { useEffect, useRef, useState } from 'react'; + +const getTimeFromSeconds = (secs: number) => { + const totalSeconds = Math.ceil(secs); + const hours = Math.floor((totalSeconds % (60 * 60 * 24)) / (60 * 60)); + const minutes = Math.floor((totalSeconds % (60 * 60)) / 60); + const seconds = Math.floor(totalSeconds % 60); + + return { + seconds, + minutes, + hours, + }; +}; + +const useTimer = () => { + const intervalRef = useRef(); + const [seconds, setSeconds] = useState(0); + + const clearIntervalRef = () => { + if (intervalRef.current) { + clearInterval(intervalRef.current); + intervalRef.current = undefined; + } + }; + + const startTimer = () => { + if (!intervalRef.current) { + intervalRef.current = setInterval(() => setSeconds((prevSeconds) => prevSeconds + 1), 1000); + } + }; + + const resetTimer = () => { + clearIntervalRef(); + }; + + useEffect(() => { + startTimer(); + return clearIntervalRef; + }, []); + + return { ...getTimeFromSeconds(seconds), startTimer, resetTimer }; +}; + +export default useTimer; diff --git a/phone/src/ui/components/AppContent.tsx b/phone/src/ui/components/AppContent.tsx index 268fb75..e8b1c16 100644 --- a/phone/src/ui/components/AppContent.tsx +++ b/phone/src/ui/components/AppContent.tsx @@ -23,7 +23,7 @@ const useStyles = makeStyles(() => ({ export const AppContent = ({ children, - style, + paperStyle, backdrop, onClickBackdrop, ...props @@ -38,7 +38,7 @@ export const AppContent = ({ > - + {children} diff --git a/phone/src/ui/interface/InterfaceUI.ts b/phone/src/ui/interface/InterfaceUI.ts index eb5f670..878b912 100644 --- a/phone/src/ui/interface/InterfaceUI.ts +++ b/phone/src/ui/interface/InterfaceUI.ts @@ -2,7 +2,7 @@ import { CSSProperties } from 'react'; export interface AppContentTypes { children?: JSX.Element | JSX.Element[]; - style?: CSSProperties; + paperStyle?: CSSProperties; backdrop?: boolean; onClickBackdrop?: (...args: any[]) => void; }