mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
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:
1 parent
d2461bab16
commit
41674968ab
24 files changed
+396
-206
No files matched your search
+15
-16
@@ -5,7 +5,7 @@ import { Route } from 'react-router-dom';
|
|||||||
import { CallModal } from './os/call/components/CallModal';
|
import { CallModal } from './os/call/components/CallModal';
|
||||||
import { HomeApp } from './apps/home/components/Home';
|
import { HomeApp } from './apps/home/components/Home';
|
||||||
import { Slide } from '@material-ui/core';
|
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 { NotificationBar } from './os/notifications/components/NotificationBar';
|
||||||
import { Navigation } from './os/navigation-bar/components/Navigation';
|
import { Navigation } from './os/navigation-bar/components/Navigation';
|
||||||
import { useNuiService } from './os/nui-events/hooks/useNuiService';
|
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 { usePhotoService } from './apps/camera/hooks/usePhotoService';
|
||||||
import { useSettings } from './apps/settings/hooks/useSettings';
|
import { useSettings } from './apps/settings/hooks/useSettings';
|
||||||
import { useCallService } from './os/call/hooks/useCallService';
|
import { useCallService } from './os/call/hooks/useCallService';
|
||||||
import { useModal } from './os/call/hooks/useModal';
|
|
||||||
import { useDialService } from './apps/dialer/hooks/useDialService';
|
import { useDialService } from './apps/dialer/hooks/useDialService';
|
||||||
import InjectDebugData from './os/debug/InjectDebugData';
|
import InjectDebugData from './os/debug/InjectDebugData';
|
||||||
import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
|
import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
|
||||||
import { Snackbar } from './ui/components/Snackbar';
|
import { Snackbar } from './ui/components/Snackbar';
|
||||||
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
|
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
|
||||||
|
import { useCallModal } from './os/call/hooks/useCallModal';
|
||||||
|
|
||||||
function Phone() {
|
function Phone() {
|
||||||
const { modal } = useModal();
|
|
||||||
const { apps } = useApps();
|
const { apps } = useApps();
|
||||||
|
|
||||||
const [settings] = useSettings();
|
const [settings] = useSettings();
|
||||||
|
|
||||||
const { bottom, visibility } = usePhoneVisibility();
|
|
||||||
|
|
||||||
useNuiService();
|
useNuiService();
|
||||||
|
useKeyboardService();
|
||||||
usePhoneService();
|
usePhoneService();
|
||||||
useSimcardService();
|
useSimcardService();
|
||||||
useContactsService();
|
useContactsService();
|
||||||
useTwitterService();
|
useTwitterService();
|
||||||
useInitKeyboard();
|
|
||||||
useSelloutService();
|
useSelloutService();
|
||||||
useBankService();
|
useBankService();
|
||||||
useMessagesService();
|
useMessagesService();
|
||||||
@@ -51,6 +48,9 @@ function Phone() {
|
|||||||
useCallService();
|
useCallService();
|
||||||
useDialService();
|
useDialService();
|
||||||
|
|
||||||
|
const { modal: callModal } = useCallModal();
|
||||||
|
const { bottom, visibility } = usePhoneVisibility();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slide direction='up' in={visibility}>
|
<Slide direction='up' in={visibility}>
|
||||||
<div className='PhoneWrapper'>
|
<div className='PhoneWrapper'>
|
||||||
@@ -79,16 +79,15 @@ function Phone() {
|
|||||||
<>
|
<>
|
||||||
<NotificationBar />
|
<NotificationBar />
|
||||||
<div className='PhoneAppContainer'>
|
<div className='PhoneAppContainer'>
|
||||||
{modal ? (
|
<>
|
||||||
<CallModal />
|
<Route exact path='/' component={HomeApp} />
|
||||||
) : (
|
{callModal && (
|
||||||
<>
|
<Route exact path='/call' component={CallModal} />
|
||||||
<Route exact path='/' component={HomeApp} />
|
)}
|
||||||
{apps.map((App) => (
|
{apps.map((App) => (
|
||||||
<App.Route key={App.id} />
|
<App.Route key={App.id} />
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
|
||||||
<NotificationAlert />
|
<NotificationAlert />
|
||||||
<Snackbar />
|
<Snackbar />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
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 (
|
return (
|
||||||
<SvgIcon {...props}>
|
<SvgIcon {...props}>
|
||||||
<svg
|
<svg
|
||||||
|
|||||||
@@ -48,7 +48,12 @@ export const DialerHistory = ({ calls }) => {
|
|||||||
alignItems='center'
|
alignItems='center'
|
||||||
paddingTop={35}
|
paddingTop={35}
|
||||||
>
|
>
|
||||||
<p>You got no friends!😎</p>
|
<p>
|
||||||
|
You got no friends!
|
||||||
|
<span role='img' aria-label='deal with it'>
|
||||||
|
😎
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -60,7 +65,6 @@ export const DialerHistory = ({ calls }) => {
|
|||||||
<ListItem
|
<ListItem
|
||||||
key={call.id}
|
key={call.id}
|
||||||
divider
|
divider
|
||||||
onClick={() => handleCall(call.receiver)}
|
|
||||||
>
|
>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
{<PhoneForwardedIcon className={classes.callForward} />}
|
{<PhoneForwardedIcon className={classes.callForward} />}
|
||||||
@@ -74,21 +78,22 @@ export const DialerHistory = ({ calls }) => {
|
|||||||
{<PhoneIcon />}
|
{<PhoneIcon />}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
<IconButton
|
{getDisplayByNumber(call.transmitter) === call.transmitter ? (
|
||||||
onClick={() =>
|
<IconButton
|
||||||
history.push(
|
onClick={() =>
|
||||||
`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`
|
history.push(
|
||||||
)
|
`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`
|
||||||
}
|
)
|
||||||
>
|
}
|
||||||
{<PersonAddIcon />}
|
>
|
||||||
</IconButton>
|
{<PersonAddIcon />}
|
||||||
|
</IconButton>
|
||||||
|
) : null}
|
||||||
</ListItem>
|
</ListItem>
|
||||||
) : (
|
) : (
|
||||||
<ListItem
|
<ListItem
|
||||||
key={call.id}
|
key={call.id}
|
||||||
divider
|
divider
|
||||||
onClick={() => handleCall(call.transmitter)}
|
|
||||||
>
|
>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
{<PhoneCallbackIcon className={classes.callBack} />}
|
{<PhoneCallbackIcon className={classes.callBack} />}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ export const HomeApp = () => {
|
|||||||
const { apps } = useApps();
|
const { apps } = useApps();
|
||||||
return (
|
return (
|
||||||
<AppWrapper>
|
<AppWrapper>
|
||||||
<Box width='100%' mt={6} px={1}>
|
<Box component="div" mt={6} px={1}>
|
||||||
{apps && <GridMenu items={apps} />}
|
{apps && <GridMenu xs={3} items={apps} />}
|
||||||
</Box>
|
</Box>
|
||||||
</AppWrapper>
|
</AppWrapper>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ InjectDebugData(
|
|||||||
profile_name: 'ItsChip',
|
profile_name: 'ItsChip',
|
||||||
isMine: false,
|
isMine: false,
|
||||||
isReported: 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',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
"palette": {
|
"palette": {
|
||||||
"type": "dark",
|
"type": "dark",
|
||||||
"primary": {
|
"primary": {
|
||||||
"main": "#a6d4fa"
|
"main": "#a6d4fa"
|
||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
"paper": "#1c1c1c",
|
"paper": "#1c1c1c",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"APPS_DIALER_CURRENT_CALL_TITLE": "Current Phone Call",
|
"APPS_DIALER_CURRENT_CALL_TITLE": "Current Phone Call",
|
||||||
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
"APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call",
|
||||||
"APPS_DIALER_CURRENT_CALL_WITH": "In call with {{ transmitter }}",
|
"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_ACCEPT_CALL": "Accept",
|
||||||
"APPS_DIALER_REJECT_CALL": "Reject",
|
"APPS_DIALER_REJECT_CALL": "Reject",
|
||||||
"APPS_DIALER_END_CALL": "End",
|
"APPS_DIALER_END_CALL": "End",
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export const APPS: IAppConfig[] = [
|
|||||||
{
|
{
|
||||||
id: 'DIALER',
|
id: 'DIALER',
|
||||||
nameLocale: 'APPS_DIALER',
|
nameLocale: 'APPS_DIALER',
|
||||||
icon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
|
icon: <FontAwesomeIcon icon={faPhoneAlt} />,
|
||||||
notificationIcon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
|
notificationIcon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
|
||||||
backgroundColor: DIALER_APP_PRIMARY_COLOR,
|
backgroundColor: DIALER_APP_PRIMARY_COLOR,
|
||||||
color: DIALER_APP_TEXT_COLOR,
|
color: DIALER_APP_TEXT_COLOR,
|
||||||
@@ -70,7 +70,7 @@ export const APPS: IAppConfig[] = [
|
|||||||
{
|
{
|
||||||
id: 'MESSAGES',
|
id: 'MESSAGES',
|
||||||
nameLocale: 'APPS_MESSAGES',
|
nameLocale: 'APPS_MESSAGES',
|
||||||
icon: <MessageIcon fontSize='default' />,
|
icon: <MessageIcon fontSize="large" />,
|
||||||
notificationIcon: <MessageIcon fontSize='small' />,
|
notificationIcon: <MessageIcon fontSize='small' />,
|
||||||
backgroundColor: MESSAGES_APP_PRIMARY_COLOR,
|
backgroundColor: MESSAGES_APP_PRIMARY_COLOR,
|
||||||
color: MESSAGES_APP_TEXT_COLOR,
|
color: MESSAGES_APP_TEXT_COLOR,
|
||||||
@@ -82,7 +82,7 @@ export const APPS: IAppConfig[] = [
|
|||||||
{
|
{
|
||||||
id: 'CONTACTS',
|
id: 'CONTACTS',
|
||||||
nameLocale: 'APPS_CONTACTS',
|
nameLocale: 'APPS_CONTACTS',
|
||||||
icon: <ContactsIcon />,
|
icon: <ContactsIcon fontSize="large" />,
|
||||||
notificationIcon: <ContactsIcon fontSize='small' />,
|
notificationIcon: <ContactsIcon fontSize='small' />,
|
||||||
backgroundColor: CONTACTS_APP_PRIMARY_COLOR,
|
backgroundColor: CONTACTS_APP_PRIMARY_COLOR,
|
||||||
color: CONTACTS_APP_TEXT_COLOR,
|
color: CONTACTS_APP_TEXT_COLOR,
|
||||||
@@ -94,7 +94,7 @@ export const APPS: IAppConfig[] = [
|
|||||||
{
|
{
|
||||||
id: 'CALCULATOR',
|
id: 'CALCULATOR',
|
||||||
nameLocale: 'APPS_CALCULATOR',
|
nameLocale: 'APPS_CALCULATOR',
|
||||||
icon: <CalculatorIcon />,
|
icon: <CalculatorIcon fontSize="large" />,
|
||||||
notificationIcon: <CalculatorIcon fontSize='small' />,
|
notificationIcon: <CalculatorIcon fontSize='small' />,
|
||||||
backgroundColor: purple[500],
|
backgroundColor: purple[500],
|
||||||
color: grey[50],
|
color: grey[50],
|
||||||
@@ -106,7 +106,7 @@ export const APPS: IAppConfig[] = [
|
|||||||
{
|
{
|
||||||
id: 'SETTINGS',
|
id: 'SETTINGS',
|
||||||
nameLocale: 'APPS_SETTINGS',
|
nameLocale: 'APPS_SETTINGS',
|
||||||
icon: <SettingsIcon />,
|
icon: <SettingsIcon fontSize="large" />,
|
||||||
notificationIcon: <SettingsIcon fontSize='small' />,
|
notificationIcon: <SettingsIcon fontSize='small' />,
|
||||||
backgroundColor: '#383838',
|
backgroundColor: '#383838',
|
||||||
color: grey[50],
|
color: grey[50],
|
||||||
@@ -118,7 +118,7 @@ export const APPS: IAppConfig[] = [
|
|||||||
{
|
{
|
||||||
id: 'BANK',
|
id: 'BANK',
|
||||||
nameLocale: 'APPS_BANK',
|
nameLocale: 'APPS_BANK',
|
||||||
icon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
|
icon: <FontAwesomeIcon icon={faWonSign} />,
|
||||||
notificationIcon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
|
notificationIcon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
|
||||||
backgroundColor: blue[900],
|
backgroundColor: blue[900],
|
||||||
color: common.white,
|
color: common.white,
|
||||||
@@ -128,7 +128,7 @@ export const APPS: IAppConfig[] = [
|
|||||||
{
|
{
|
||||||
id: 'TWITTER',
|
id: 'TWITTER',
|
||||||
nameLocale: 'APPS_TWITTER',
|
nameLocale: 'APPS_TWITTER',
|
||||||
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
|
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth />,
|
||||||
notificationIcon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
|
notificationIcon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
|
||||||
backgroundColor: blue[600],
|
backgroundColor: blue[600],
|
||||||
color: common.white,
|
color: common.white,
|
||||||
|
|||||||
@@ -1,30 +1,47 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import CallIcon from '@material-ui/icons/Call';
|
import CallIcon from '@material-ui/icons/Call';
|
||||||
import CallEndIcon from '@material-ui/icons/CallEnd';
|
import CallEndIcon from '@material-ui/icons/CallEnd';
|
||||||
import { Fab } from '@material-ui/core';
|
|
||||||
import { useCall } from '../hooks/useCall';
|
import { useCall } from '../hooks/useCall';
|
||||||
import useStyles from './modal.styles';
|
import { useCallModal } from '../hooks/useCallModal';
|
||||||
import { useModal } from '../hooks/useModal';
|
import { StatusIconButton } from '../../../ui/components/StatusIconButton';
|
||||||
|
import { Box, makeStyles } from '@material-ui/core';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
export const CallControls = ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
size,
|
icon: {
|
||||||
}: {
|
color: theme.palette.secondary.contrastText,
|
||||||
size?: 'small' | 'medium' | 'large';
|
},
|
||||||
}) => {
|
}));
|
||||||
|
|
||||||
|
const SIZES_SPACING = {
|
||||||
|
small: 1,
|
||||||
|
medium: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const CallControls = ({ size }: { size?: 'small' | 'medium' }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { setModal } = useModal();
|
const history = useHistory();
|
||||||
|
const { setModal } = useCallModal();
|
||||||
const { call, endCall, acceptCall, rejectCall } = useCall();
|
const { call, endCall, acceptCall, rejectCall } = useCall();
|
||||||
|
|
||||||
if (!call) {
|
if (!call) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRejectCall = () => {
|
const handleAcceptCall = (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
history.push('/call');
|
||||||
|
acceptCall();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRejectCall = (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
setModal(false);
|
setModal(false);
|
||||||
rejectCall();
|
rejectCall();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEndCall = () => {
|
const handleEndCall = (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
setModal(false);
|
setModal(false);
|
||||||
endCall();
|
endCall();
|
||||||
};
|
};
|
||||||
@@ -33,34 +50,27 @@ export const CallControls = ({
|
|||||||
|
|
||||||
if (accepted || isTransmitter) {
|
if (accepted || isTransmitter) {
|
||||||
return (
|
return (
|
||||||
<Fab
|
<StatusIconButton color='error' size={size} onClick={handleEndCall}>
|
||||||
size={size}
|
|
||||||
onClick={handleEndCall}
|
|
||||||
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
|
|
||||||
className={classes.actionButton}
|
|
||||||
>
|
|
||||||
<CallEndIcon />
|
<CallEndIcon />
|
||||||
</Fab>
|
</StatusIconButton>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Fab
|
<Box m={SIZES_SPACING[size] || 1} display='inline'>
|
||||||
size={size}
|
<StatusIconButton color='error' size={size} onClick={handleRejectCall}>
|
||||||
onClick={handleRejectCall}
|
<CallEndIcon className={classes.icon} />
|
||||||
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
|
</StatusIconButton>
|
||||||
className={classes.actionButton}
|
</Box>
|
||||||
>
|
<Box m={SIZES_SPACING[size] || 1} display='inline'>
|
||||||
<CallEndIcon />
|
<StatusIconButton
|
||||||
</Fab>
|
color='success'
|
||||||
<Fab
|
size={size}
|
||||||
size={size}
|
onClick={handleAcceptCall}
|
||||||
onClick={acceptCall}
|
>
|
||||||
style={{ backgroundColor: '#27ae60', color: '#fff' }}
|
<CallIcon className={classes.icon} />
|
||||||
className={classes.actionButton}
|
</StatusIconButton>
|
||||||
>
|
</Box>
|
||||||
<CallIcon />
|
|
||||||
</Fab>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -14,12 +14,12 @@ export const CallModal = () => {
|
|||||||
return (
|
return (
|
||||||
<AppWrapper>
|
<AppWrapper>
|
||||||
<AppContent>
|
<AppContent>
|
||||||
<Box pt={16}>
|
<Box pt={24}>
|
||||||
<h1 style={{ textAlign: 'center' }}>{call?.transmitter}</h1>
|
<h1 style={{ textAlign: 'center' }}>{call?.transmitter}</h1>
|
||||||
<CallTimer isAccepted={call?.accepted} />
|
<CallTimer isAccepted={call?.accepted} />
|
||||||
</Box>
|
</Box>
|
||||||
<div className={classes.actions}>
|
<div className={classes.actions}>
|
||||||
<CallControls />
|
<CallControls size="medium" />
|
||||||
</div>
|
</div>
|
||||||
</AppContent>
|
</AppContent>
|
||||||
</AppWrapper>
|
</AppWrapper>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Box } from '@material-ui/core';
|
import { Box, makeStyles } from '@material-ui/core';
|
||||||
import { CallControls } from './CallControls';
|
import { CallControls } from './CallControls';
|
||||||
|
|
||||||
interface ICallNotificationProps {
|
interface ICallNotificationProps {
|
||||||
@@ -7,15 +7,27 @@ interface ICallNotificationProps {
|
|||||||
onReject(): void;
|
onReject(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
root: {
|
||||||
|
paddingBottom: '48px',
|
||||||
|
},
|
||||||
|
controls: {
|
||||||
|
position: 'absolute',
|
||||||
|
bottom: theme.spacing(1),
|
||||||
|
right: '4px',
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
export const CallNotification = ({
|
export const CallNotification = ({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) => {
|
}) => {
|
||||||
|
const classes = useStyles();
|
||||||
return (
|
return (
|
||||||
<div style={{ paddingBottom: '48px' }}>
|
<div className={classes.root}>
|
||||||
<Box>{children}</Box>
|
<Box>{children}</Box>
|
||||||
<Box style={{ position: 'absolute', bottom: 0, right: 0 }}>
|
<Box className={classes.controls}>
|
||||||
<CallControls size='small' />
|
<CallControls size='small' />
|
||||||
</Box>
|
</Box>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ interface ModalProps {
|
|||||||
setModal: (show: boolean) => void;
|
setModal: (show: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useModal = (): ModalProps => {
|
export const useCallModal = (): ModalProps => {
|
||||||
const [modal, setModal] = useRecoilState(callerState.callModal);
|
const [modal, setModal] = useRecoilState(callerState.callModal);
|
||||||
return { modal, setModal }
|
return { modal, setModal }
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
|
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
|
||||||
import { useSetRecoilState } from 'recoil';
|
import { useSetRecoilState } from 'recoil';
|
||||||
import { callerState } from './state';
|
import { callerState } from './state';
|
||||||
@@ -9,10 +9,12 @@ import { useCall } from './useCall';
|
|||||||
import { CallProps } from '../../../common/typings/call';
|
import { CallProps } from '../../../common/typings/call';
|
||||||
import { useApp } from '../../apps/hooks/useApps';
|
import { useApp } from '../../apps/hooks/useApps';
|
||||||
import InjectDebugData from '../../debug/InjectDebugData';
|
import InjectDebugData from '../../debug/InjectDebugData';
|
||||||
|
import { useCallModal } from './useCallModal';
|
||||||
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
const NOTIFICATION_ID = 'call:current';
|
const NOTIFICATION_ID = 'call:current';
|
||||||
|
|
||||||
InjectDebugData<CallProps>([
|
/* InjectDebugData<CallProps | boolean>([
|
||||||
{
|
{
|
||||||
app: 'CALL',
|
app: 'CALL',
|
||||||
method: 'setCaller',
|
method: 'setCaller',
|
||||||
@@ -20,14 +22,22 @@ InjectDebugData<CallProps>([
|
|||||||
accepted: false,
|
accepted: false,
|
||||||
isTransmitter: false,
|
isTransmitter: false,
|
||||||
transmitter: 'Chip',
|
transmitter: 'Chip',
|
||||||
receiver: 'Taso',
|
receiver: 'Taso',
|
||||||
active: true,
|
active: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
{
|
||||||
|
app: 'CALL',
|
||||||
|
method: 'callModal',
|
||||||
|
data: true,
|
||||||
|
},
|
||||||
|
]); */
|
||||||
|
|
||||||
export const useCallService = () => {
|
export const useCallService = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { modal } = useCallModal();
|
||||||
|
const history = useHistory();
|
||||||
|
const { pathname } = useLocation();
|
||||||
const {
|
const {
|
||||||
addNotificationAlert,
|
addNotificationAlert,
|
||||||
removeId,
|
removeId,
|
||||||
@@ -40,14 +50,30 @@ export const useCallService = () => {
|
|||||||
|
|
||||||
const setModal = useSetRecoilState(callerState.callModal);
|
const setModal = useSetRecoilState(callerState.callModal);
|
||||||
|
|
||||||
|
const [modalHasBeenOpenedThisCall, setModalOpened] = useState<boolean>(false);
|
||||||
|
|
||||||
const callNotificationBase = {
|
const callNotificationBase = {
|
||||||
app: 'CALL',
|
app: 'CALL',
|
||||||
id: NOTIFICATION_ID,
|
id: NOTIFICATION_ID,
|
||||||
cantClose: true,
|
cantClose: true,
|
||||||
icon,
|
icon,
|
||||||
|
onClick: () => history.push('/call'),
|
||||||
notificationIcon,
|
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) => {
|
const _setCall = (_call: CallProps) => {
|
||||||
setCall(_call);
|
setCall(_call);
|
||||||
if (!_call || !_call.active) {
|
if (!_call || !_call.active) {
|
||||||
@@ -76,6 +102,7 @@ export const useCallService = () => {
|
|||||||
title: t('APPS_DIALER_INCOMING_CALL_TITLE', {
|
title: t('APPS_DIALER_INCOMING_CALL_TITLE', {
|
||||||
transmitter: _call.transmitter,
|
transmitter: _call.transmitter,
|
||||||
}),
|
}),
|
||||||
|
keepWhenPhoneClosed: true,
|
||||||
content: (
|
content: (
|
||||||
<CallNotification>
|
<CallNotification>
|
||||||
{t('APPS_DIALER_TRANSMITTER_IS_CALLING', {
|
{t('APPS_DIALER_TRANSMITTER_IS_CALLING', {
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ const validKeys = [
|
|||||||
|
|
||||||
const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
|
const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
|
||||||
|
|
||||||
export const useInitKeyboard = () => {
|
export const useKeyboardService = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { closePhone } = usePhone();
|
const { closePhone } = usePhone();
|
||||||
const getters = {
|
const getters = {
|
||||||
@@ -7,8 +7,9 @@ import {
|
|||||||
import KeyboardArrowLeftIcon from '@material-ui/icons/KeyboardArrowLeft';
|
import KeyboardArrowLeftIcon from '@material-ui/icons/KeyboardArrowLeft';
|
||||||
import AppsIcon from '@material-ui/icons/Apps';
|
import AppsIcon from '@material-ui/icons/Apps';
|
||||||
import RadioButtonUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked';
|
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 { usePhone } from '../../phone/hooks/usePhone';
|
||||||
|
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -18,14 +19,18 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const Navigation = () => {
|
export const Navigation = () => {
|
||||||
const { closePhone } = usePhone();
|
|
||||||
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { isExact } = useRouteMatch('/');
|
||||||
|
const { closePhone } = usePhone();
|
||||||
|
const { setBarUncollapsed } = useNotifications();
|
||||||
return (
|
return (
|
||||||
<BottomNavigation
|
<BottomNavigation
|
||||||
className={classes.root}
|
className={classes.root}
|
||||||
onChange={(_e, value) => value()}
|
onChange={(_e, value) => {
|
||||||
|
setBarUncollapsed(false);
|
||||||
|
value();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<BottomNavigationAction
|
<BottomNavigationAction
|
||||||
label='Home'
|
label='Home'
|
||||||
@@ -39,7 +44,7 @@ export const Navigation = () => {
|
|||||||
/>
|
/>
|
||||||
<BottomNavigationAction
|
<BottomNavigationAction
|
||||||
label='Back'
|
label='Back'
|
||||||
value={history.goBack}
|
value={() => !isExact && history.goBack()}
|
||||||
icon={<KeyboardArrowLeftIcon />}
|
icon={<KeyboardArrowLeftIcon />}
|
||||||
/>
|
/>
|
||||||
</BottomNavigation>
|
</BottomNavigation>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
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 { useNotifications } from '../hooks/useNotifications';
|
||||||
import { Alert, AlertTitle } from '@material-ui/lab';
|
import { Alert, AlertTitle } from '@material-ui/lab';
|
||||||
|
|
||||||
@@ -11,6 +12,11 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
alert: {
|
alert: {
|
||||||
|
'& .MuiAlert-action': {
|
||||||
|
top: theme.spacing(1),
|
||||||
|
right: theme.spacing(2),
|
||||||
|
position: 'absolute',
|
||||||
|
},
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
width: '370px',
|
width: '370px',
|
||||||
@@ -22,6 +28,16 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
color: theme.palette.text.primary,
|
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 = () => {
|
export const NotificationAlert = () => {
|
||||||
@@ -30,17 +46,37 @@ export const NotificationAlert = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.snackbar}>
|
<div className={classes.snackbar}>
|
||||||
{currentAlert ? (
|
<Slide in={!!currentAlert} mountOnEnter unmountOnExit>
|
||||||
<Alert
|
<Alert
|
||||||
onClick={() => currentAlert.onClick?.(currentAlert)}
|
action={
|
||||||
icon={currentAlert.icon || false}
|
<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}
|
className={classes.alert}
|
||||||
elevation={6}
|
elevation={6}
|
||||||
>
|
>
|
||||||
<AlertTitle>{currentAlert.title}</AlertTitle>
|
<AlertTitle>
|
||||||
<Box width='100%'>{currentAlert.content}</Box>
|
<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>
|
</Alert>
|
||||||
) : null}
|
</Slide>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
makeStyles,
|
makeStyles,
|
||||||
Typography,
|
Typography,
|
||||||
@@ -66,9 +66,13 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
export const NotificationBar = () => {
|
export const NotificationBar = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
const { icons, notifications, removeNotification } = useNotifications();
|
const {
|
||||||
|
icons,
|
||||||
const [uncollapsed, setUncollapsed] = useState<boolean>(false);
|
notifications,
|
||||||
|
removeNotification,
|
||||||
|
barUncollapsed,
|
||||||
|
setBarUncollapsed,
|
||||||
|
} = useNotifications();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -78,7 +82,7 @@ export const NotificationBar = () => {
|
|||||||
justify='space-between'
|
justify='space-between'
|
||||||
wrap='nowrap'
|
wrap='nowrap'
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setUncollapsed(!uncollapsed);
|
setBarUncollapsed((curr) => !curr);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Grid container item wrap='nowrap'>
|
<Grid container item wrap='nowrap'>
|
||||||
@@ -115,28 +119,29 @@ export const NotificationBar = () => {
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Slide direction='down' in={uncollapsed}>
|
<Slide direction='down' in={barUncollapsed}>
|
||||||
<Paper square className={classes.drawer}>
|
<Paper square className={classes.drawer}>
|
||||||
<Box p={2}>
|
<Box py={2}>
|
||||||
<List>
|
<List>
|
||||||
<Divider />
|
<Divider />
|
||||||
{notifications.map((notification, idx) => (
|
{notifications.map((notification, idx) => (
|
||||||
<NotificationItem
|
<NotificationItem
|
||||||
key={idx}
|
key={idx}
|
||||||
|
{...notification}
|
||||||
onClose={(e) => {
|
onClose={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
notification.onClose?.(notification);
|
||||||
if (notifications.length === 1) {
|
if (notifications.length === 1) {
|
||||||
setUncollapsed(false);
|
setBarUncollapsed(false);
|
||||||
}
|
}
|
||||||
removeNotification(idx);
|
removeNotification(idx);
|
||||||
}}
|
}}
|
||||||
onClickClose={() => {
|
onClickClose={() => {
|
||||||
setUncollapsed(false);
|
setBarUncollapsed(false);
|
||||||
if (!notification.cantClose) {
|
if (!notification.cantClose) {
|
||||||
removeNotification(idx);
|
removeNotification(idx);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
{...notification}
|
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
@@ -145,7 +150,7 @@ export const NotificationBar = () => {
|
|||||||
<IconButton
|
<IconButton
|
||||||
className={classes.collapseBtn}
|
className={classes.collapseBtn}
|
||||||
size='small'
|
size='small'
|
||||||
onClick={() => setUncollapsed(false)}
|
onClick={() => setBarUncollapsed(false)}
|
||||||
>
|
>
|
||||||
<ArrowDropUpIcon />
|
<ArrowDropUpIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|||||||
@@ -6,16 +6,18 @@ import {
|
|||||||
ListItemAvatar,
|
ListItemAvatar,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
makeStyles,
|
makeStyles,
|
||||||
|
Theme,
|
||||||
} from '@material-ui/core';
|
} from '@material-ui/core';
|
||||||
import { INotification } from '../providers/NotificationsProvider';
|
import { INotification } from '../providers/NotificationsProvider';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles<Theme, { cantClose: boolean }>((theme) => ({
|
||||||
closeNotifBtn: {
|
closeNotifBtn: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
right: '8px',
|
right: '8px',
|
||||||
top: '8px',
|
top: '8px',
|
||||||
},
|
},
|
||||||
notificationItem: {
|
notificationItem: {
|
||||||
|
paddingRight: ({ cantClose }) => (cantClose ? '8px' : '28px'),
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -29,7 +31,7 @@ export const NotificationItem = ({
|
|||||||
onClickClose: (e: any) => void;
|
onClickClose: (e: any) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const { title, icon, content, cantClose, onClick } = notification;
|
const { title, icon, content, cantClose, onClick } = notification;
|
||||||
const classes = useStyles();
|
const classes = useStyles({ cantClose });
|
||||||
return (
|
return (
|
||||||
<ListItem
|
<ListItem
|
||||||
divider
|
divider
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import React, {
|
|||||||
useRef,
|
useRef,
|
||||||
useEffect,
|
useEffect,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
import { phoneState } from '../../phone/hooks/state';
|
||||||
import { DEFAULT_ALERT_HIDE_TIME } from '../notifications.constants';
|
import { DEFAULT_ALERT_HIDE_TIME } from '../notifications.constants';
|
||||||
|
|
||||||
export interface INotification {
|
export interface INotification {
|
||||||
@@ -16,9 +18,17 @@ export interface INotification {
|
|||||||
icon?: JSX.Element;
|
icon?: JSX.Element;
|
||||||
notificationIcon?: JSX.Element;
|
notificationIcon?: JSX.Element;
|
||||||
cantClose?: boolean;
|
cantClose?: boolean;
|
||||||
|
keepWhenPhoneClosed?: boolean;
|
||||||
|
onClose?: (notification: INotification) => void;
|
||||||
onClick?: (notification: INotification) => void;
|
onClick?: (notification: INotification) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type INotificationAlert = INotification & {
|
||||||
|
onClickAlert(e?: any): void;
|
||||||
|
onCloseAlert(e?: any): void;
|
||||||
|
resolve(): void;
|
||||||
|
};
|
||||||
|
|
||||||
interface INotificationIcon {
|
interface INotificationIcon {
|
||||||
key: string;
|
key: string;
|
||||||
icon: JSX.Element;
|
icon: JSX.Element;
|
||||||
@@ -26,8 +36,10 @@ interface INotificationIcon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const NotificationsContext = createContext<{
|
export const NotificationsContext = createContext<{
|
||||||
|
barUncollapsed: boolean;
|
||||||
|
setBarUncollapsed: (v: boolean | ((c: boolean) => boolean)) => void;
|
||||||
notifications: INotification[];
|
notifications: INotification[];
|
||||||
currentAlert: INotification;
|
currentAlert: INotificationAlert;
|
||||||
icons: INotificationIcon[];
|
icons: INotificationIcon[];
|
||||||
count: number;
|
count: number;
|
||||||
removeAlerts(): void;
|
removeAlerts(): void;
|
||||||
@@ -45,13 +57,23 @@ export const NotificationsContext = createContext<{
|
|||||||
}>(null);
|
}>(null);
|
||||||
|
|
||||||
export function NotificationsProvider({ children }) {
|
export function NotificationsProvider({ children }) {
|
||||||
|
const isPhoneOpen = useRecoilValue(phoneState.visibility);
|
||||||
|
|
||||||
|
const [barUncollapsed, setBarUncollapsed] = useState<boolean>(false);
|
||||||
|
|
||||||
const [notifications, setNotifications] = useState<INotification[]>([]);
|
const [notifications, setNotifications] = useState<INotification[]>([]);
|
||||||
|
|
||||||
const alertTimeout = useRef<NodeJS.Timeout>();
|
const alertTimeout = useRef<NodeJS.Timeout>();
|
||||||
const [alerts, setAlerts] = useState<
|
const [alerts, setAlerts] = useState<
|
||||||
Array<[INotification, boolean, Partial<INotification>]>
|
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(
|
const updateNotification = useCallback(
|
||||||
(idx: number, value: INotification) => {
|
(idx: number, value: INotification) => {
|
||||||
@@ -109,20 +131,28 @@ export function NotificationsProvider({ children }) {
|
|||||||
res();
|
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(() => {
|
alertTimeout.current = setTimeout(() => {
|
||||||
resolve();
|
resolve();
|
||||||
// If you change or remove the 300 i'll kill your pet - Kidz /s
|
// If you change or remove the 300 i'll kill your pet - Kidz /s
|
||||||
// Really, this makes it work nicely with usePhoneVisibility :)
|
// Really, this makes it work nicely with usePhoneVisibility :)
|
||||||
}, DEFAULT_ALERT_HIDE_TIME + 300);
|
}, DEFAULT_ALERT_HIDE_TIME + 300);
|
||||||
|
|
||||||
setCurrentAlert({
|
|
||||||
...n,
|
|
||||||
onClick: () => {
|
|
||||||
clearTimeout(alertTimeout.current);
|
|
||||||
n.onClick?.(n);
|
|
||||||
resolve();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[addOrUpdateNotification]
|
[addOrUpdateNotification]
|
||||||
@@ -186,6 +216,8 @@ export function NotificationsProvider({ children }) {
|
|||||||
return (
|
return (
|
||||||
<NotificationsContext.Provider
|
<NotificationsContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
setBarUncollapsed,
|
||||||
|
barUncollapsed,
|
||||||
currentAlert,
|
currentAlert,
|
||||||
notifications,
|
notifications,
|
||||||
removeAlerts,
|
removeAlerts,
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
import { IServerConfig } from '../../../common/typings/config';
|
import { IServerConfig } from '../../../common/typings/config';
|
||||||
import ServerConfig from '../../../config.autogen.json';
|
import ServerConfig from '../../../config.autogen.json';
|
||||||
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
||||||
import Nui from '../../nui-events/utils/Nui';
|
import Nui from '../../nui-events/utils/Nui';
|
||||||
|
import { phoneState } from './state';
|
||||||
|
|
||||||
interface IUsePhone {
|
interface IUsePhone {
|
||||||
config?: IServerConfig;
|
config?: IServerConfig;
|
||||||
openPhone(): void;
|
openPhone(): void;
|
||||||
closePhone(): void;
|
closePhone(): void;
|
||||||
|
isPhoneOpen: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const usePhone = (): IUsePhone => {
|
export const usePhone = (): IUsePhone => {
|
||||||
|
const isPhoneOpen = useRecoilValue(phoneState.visibility);
|
||||||
|
|
||||||
const { removeAlerts } = useNotifications();
|
const { removeAlerts } = useNotifications();
|
||||||
|
|
||||||
const closePhone = () => {
|
const closePhone = () => {
|
||||||
@@ -20,5 +25,5 @@ export const usePhone = (): IUsePhone => {
|
|||||||
Nui.send('phone:open');
|
Nui.send('phone:open');
|
||||||
};
|
};
|
||||||
|
|
||||||
return { config: ServerConfig as any, closePhone, openPhone };
|
return { config: ServerConfig as any, closePhone, openPhone, isPhoneOpen };
|
||||||
};
|
};
|
||||||
@@ -12,35 +12,36 @@ export const usePhoneVisibility = () => {
|
|||||||
|
|
||||||
const [notifVisibility, setNotifVisibility] = useState<boolean>(false);
|
const [notifVisibility, setNotifVisibility] = useState<boolean>(false);
|
||||||
|
|
||||||
const [isNotificationVisibleOnly, setNotificationVisibleOnly] = useState<
|
|
||||||
boolean
|
|
||||||
>(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setNotificationVisibleOnly(!!(!visibility && currentAlert));
|
|
||||||
}, [visibility, currentAlert]);
|
|
||||||
|
|
||||||
const notificationTimer = useRef<NodeJS.Timeout>();
|
const notificationTimer = useRef<NodeJS.Timeout>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isNotificationVisibleOnly) {
|
if (visibility) {
|
||||||
|
setNotifVisibility(false);
|
||||||
|
}
|
||||||
|
}, [visibility]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!visibility && currentAlert) {
|
||||||
setNotifVisibility(true);
|
setNotifVisibility(true);
|
||||||
if (notificationTimer.current) {
|
if (notificationTimer.current) {
|
||||||
clearTimeout(notificationTimer.current);
|
clearTimeout(notificationTimer.current);
|
||||||
notificationTimer.current = undefined;
|
notificationTimer.current = undefined;
|
||||||
}
|
}
|
||||||
|
if (currentAlert?.keepWhenPhoneClosed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
notificationTimer.current = setTimeout(() => {
|
notificationTimer.current = setTimeout(() => {
|
||||||
setNotifVisibility(false);
|
setNotifVisibility(false);
|
||||||
}, DEFAULT_ALERT_HIDE_TIME);
|
}, DEFAULT_ALERT_HIDE_TIME);
|
||||||
}
|
}
|
||||||
}, [isNotificationVisibleOnly, setVisibility]);
|
}, [currentAlert, visibility, setVisibility]);
|
||||||
|
|
||||||
const bottom = useMemo(() => {
|
const bottom = useMemo(() => {
|
||||||
if (isNotificationVisibleOnly) {
|
if (!visibility) {
|
||||||
return `calc(-70% * ${zoom})`;
|
return `calc(-70% * ${zoom})`;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}, [isNotificationVisibleOnly, zoom]);
|
}, [visibility, zoom]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bottom,
|
bottom,
|
||||||
|
|||||||
@@ -1,56 +1,68 @@
|
|||||||
import React from 'react';
|
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 Avatar from '@material-ui/core/Avatar';
|
||||||
import { green } from '@material-ui/core/colors';
|
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 {
|
const useStyles = makeStyles<Theme, { color: string; backgroundColor: string }>(
|
||||||
root: any;
|
(theme) => ({
|
||||||
avatar: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
|
||||||
(theme): IStyles => ({
|
|
||||||
root: {
|
root: {
|
||||||
display: 'flex',
|
|
||||||
'& > *': {
|
|
||||||
margin: theme.spacing(1),
|
|
||||||
},
|
|
||||||
padding: 0,
|
padding: 0,
|
||||||
|
marginTop: theme.spacing(3),
|
||||||
},
|
},
|
||||||
avatar: {
|
avatar: {
|
||||||
|
'&:hover': {
|
||||||
|
backgroundColor: ({ backgroundColor }) => fade(backgroundColor, 0.6),
|
||||||
|
},
|
||||||
backgroundColor: ({ backgroundColor }) => backgroundColor,
|
backgroundColor: ({ backgroundColor }) => backgroundColor,
|
||||||
color: ({ color }) => color,
|
color: ({ color }) => color,
|
||||||
width: theme.spacing(7),
|
boxShadow: theme.shadows[2],
|
||||||
height: theme.spacing(7),
|
width: theme.spacing(8),
|
||||||
|
height: theme.spacing(8),
|
||||||
fontSize: theme.typography.h4.fontSize,
|
fontSize: theme.typography.h4.fontSize,
|
||||||
},
|
},
|
||||||
|
tooltip: {
|
||||||
|
fontSize: 12,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export const AppIcon = ({
|
export const AppIcon = ({
|
||||||
|
id,
|
||||||
|
nameLocale,
|
||||||
name,
|
name,
|
||||||
icon,
|
icon,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
color,
|
color,
|
||||||
notification,
|
notification,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
const classes = useStyles({
|
const classes = useStyles({
|
||||||
backgroundColor: backgroundColor || green[50],
|
backgroundColor: backgroundColor || green[50],
|
||||||
color: color || green[400],
|
color: color || green[400],
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button className={classes.root}>
|
<Tooltip
|
||||||
<Badge
|
arrow
|
||||||
color="error"
|
key={id}
|
||||||
badgeContent={notification?.badge}
|
title={t(nameLocale)}
|
||||||
invisible={!notification || notification.badge < 2}
|
placement='top'
|
||||||
>
|
classes={{ tooltip: classes.tooltip }}
|
||||||
<Avatar className={classes.avatar}>
|
TransitionComponent={Zoom}
|
||||||
{icon || name[0].toUpperCase()}
|
>
|
||||||
</Avatar>
|
<Button className={classes.root}>
|
||||||
</Badge>
|
<Badge
|
||||||
</Button>
|
color='error'
|
||||||
|
badgeContent={notification?.badge}
|
||||||
|
invisible={!notification || notification.badge < 2}
|
||||||
|
>
|
||||||
|
<Avatar className={classes.avatar}>
|
||||||
|
{icon || name[0].toUpperCase()}
|
||||||
|
</Avatar>
|
||||||
|
</Badge>
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1,53 +1,32 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { AppIcon } from './AppIcon';
|
import { AppIcon } from './AppIcon';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { Box, Grid } from '@material-ui/core';
|
||||||
import { Grid, makeStyles, Tooltip, Zoom } from '@material-ui/core';
|
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
export const GridMenu = ({
|
||||||
root: {
|
items,
|
||||||
marginTop: theme.spacing(3),
|
Component = AppIcon,
|
||||||
},
|
xs = undefined,
|
||||||
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
|
|
||||||
return (
|
return (
|
||||||
<Grid container justify='center'>
|
<Grid container alignItems='center' direction='row'>
|
||||||
<Grid container item>
|
{items &&
|
||||||
{items &&
|
items.length &&
|
||||||
items.length &&
|
items.map((item) => (
|
||||||
items.map((item) => (
|
<Grid
|
||||||
<Tooltip
|
item
|
||||||
arrow
|
xs={xs}
|
||||||
key={item.id}
|
key={item.id}
|
||||||
title={t(item.nameLocale)}
|
alignItems='center'
|
||||||
placement='top'
|
justify='center'
|
||||||
classes={{ tooltip: classes.tooltip }}
|
>
|
||||||
TransitionComponent={Zoom}
|
<Box textAlign='center'>
|
||||||
>
|
<Link to={item.path}>
|
||||||
<Grid
|
|
||||||
key={item.id}
|
|
||||||
item
|
|
||||||
className={classes.item}
|
|
||||||
component={Link}
|
|
||||||
to={item.path}
|
|
||||||
>
|
|
||||||
<Component {...item} />
|
<Component {...item} />
|
||||||
</Grid>
|
</Link>
|
||||||
</Tooltip>
|
</Box>
|
||||||
))}
|
</Grid>
|
||||||
</Grid>
|
))}
|
||||||
</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} />;
|
||||||
|
};
|
||||||
Reference in new issue
Block a user