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

+15 -16
View File
@@ -5,7 +5,7 @@ import { Route } from 'react-router-dom';
import { CallModal } from './os/call/components/CallModal';
import { HomeApp } from './apps/home/components/Home';
import { Slide } from '@material-ui/core';
import { useInitKeyboard } from './os/keyboard/hooks/useKeyboard';
import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService';
import { NotificationBar } from './os/notifications/components/NotificationBar';
import { Navigation } from './os/navigation-bar/components/Navigation';
import { useNuiService } from './os/nui-events/hooks/useNuiService';
@@ -22,27 +22,24 @@ import { useNotesService } from './apps/notes/hooks/useNotesService';
import { usePhotoService } from './apps/camera/hooks/usePhotoService';
import { useSettings } from './apps/settings/hooks/useSettings';
import { useCallService } from './os/call/hooks/useCallService';
import { useModal } from './os/call/hooks/useModal';
import { useDialService } from './apps/dialer/hooks/useDialService';
import InjectDebugData from './os/debug/InjectDebugData';
import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
import { Snackbar } from './ui/components/Snackbar';
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
import { useCallModal } from './os/call/hooks/useCallModal';
function Phone() {
const { modal } = useModal();
const { apps } = useApps();
const [settings] = useSettings();
const { bottom, visibility } = usePhoneVisibility();
useNuiService();
useKeyboardService();
usePhoneService();
useSimcardService();
useContactsService();
useTwitterService();
useInitKeyboard();
useSelloutService();
useBankService();
useMessagesService();
@@ -51,6 +48,9 @@ function Phone() {
useCallService();
useDialService();
const { modal: callModal } = useCallModal();
const { bottom, visibility } = usePhoneVisibility();
return (
<Slide direction='up' in={visibility}>
<div className='PhoneWrapper'>
@@ -79,16 +79,15 @@ function Phone() {
<>
<NotificationBar />
<div className='PhoneAppContainer'>
{modal ? (
<CallModal />
) : (
<>
<Route exact path='/' component={HomeApp} />
{apps.map((App) => (
<App.Route key={App.id} />
))}
</>
)}
<>
<Route exact path='/' component={HomeApp} />
{callModal && (
<Route exact path='/call' component={CallModal} />
)}
{apps.map((App) => (
<App.Route key={App.id} />
))}
</>
<NotificationAlert />
<Snackbar />
</div>
@@ -1,7 +1,7 @@
import React from 'react';
import { SvgIcon } from '@material-ui/core';
import { SvgIcon, SvgIconProps } from '@material-ui/core';
export const CalculatorIcon = ({ ...props }) => {
export const CalculatorIcon = ({ ...props}: SvgIconProps) => {
return (
<SvgIcon {...props}>
<svg
@@ -48,7 +48,12 @@ export const DialerHistory = ({ calls }) => {
alignItems='center'
paddingTop={35}
>
<p>You got no friends!😎</p>
<p>
You got no friends!
<span role='img' aria-label='deal with it'>
😎
</span>
</p>
</Box>
);
}
@@ -60,7 +65,6 @@ export const DialerHistory = ({ calls }) => {
<ListItem
key={call.id}
divider
onClick={() => handleCall(call.receiver)}
>
<ListItemIcon>
{<PhoneForwardedIcon className={classes.callForward} />}
@@ -74,21 +78,22 @@ export const DialerHistory = ({ calls }) => {
{<PhoneIcon />}
</IconButton>
<IconButton
onClick={() =>
history.push(
`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`
)
}
>
{<PersonAddIcon />}
</IconButton>
{getDisplayByNumber(call.transmitter) === call.transmitter ? (
<IconButton
onClick={() =>
history.push(
`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`
)
}
>
{<PersonAddIcon />}
</IconButton>
) : null}
</ListItem>
) : (
<ListItem
key={call.id}
divider
onClick={() => handleCall(call.transmitter)}
>
<ListItemIcon>
{<PhoneCallbackIcon className={classes.callBack} />}
+2 -2
View File
@@ -8,8 +8,8 @@ export const HomeApp = () => {
const { apps } = useApps();
return (
<AppWrapper>
<Box width='100%' mt={6} px={1}>
{apps && <GridMenu items={apps} />}
<Box component="div" mt={6} px={1}>
{apps && <GridMenu xs={3} items={apps} />}
</Box>
</AppWrapper>
);
@@ -188,7 +188,7 @@ InjectDebugData(
profile_name: 'ItsChip',
isMine: false,
isReported: false,
message: 'I have tweeted this because Im even more badass',
message: 'I have tweeted this because Im even more badass... And I need this to be longer so I will continue to write',
},
},
],
+1 -1
View File
@@ -44,7 +44,7 @@
"palette": {
"type": "dark",
"primary": {
"main": "#a6d4fa"
"main": "#a6d4fa"
},
"background": {
"paper": "#1c1c1c",
+1 -1
View File
@@ -20,7 +20,7 @@
"APPS_DIALER_CURRENT_CALL_TITLE": "Current Phone Call",
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
"APPS_DIALER_CURRENT_CALL_WITH": "In call with {{ transmitter }}",
"APPS_DIALER_TRANSMITTER_IS_CALLING": "You have a new call from {{ transmitter }}!",
"APPS_DIALER_TRANSMITTER_IS_CALLING": "{{ transmitter }} is calling you!",
"APPS_DIALER_ACCEPT_CALL": "Accept",
"APPS_DIALER_REJECT_CALL": "Reject",
"APPS_DIALER_END_CALL": "End",
+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,
+38 -26
View File
@@ -1,56 +1,68 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { fade, makeStyles, Theme } from '@material-ui/core/styles';
import Avatar from '@material-ui/core/Avatar';
import { green } from '@material-ui/core/colors';
import { Badge, Button } from '@material-ui/core';
import { Badge, Button, Tooltip, Zoom } from '@material-ui/core';
import { useTranslation } from 'react-i18next';
interface IStyles {
root: any;
avatar: any;
}
const useStyles = makeStyles(
(theme): IStyles => ({
const useStyles = makeStyles<Theme, { color: string; backgroundColor: string }>(
(theme) => ({
root: {
display: 'flex',
'& > *': {
margin: theme.spacing(1),
},
padding: 0,
marginTop: theme.spacing(3),
},
avatar: {
'&:hover': {
backgroundColor: ({ backgroundColor }) => fade(backgroundColor, 0.6),
},
backgroundColor: ({ backgroundColor }) => backgroundColor,
color: ({ color }) => color,
width: theme.spacing(7),
height: theme.spacing(7),
boxShadow: theme.shadows[2],
width: theme.spacing(8),
height: theme.spacing(8),
fontSize: theme.typography.h4.fontSize,
},
tooltip: {
fontSize: 12,
},
})
);
export const AppIcon = ({
id,
nameLocale,
name,
icon,
backgroundColor,
color,
notification,
}) => {
const { t } = useTranslation();
const classes = useStyles({
backgroundColor: backgroundColor || green[50],
color: color || green[400],
});
return (
<Button className={classes.root}>
<Badge
color="error"
badgeContent={notification?.badge}
invisible={!notification || notification.badge < 2}
>
<Avatar className={classes.avatar}>
{icon || name[0].toUpperCase()}
</Avatar>
</Badge>
</Button>
<Tooltip
arrow
key={id}
title={t(nameLocale)}
placement='top'
classes={{ tooltip: classes.tooltip }}
TransitionComponent={Zoom}
>
<Button className={classes.root}>
<Badge
color='error'
badgeContent={notification?.badge}
invisible={!notification || notification.badge < 2}
>
<Avatar className={classes.avatar}>
{icon || name[0].toUpperCase()}
</Avatar>
</Badge>
</Button>
</Tooltip>
);
};
+23 -44
View File
@@ -1,53 +1,32 @@
import React from 'react';
import { AppIcon } from './AppIcon';
import { useTranslation } from 'react-i18next';
import { Grid, makeStyles, Tooltip, Zoom } from '@material-ui/core';
import { Box, Grid } from '@material-ui/core';
import { Link } from 'react-router-dom';
const useStyles = makeStyles((theme) => ({
root: {
marginTop: theme.spacing(3),
},
item: {
marginTop: theme.spacing(3),
width: '20%',
},
tooltip: {
fontSize: 12,
},
}));
export const GridMenu = ({ items, Component = AppIcon }) => {
const classes = useStyles();
const { t } = useTranslation();
// TODO: Fix tooltip position to be closer to app icon
export const GridMenu = ({
items,
Component = AppIcon,
xs = undefined,
}) => {
return (
<Grid container justify='center'>
<Grid container item>
{items &&
items.length &&
items.map((item) => (
<Tooltip
arrow
key={item.id}
title={t(item.nameLocale)}
placement='top'
classes={{ tooltip: classes.tooltip }}
TransitionComponent={Zoom}
>
<Grid
key={item.id}
item
className={classes.item}
component={Link}
to={item.path}
>
<Grid container alignItems='center' direction='row'>
{items &&
items.length &&
items.map((item) => (
<Grid
item
xs={xs}
key={item.id}
alignItems='center'
justify='center'
>
<Box textAlign='center'>
<Link to={item.path}>
<Component {...item} />
</Grid>
</Tooltip>
))}
</Grid>
</Link>
</Box>
</Grid>
))}
</Grid>
);
};
@@ -0,0 +1,60 @@
import {
fade,
IconButton,
IconButtonProps,
makeStyles,
} from '@material-ui/core';
import React from 'react';
type StatusButtonStyleColor = 'success' | 'error' | 'warning' | 'info';
interface IStatusButtonStyleProps {
color: StatusButtonStyleColor;
}
const useStyles = makeStyles(
(theme) => ({
root: {
color: ({ color }: IStatusButtonStyleProps) =>
theme.palette[color].contrastText,
backgroundColor: ({ color }: IStatusButtonStyleProps) =>
theme.palette[color].main,
'&:hover': {
backgroundColor: ({ color }: IStatusButtonStyleProps) =>
theme.palette[color].light,
},
},
outlined: {
border: ({ color }: IStatusButtonStyleProps) =>
`1px solid ${fade(theme.palette[color].main, 0.5)}`,
'&:hover': {
border: ({ color }: IStatusButtonStyleProps) =>
`1px solid ${theme.palette[color].main}`,
},
'&$disabled': {
border: `1px solid ${theme.palette.action.disabled}`,
},
},
contained: {
color: ({ color }: IStatusButtonStyleProps) =>
theme.palette[color].contrastText,
backgroundColor: ({ color }: IStatusButtonStyleProps) =>
theme.palette[color].main,
'&:hover': {
backgroundColor: ({ color }: IStatusButtonStyleProps) =>
theme.palette[color].dark,
},
},
}),
{ name: 'MuiIconButton' }
);
export const StatusIconButton = ({
color = 'info',
size,
className,
...props
}: Omit<IconButtonProps, 'color'> & { color: StatusButtonStyleColor }) => {
const classes = useStyles({ color });
return <IconButton className={`${classes.root} ${className}`} size={size} {...props} />;
};