This commit is contained in:
Christopher committed 2021-04-04 02:44:39 +02:00
commit fed7b2c13a
15 files changed
+248 -136

No files matched your search

@@ -46,7 +46,8 @@ InjectDebugData([
{
id: 3,
display: 'Chip',
number: '111-1111',
number: '603-275-8373',
avatar: 'http://i.tasoagc.dev/2QYV',
},
{
id: 4,
+11 -2
View File
@@ -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<Contact[]>(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 };
};
@@ -0,0 +1,3 @@
const getBackgroundPath = (bg: string) => `media/backgrounds/${bg}`;
export default getBackgroundPath;
+7
View File
@@ -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",
@@ -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 (
<Box display="flex" alignItems="center">
<Box style={{ flexGrow: 1 }}>
<Typography variant="body1">
{call.isTransmitter
? t('CALLS.MESSAGES.OUTGOING').toUpperCase()
: t('CALLS.MESSAGES.INCOMING').toUpperCase()}
</Typography>
<Typography variant="h4">{getDisplayOrNumber()}</Typography>
</Box>
<Avatar
className={classes.image}
alt={getDisplayOrNumber()}
src={
call.isTransmitter
? getPictureByNumber(call.receiver)
: getPictureByNumber(call?.transmitter)
}
/>
</Box>
);
};
export default CallContactContainer;
+41 -28
View File
@@ -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 (
<StatusIconButton color="error" size={size} onClick={handleEndCall}>
<CallEndIcon />
</StatusIconButton>
);
}
return (
<>
<Box m={SIZES_SPACING[size] || 1} display="inline">
<StatusIconButton color="error" size={size} onClick={handleRejectCall}>
<Box display="flex" justifyContent="center" px={2} my={2}>
<StatusIconButton
color="error"
size={isSmall ? 'small' : 'medium'}
onClick={handleEndCall}
className={isSmall ? classes.smallIconWrapper : classes.iconWrapper}
>
<CallEndIcon className={classes.icon} />
</StatusIconButton>
</Box>
<Box m={SIZES_SPACING[size] || 1} display="inline">
<StatusIconButton color="success" size={size} onClick={handleAcceptCall}>
<CallIcon className={classes.icon} />
</StatusIconButton>
</Box>
</>
);
return (
<Box display="flex" alignItems="center" justifyContent="space-between" px={2} my={2}>
<StatusIconButton
color="error"
size={isSmall ? 'small' : 'medium'}
onClick={handleRejectCall}
className={isSmall ? classes.smallIconWrapper : classes.iconWrapper}
>
<CallEndIcon className={classes.icon} />
</StatusIconButton>
<StatusIconButton
color="success"
size={isSmall ? 'small' : 'medium'}
onClick={handleAcceptCall}
className={isSmall ? classes.smallIconWrapper : classes.iconWrapper}
>
<CallIcon className={classes.icon} />
</StatusIconButton>
</Box>
);
};
+30 -14
View File
@@ -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 (
<AppWrapper>
<AppContent>
<Box pt={24}>
<h1 style={{ textAlign: 'center' }}>
{myNumber === call?.transmitter ? call?.receiver : call?.transmitter}
</h1>
<CallTimer isAccepted={call?.accepted} />
<AppContent
paperStyle={{
backgroundImage: `url(${getBackgroundPath(settings.wallpaper.value)})`,
}}
>
<Box className={classes.root} padding={5}>
<Box>
<CallContactContainer />
{call.accepted ? <CallTimer /> : call.isTransmitter && <RingingText />}
</Box>
<CallControls />
</Box>
<div className={classes.actions}>
<CallControls size="medium" />
</div>
</AppContent>
</AppWrapper>
);
@@ -24,7 +24,7 @@ export const CallNotification = ({ children }: { children: React.ReactNode }) =>
<div className={classes.root}>
<Box>{children}</Box>
<Box className={classes.controls}>
<CallControls size="small" />
<CallControls isSmall />
</Box>
</div>
);
+12 -54
View File
@@ -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 (
<div
style={{
textAlign: 'center',
marginTop: '2em',
fontSize: 30,
}}
>
<span>{duration.h >= 10 ? duration.h : '0' + duration.h}</span>
&nbsp;:&nbsp;
<span>{duration.m >= 10 ? duration.m : '0' + duration.m}</span>
&nbsp;:&nbsp;
<span>{duration.s >= 10 ? duration.s : '0' + duration.s}</span>&nbsp;
</div>
<Box>
<Typography variant="body1">
{`${formatTime(hours)}:${formatTime(minutes)}:${formatTime(seconds)}`}
</Typography>
</Box>
);
}
export default CallTimer;
};
@@ -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<string>(t('CALLS.MESSAGES.RINGING'));
const [step, setStep] = useState<number>(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 <Typography>{text}</Typography>;
};
export default RingingText;
+19 -22
View File
@@ -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<CallProps | boolean>([
/* {
app: 'CALL',
method: 'setCaller',
data: {
accepted: true,
isTransmitter: false,
transmitter: 'Chip',
receiver: 'Taso',
active: true,
},
},
{
app: 'CALL',
method: 'callModal',
data: true,
}, */
]);
// InjectDebugData<CallProps | boolean>([
// {
// 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);
};
-11
View File
@@ -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 };
};
+45
View File
@@ -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<NodeJS.Timer>();
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;
+2 -2
View File
@@ -23,7 +23,7 @@ const useStyles = makeStyles(() => ({
export const AppContent = ({
children,
style,
paperStyle,
backdrop,
onClickBackdrop,
...props
@@ -38,7 +38,7 @@ export const AppContent = ({
>
<Backdrop className={classes.backdrop} open={backdrop || false} onClick={onClickBackdrop} />
<Box flexGrow={1} className={classes.box} {...props}>
<Paper square elevation={0} className={classes.paper}>
<Paper square elevation={0} className={classes.paper} style={paperStyle}>
{children}
</Paper>
</Box>
+1 -1
View File
@@ -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;
}