Feature/floating notifications calling and twitter (#112)

* Add floating notifications :O

* Add phone notifications and refactor calling ui

* This is unsafe

* Fix controls null check

* Remove go to alert

* Fix phone stuck after call

* Remove lazy mount for Phone

* Fix open/close cl_main

* Use effect for notification visibility

* Remove all alerts when phone closes

* Avoid re-render useNuiEvent

* It works now :c
This commit is contained in:
J Francisco Rader authored and GitHub committed 2021-02-23 13:19:10 -05:00
1 parent 4633146d40
commit f6d7a3dbe1
42 files changed
+869 -679

No files matched your search

@@ -0,0 +1,66 @@
import React from 'react';
import CallIcon from '@material-ui/icons/Call';
import CallEndIcon from '@material-ui/icons/CallEnd';
import { Fab } from '@material-ui/core';
import { useCall } from '../hooks/useCall';
import useStyles from './modal.styles';
import { useModal } from '../hooks/useModal';
export const CallControls = ({
size,
}: {
size?: 'small' | 'medium' | 'large';
}) => {
const classes = useStyles();
const { setModal } = useModal();
const { call, endCall, acceptCall, rejectCall } = useCall();
if (!call) {
return null;
}
const handleRejectCall = () => {
setModal(false);
rejectCall();
};
const handleEndCall = () => {
setModal(false);
endCall();
};
const { accepted, isTransmitter } = call;
if (accepted || isTransmitter) {
return (
<Fab
size={size}
onClick={handleEndCall}
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
className={classes.actionButton}
>
<CallEndIcon />
</Fab>
);
}
return (
<>
<Fab
size={size}
onClick={handleRejectCall}
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
className={classes.actionButton}
>
<CallEndIcon />
</Fab>
<Fab
size={size}
onClick={acceptCall}
style={{ backgroundColor: '#27ae60', color: '#fff' }}
className={classes.actionButton}
>
<CallIcon />
</Fab>
</>
);
};
@@ -0,0 +1,27 @@
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 { CallControls } from './CallControls';
import { Box } from '@material-ui/core';
export const CallModal = () => {
const classes = useStyles();
const { call } = useCall();
return (
<AppWrapper>
<AppContent>
<Box pt={16}>
<h1 style={{ textAlign: 'center' }}>{call?.transmitter}</h1>
<CallTimer isAccepted={call?.accepted} />
</Box>
<div className={classes.actions}>
<CallControls />
</div>
</AppContent>
</AppWrapper>
);
};
@@ -0,0 +1,23 @@
import React from 'react';
import { Box } from '@material-ui/core';
import { CallControls } from './CallControls';
interface ICallNotificationProps {
onAccept(): void;
onReject(): void;
}
export const CallNotification = ({
children,
}: {
children: React.ReactNode;
}) => {
return (
<div style={{ paddingBottom: '48px' }}>
<Box>{children}</Box>
<Box style={{ position: 'absolute', bottom: 0, right: 0 }}>
<CallControls size='small' />
</Box>
</div>
);
};
@@ -0,0 +1,60 @@
import React, { useEffect, useRef } from 'react';
import { useDuration } from '../hooks/useDuration';
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) return null;
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>
);
}
export default CallTimer;
@@ -0,0 +1,18 @@
import { makeStyles, Theme } from '@material-ui/core/styles';
const useStyles = makeStyles((theme: Theme) => ({
actions: {
width: '100%',
margin: 'auto',
position: 'absolute',
display: 'flex',
alignContent: 'center',
justifyContent: 'center',
bottom: '10%',
},
actionButton: {
margin: 10,
},
}));
export default useStyles;