Notification alert stays on if it is an incoming call and phone is closed (#115)

* Phone now shows all the time slide a bit if incoming call exists | can close alerts!

* Improve animation

* Improve call controls

* Make alerts not overflow | Call modal is navigable out :)

* Open modal when accepting call

* Cant navigate back from homepage

* Avoid call route if no call active + rename things

* Impprove main apps icons sizes

* hover effect to app icons :)

* Revert interface change

* fix(phone/dialer): resolve not calling when adding contacts

Co-authored-by: Christopher <[email protected]>
This commit is contained in:
J Francisco RaderandChristopher authored and GitHub committed 2021-02-26 21:45:01 -05:00
1 parent d2461bab16
commit 41674968ab
24 files changed
+396 -206

No files matched your search

+7 -7
View File
@@ -60,7 +60,7 @@ export const APPS: IAppConfig[] = [
{
id: 'DIALER',
nameLocale: 'APPS_DIALER',
icon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
icon: <FontAwesomeIcon icon={faPhoneAlt} />,
notificationIcon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
backgroundColor: DIALER_APP_PRIMARY_COLOR,
color: DIALER_APP_TEXT_COLOR,
@@ -70,7 +70,7 @@ export const APPS: IAppConfig[] = [
{
id: 'MESSAGES',
nameLocale: 'APPS_MESSAGES',
icon: <MessageIcon fontSize='default' />,
icon: <MessageIcon fontSize="large" />,
notificationIcon: <MessageIcon fontSize='small' />,
backgroundColor: MESSAGES_APP_PRIMARY_COLOR,
color: MESSAGES_APP_TEXT_COLOR,
@@ -82,7 +82,7 @@ export const APPS: IAppConfig[] = [
{
id: 'CONTACTS',
nameLocale: 'APPS_CONTACTS',
icon: <ContactsIcon />,
icon: <ContactsIcon fontSize="large" />,
notificationIcon: <ContactsIcon fontSize='small' />,
backgroundColor: CONTACTS_APP_PRIMARY_COLOR,
color: CONTACTS_APP_TEXT_COLOR,
@@ -94,7 +94,7 @@ export const APPS: IAppConfig[] = [
{
id: 'CALCULATOR',
nameLocale: 'APPS_CALCULATOR',
icon: <CalculatorIcon />,
icon: <CalculatorIcon fontSize="large" />,
notificationIcon: <CalculatorIcon fontSize='small' />,
backgroundColor: purple[500],
color: grey[50],
@@ -106,7 +106,7 @@ export const APPS: IAppConfig[] = [
{
id: 'SETTINGS',
nameLocale: 'APPS_SETTINGS',
icon: <SettingsIcon />,
icon: <SettingsIcon fontSize="large" />,
notificationIcon: <SettingsIcon fontSize='small' />,
backgroundColor: '#383838',
color: grey[50],
@@ -118,7 +118,7 @@ export const APPS: IAppConfig[] = [
{
id: 'BANK',
nameLocale: 'APPS_BANK',
icon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
icon: <FontAwesomeIcon icon={faWonSign} />,
notificationIcon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
backgroundColor: blue[900],
color: common.white,
@@ -128,7 +128,7 @@ export const APPS: IAppConfig[] = [
{
id: 'TWITTER',
nameLocale: 'APPS_TWITTER',
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth />,
notificationIcon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
backgroundColor: blue[600],
color: common.white,
+44 -34
View File
@@ -1,30 +1,47 @@
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';
import { useCallModal } from '../hooks/useCallModal';
import { StatusIconButton } from '../../../ui/components/StatusIconButton';
import { Box, makeStyles } from '@material-ui/core';
import { useHistory } from 'react-router-dom';
export const CallControls = ({
size,
}: {
size?: 'small' | 'medium' | 'large';
}) => {
const useStyles = makeStyles((theme) => ({
icon: {
color: theme.palette.secondary.contrastText,
},
}));
const SIZES_SPACING = {
small: 1,
medium: 3,
};
export const CallControls = ({ size }: { size?: 'small' | 'medium' }) => {
const classes = useStyles();
const { setModal } = useModal();
const history = useHistory();
const { setModal } = useCallModal();
const { call, endCall, acceptCall, rejectCall } = useCall();
if (!call) {
return null;
}
const handleRejectCall = () => {
const handleAcceptCall = (e) => {
e.stopPropagation();
history.push('/call');
acceptCall();
};
const handleRejectCall = (e) => {
e.stopPropagation();
setModal(false);
rejectCall();
};
const handleEndCall = () => {
const handleEndCall = (e) => {
e.stopPropagation();
setModal(false);
endCall();
};
@@ -33,34 +50,27 @@ export const CallControls = ({
if (accepted || isTransmitter) {
return (
<Fab
size={size}
onClick={handleEndCall}
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
className={classes.actionButton}
>
<StatusIconButton color='error' size={size} onClick={handleEndCall}>
<CallEndIcon />
</Fab>
</StatusIconButton>
);
}
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>
<Box m={SIZES_SPACING[size] || 1} display='inline'>
<StatusIconButton color='error' size={size} onClick={handleRejectCall}>
<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>
</>
);
};
+2 -2
View File
@@ -14,12 +14,12 @@ export const CallModal = () => {
return (
<AppWrapper>
<AppContent>
<Box pt={16}>
<Box pt={24}>
<h1 style={{ textAlign: 'center' }}>{call?.transmitter}</h1>
<CallTimer isAccepted={call?.accepted} />
</Box>
<div className={classes.actions}>
<CallControls />
<CallControls size="medium" />
</div>
</AppContent>
</AppWrapper>
@@ -1,5 +1,5 @@
import React from 'react';
import { Box } from '@material-ui/core';
import { Box, makeStyles } from '@material-ui/core';
import { CallControls } from './CallControls';
interface ICallNotificationProps {
@@ -7,15 +7,27 @@ interface ICallNotificationProps {
onReject(): void;
}
const useStyles = makeStyles((theme) => ({
root: {
paddingBottom: '48px',
},
controls: {
position: 'absolute',
bottom: theme.spacing(1),
right: '4px',
},
}));
export const CallNotification = ({
children,
}: {
children: React.ReactNode;
}) => {
const classes = useStyles();
return (
<div style={{ paddingBottom: '48px' }}>
<div className={classes.root}>
<Box>{children}</Box>
<Box style={{ position: 'absolute', bottom: 0, right: 0 }}>
<Box className={classes.controls}>
<CallControls size='small' />
</Box>
</div>
@@ -6,7 +6,7 @@ interface ModalProps {
setModal: (show: boolean) => void;
}
export const useModal = (): ModalProps => {
export const useCallModal = (): ModalProps => {
const [modal, setModal] = useRecoilState(callerState.callModal);
return { modal, setModal }
}
+31 -4
View File
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
import { useSetRecoilState } from 'recoil';
import { callerState } from './state';
@@ -9,10 +9,12 @@ import { useCall } from './useCall';
import { CallProps } from '../../../common/typings/call';
import { useApp } from '../../apps/hooks/useApps';
import InjectDebugData from '../../debug/InjectDebugData';
import { useCallModal } from './useCallModal';
import { useHistory, useLocation } from 'react-router-dom';
const NOTIFICATION_ID = 'call:current';
InjectDebugData<CallProps>([
/* InjectDebugData<CallProps | boolean>([
{
app: 'CALL',
method: 'setCaller',
@@ -20,14 +22,22 @@ InjectDebugData<CallProps>([
accepted: false,
isTransmitter: false,
transmitter: 'Chip',
receiver: 'Taso',
receiver: 'Taso',
active: true,
},
},
]);
{
app: 'CALL',
method: 'callModal',
data: true,
},
]); */
export const useCallService = () => {
const { t } = useTranslation();
const { modal } = useCallModal();
const history = useHistory();
const { pathname } = useLocation();
const {
addNotificationAlert,
removeId,
@@ -40,14 +50,30 @@ export const useCallService = () => {
const setModal = useSetRecoilState(callerState.callModal);
const [modalHasBeenOpenedThisCall, setModalOpened] = useState<boolean>(false);
const callNotificationBase = {
app: 'CALL',
id: NOTIFICATION_ID,
cantClose: true,
icon,
onClick: () => history.push('/call'),
notificationIcon,
};
useEffect(() => {
setModalOpened(!!modal);
}, [modal]);
useEffect(() => {
if (!modal && pathname === '/call') {
history.replace('/');
}
if (modal && !modalHasBeenOpenedThisCall && pathname !== '/call') {
history.push('/call');
}
}, [history, modal, pathname, modalHasBeenOpenedThisCall]);
const _setCall = (_call: CallProps) => {
setCall(_call);
if (!_call || !_call.active) {
@@ -76,6 +102,7 @@ export const useCallService = () => {
title: t('APPS_DIALER_INCOMING_CALL_TITLE', {
transmitter: _call.transmitter,
}),
keepWhenPhoneClosed: true,
content: (
<CallNotification>
{t('APPS_DIALER_TRANSMITTER_IS_CALLING', {
@@ -46,7 +46,7 @@ const validKeys = [
const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
export const useInitKeyboard = () => {
export const useKeyboardService = () => {
const history = useHistory();
const { closePhone } = usePhone();
const getters = {
@@ -7,8 +7,9 @@ import {
import KeyboardArrowLeftIcon from '@material-ui/icons/KeyboardArrowLeft';
import AppsIcon from '@material-ui/icons/Apps';
import RadioButtonUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked';
import { useHistory } from 'react-router-dom';
import { useHistory, useRouteMatch } from 'react-router-dom';
import { usePhone } from '../../phone/hooks/usePhone';
import { useNotifications } from '../../notifications/hooks/useNotifications';
const useStyles = makeStyles((theme) => ({
root: {
@@ -18,14 +19,18 @@ const useStyles = makeStyles((theme) => ({
}));
export const Navigation = () => {
const { closePhone } = usePhone();
const classes = useStyles();
const history = useHistory();
const { isExact } = useRouteMatch('/');
const { closePhone } = usePhone();
const { setBarUncollapsed } = useNotifications();
return (
<BottomNavigation
className={classes.root}
onChange={(_e, value) => value()}
onChange={(_e, value) => {
setBarUncollapsed(false);
value();
}}
>
<BottomNavigationAction
label='Home'
@@ -39,7 +44,7 @@ export const Navigation = () => {
/>
<BottomNavigationAction
label='Back'
value={history.goBack}
value={() => !isExact && history.goBack()}
icon={<KeyboardArrowLeftIcon />}
/>
</BottomNavigation>
@@ -1,5 +1,6 @@
import React from 'react';
import { Box, makeStyles } from '@material-ui/core';
import CloseIcon from '@material-ui/icons/Close';
import { Box, IconButton, makeStyles, Slide } from '@material-ui/core';
import { useNotifications } from '../hooks/useNotifications';
import { Alert, AlertTitle } from '@material-ui/lab';
@@ -11,6 +12,11 @@ const useStyles = makeStyles((theme) => ({
alignItems: 'center',
},
alert: {
'& .MuiAlert-action': {
top: theme.spacing(1),
right: theme.spacing(2),
position: 'absolute',
},
position: 'relative',
cursor: 'pointer',
width: '370px',
@@ -22,6 +28,16 @@ const useStyles = makeStyles((theme) => ({
color: theme.palette.text.primary,
},
},
alertContent: {
display: '-webkit-box',
maxWidth: '360px',
height: '60px',
margin: '0 auto',
'-webkit-line-clamp': 3,
'-webkit-box-orient': 'vertical',
overflow: 'hidden',
textOverflow: 'ellipsis',
},
}));
export const NotificationAlert = () => {
@@ -30,17 +46,37 @@ export const NotificationAlert = () => {
return (
<div className={classes.snackbar}>
{currentAlert ? (
<Slide in={!!currentAlert} mountOnEnter unmountOnExit>
<Alert
onClick={() => currentAlert.onClick?.(currentAlert)}
icon={currentAlert.icon || false}
action={
<IconButton
color='primary'
size='small'
onClick={(e) => {
e.stopPropagation();
currentAlert?.onCloseAlert(e);
}}
>
<CloseIcon fontSize='small' />
</IconButton>
}
onClick={(e) => currentAlert?.onClickAlert(e)}
icon={currentAlert?.icon || false}
className={classes.alert}
elevation={6}
>
<AlertTitle>{currentAlert.title}</AlertTitle>
<Box width='100%'>{currentAlert.content}</Box>
<AlertTitle>
<Box width='282px' whiteSpace='nowrap'>
<Box overflow='hidden' component='div' textOverflow='ellipsis'>
{currentAlert?.title}
</Box>
</Box>
</AlertTitle>
<Box component='div' className={classes.alertContent}>
{currentAlert?.content}
</Box>
</Alert>
) : null}
</Slide>
</div>
);
};
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React from 'react';
import {
makeStyles,
Typography,
@@ -66,9 +66,13 @@ const useStyles = makeStyles((theme) => ({
export const NotificationBar = () => {
const classes = useStyles();
const { icons, notifications, removeNotification } = useNotifications();
const [uncollapsed, setUncollapsed] = useState<boolean>(false);
const {
icons,
notifications,
removeNotification,
barUncollapsed,
setBarUncollapsed,
} = useNotifications();
return (
<>
@@ -78,7 +82,7 @@ export const NotificationBar = () => {
justify='space-between'
wrap='nowrap'
onClick={() => {
setUncollapsed(!uncollapsed);
setBarUncollapsed((curr) => !curr);
}}
>
<Grid container item wrap='nowrap'>
@@ -115,28 +119,29 @@ export const NotificationBar = () => {
</Grid>
</Grid>
</Grid>
<Slide direction='down' in={uncollapsed}>
<Slide direction='down' in={barUncollapsed}>
<Paper square className={classes.drawer}>
<Box p={2}>
<Box py={2}>
<List>
<Divider />
{notifications.map((notification, idx) => (
<NotificationItem
key={idx}
{...notification}
onClose={(e) => {
e.stopPropagation();
notification.onClose?.(notification);
if (notifications.length === 1) {
setUncollapsed(false);
setBarUncollapsed(false);
}
removeNotification(idx);
}}
onClickClose={() => {
setUncollapsed(false);
setBarUncollapsed(false);
if (!notification.cantClose) {
removeNotification(idx);
}
}}
{...notification}
/>
))}
</List>
@@ -145,7 +150,7 @@ export const NotificationBar = () => {
<IconButton
className={classes.collapseBtn}
size='small'
onClick={() => setUncollapsed(false)}
onClick={() => setBarUncollapsed(false)}
>
<ArrowDropUpIcon />
</IconButton>
@@ -6,16 +6,18 @@ import {
ListItemAvatar,
ListItemText,
makeStyles,
Theme,
} from '@material-ui/core';
import { INotification } from '../providers/NotificationsProvider';
const useStyles = makeStyles((theme) => ({
const useStyles = makeStyles<Theme, { cantClose: boolean }>((theme) => ({
closeNotifBtn: {
position: 'absolute',
right: '8px',
top: '8px',
},
notificationItem: {
paddingRight: ({ cantClose }) => (cantClose ? '8px' : '28px'),
position: 'relative',
},
}));
@@ -29,7 +31,7 @@ export const NotificationItem = ({
onClickClose: (e: any) => void;
}) => {
const { title, icon, content, cantClose, onClick } = notification;
const classes = useStyles();
const classes = useStyles({ cantClose });
return (
<ListItem
divider
@@ -6,6 +6,8 @@ import React, {
useRef,
useEffect,
} from 'react';
import { useRecoilValue } from 'recoil';
import { phoneState } from '../../phone/hooks/state';
import { DEFAULT_ALERT_HIDE_TIME } from '../notifications.constants';
export interface INotification {
@@ -16,9 +18,17 @@ export interface INotification {
icon?: JSX.Element;
notificationIcon?: JSX.Element;
cantClose?: boolean;
keepWhenPhoneClosed?: boolean;
onClose?: (notification: INotification) => void;
onClick?: (notification: INotification) => void;
}
type INotificationAlert = INotification & {
onClickAlert(e?: any): void;
onCloseAlert(e?: any): void;
resolve(): void;
};
interface INotificationIcon {
key: string;
icon: JSX.Element;
@@ -26,8 +36,10 @@ interface INotificationIcon {
}
export const NotificationsContext = createContext<{
barUncollapsed: boolean;
setBarUncollapsed: (v: boolean | ((c: boolean) => boolean)) => void;
notifications: INotification[];
currentAlert: INotification;
currentAlert: INotificationAlert;
icons: INotificationIcon[];
count: number;
removeAlerts(): void;
@@ -45,13 +57,23 @@ export const NotificationsContext = createContext<{
}>(null);
export function NotificationsProvider({ children }) {
const isPhoneOpen = useRecoilValue(phoneState.visibility);
const [barUncollapsed, setBarUncollapsed] = useState<boolean>(false);
const [notifications, setNotifications] = useState<INotification[]>([]);
const alertTimeout = useRef<NodeJS.Timeout>();
const [alerts, setAlerts] = useState<
Array<[INotification, boolean, Partial<INotification>]>
>([]);
const [currentAlert, setCurrentAlert] = useState<INotification>();
const [currentAlert, setCurrentAlert] = useState<INotificationAlert>();
useEffect(() => {
if (isPhoneOpen && currentAlert && currentAlert.keepWhenPhoneClosed) {
currentAlert.resolve();
}
}, [isPhoneOpen, currentAlert]);
const updateNotification = useCallback(
(idx: number, value: INotification) => {
@@ -109,20 +131,28 @@ export function NotificationsProvider({ children }) {
res();
};
const onExit = (cb) => () => {
cb?.(n);
clearTimeout(alertTimeout.current);
resolve();
};
setCurrentAlert({
...n,
resolve,
onClickAlert: onExit(n.onClick),
onCloseAlert: onExit(n.onClose),
});
if (n.keepWhenPhoneClosed) {
return;
}
alertTimeout.current = setTimeout(() => {
resolve();
// If you change or remove the 300 i'll kill your pet - Kidz /s
// Really, this makes it work nicely with usePhoneVisibility :)
}, DEFAULT_ALERT_HIDE_TIME + 300);
setCurrentAlert({
...n,
onClick: () => {
clearTimeout(alertTimeout.current);
n.onClick?.(n);
resolve();
},
});
});
},
[addOrUpdateNotification]
@@ -186,6 +216,8 @@ export function NotificationsProvider({ children }) {
return (
<NotificationsContext.Provider
value={{
setBarUncollapsed,
barUncollapsed,
currentAlert,
notifications,
removeAlerts,
+6 -1
View File
@@ -1,15 +1,20 @@
import { useRecoilValue } from 'recoil';
import { IServerConfig } from '../../../common/typings/config';
import ServerConfig from '../../../config.autogen.json';
import { useNotifications } from '../../notifications/hooks/useNotifications';
import Nui from '../../nui-events/utils/Nui';
import { phoneState } from './state';
interface IUsePhone {
config?: IServerConfig;
openPhone(): void;
closePhone(): void;
isPhoneOpen: boolean;
}
export const usePhone = (): IUsePhone => {
const isPhoneOpen = useRecoilValue(phoneState.visibility);
const { removeAlerts } = useNotifications();
const closePhone = () => {
@@ -20,5 +25,5 @@ export const usePhone = (): IUsePhone => {
Nui.send('phone:open');
};
return { config: ServerConfig as any, closePhone, openPhone };
return { config: ServerConfig as any, closePhone, openPhone, isPhoneOpen };
};
+13 -12
View File
@@ -12,35 +12,36 @@ export const usePhoneVisibility = () => {
const [notifVisibility, setNotifVisibility] = useState<boolean>(false);
const [isNotificationVisibleOnly, setNotificationVisibleOnly] = useState<
boolean
>(false);
useEffect(() => {
setNotificationVisibleOnly(!!(!visibility && currentAlert));
}, [visibility, currentAlert]);
const notificationTimer = useRef<NodeJS.Timeout>();
useEffect(() => {
if (isNotificationVisibleOnly) {
if (visibility) {
setNotifVisibility(false);
}
}, [visibility]);
useEffect(() => {
if (!visibility && currentAlert) {
setNotifVisibility(true);
if (notificationTimer.current) {
clearTimeout(notificationTimer.current);
notificationTimer.current = undefined;
}
if (currentAlert?.keepWhenPhoneClosed) {
return;
}
notificationTimer.current = setTimeout(() => {
setNotifVisibility(false);
}, DEFAULT_ALERT_HIDE_TIME);
}
}, [isNotificationVisibleOnly, setVisibility]);
}, [currentAlert, visibility, setVisibility]);
const bottom = useMemo(() => {
if (isNotificationVisibleOnly) {
if (!visibility) {
return `calc(-70% * ${zoom})`;
}
return 0;
}, [isNotificationVisibleOnly, zoom]);
}, [visibility, zoom]);
return {
bottom,