diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 5707df6..1c5c41b 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -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 (
@@ -79,16 +79,15 @@ function Phone() { <>
- {modal ? ( - - ) : ( - <> - - {apps.map((App) => ( - - ))} - - )} + <> + + {callModal && ( + + )} + {apps.map((App) => ( + + ))} +
diff --git a/phone/src/apps/calculator/components/CalculatorIcon.tsx b/phone/src/apps/calculator/components/CalculatorIcon.tsx index 41b0710..0db3dd3 100644 --- a/phone/src/apps/calculator/components/CalculatorIcon.tsx +++ b/phone/src/apps/calculator/components/CalculatorIcon.tsx @@ -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 ( { alignItems='center' paddingTop={35} > -

You got no friends!😎

+

+ You got no friends! + + 😎 + +

); } @@ -60,7 +65,6 @@ export const DialerHistory = ({ calls }) => { handleCall(call.receiver)} > {} @@ -74,21 +78,22 @@ export const DialerHistory = ({ calls }) => { {} - - history.push( - `/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts` - ) - } - > - {} - + {getDisplayByNumber(call.transmitter) === call.transmitter ? ( + + history.push( + `/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts` + ) + } + > + {} + + ) : null} ) : ( handleCall(call.transmitter)} > {} diff --git a/phone/src/apps/home/components/Home.tsx b/phone/src/apps/home/components/Home.tsx index e1513fb..da22aa0 100644 --- a/phone/src/apps/home/components/Home.tsx +++ b/phone/src/apps/home/components/Home.tsx @@ -8,8 +8,8 @@ export const HomeApp = () => { const { apps } = useApps(); return ( - - {apps && } + + {apps && } ); diff --git a/phone/src/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx index a23ab4d..3498d98 100644 --- a/phone/src/apps/twitter/components/TwitterApp.tsx +++ b/phone/src/apps/twitter/components/TwitterApp.tsx @@ -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', }, }, ], diff --git a/phone/src/config/default.json b/phone/src/config/default.json index c748c01..17eb8bb 100644 --- a/phone/src/config/default.json +++ b/phone/src/config/default.json @@ -44,7 +44,7 @@ "palette": { "type": "dark", "primary": { - "main": "#a6d4fa" + "main": "#a6d4fa" }, "background": { "paper": "#1c1c1c", diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 0a4a61e..3ac402d 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -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", diff --git a/phone/src/os/apps/config/apps.tsx b/phone/src/os/apps/config/apps.tsx index e386969..4a08f50 100644 --- a/phone/src/os/apps/config/apps.tsx +++ b/phone/src/os/apps/config/apps.tsx @@ -60,7 +60,7 @@ export const APPS: IAppConfig[] = [ { id: 'DIALER', nameLocale: 'APPS_DIALER', - icon: , + icon: , notificationIcon: , backgroundColor: DIALER_APP_PRIMARY_COLOR, color: DIALER_APP_TEXT_COLOR, @@ -70,7 +70,7 @@ export const APPS: IAppConfig[] = [ { id: 'MESSAGES', nameLocale: 'APPS_MESSAGES', - icon: , + icon: , notificationIcon: , backgroundColor: MESSAGES_APP_PRIMARY_COLOR, color: MESSAGES_APP_TEXT_COLOR, @@ -82,7 +82,7 @@ export const APPS: IAppConfig[] = [ { id: 'CONTACTS', nameLocale: 'APPS_CONTACTS', - icon: , + icon: , notificationIcon: , backgroundColor: CONTACTS_APP_PRIMARY_COLOR, color: CONTACTS_APP_TEXT_COLOR, @@ -94,7 +94,7 @@ export const APPS: IAppConfig[] = [ { id: 'CALCULATOR', nameLocale: 'APPS_CALCULATOR', - icon: , + icon: , notificationIcon: , backgroundColor: purple[500], color: grey[50], @@ -106,7 +106,7 @@ export const APPS: IAppConfig[] = [ { id: 'SETTINGS', nameLocale: 'APPS_SETTINGS', - icon: , + icon: , notificationIcon: , backgroundColor: '#383838', color: grey[50], @@ -118,7 +118,7 @@ export const APPS: IAppConfig[] = [ { id: 'BANK', nameLocale: 'APPS_BANK', - icon: , + icon: , notificationIcon: , backgroundColor: blue[900], color: common.white, @@ -128,7 +128,7 @@ export const APPS: IAppConfig[] = [ { id: 'TWITTER', nameLocale: 'APPS_TWITTER', - icon: , + icon: , notificationIcon: , backgroundColor: blue[600], color: common.white, diff --git a/phone/src/os/call/components/CallControls.tsx b/phone/src/os/call/components/CallControls.tsx index 8ef9cf6..b766229 100644 --- a/phone/src/os/call/components/CallControls.tsx +++ b/phone/src/os/call/components/CallControls.tsx @@ -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 ( - + - + ); } return ( <> - - - - - - + + + + + + + + + + ); }; diff --git a/phone/src/os/call/components/CallModal.tsx b/phone/src/os/call/components/CallModal.tsx index 64b0b01..4a3e390 100644 --- a/phone/src/os/call/components/CallModal.tsx +++ b/phone/src/os/call/components/CallModal.tsx @@ -14,12 +14,12 @@ export const CallModal = () => { return ( - +

{call?.transmitter}

- +
diff --git a/phone/src/os/call/components/CallNotification.tsx b/phone/src/os/call/components/CallNotification.tsx index d8b8719..e5bca99 100644 --- a/phone/src/os/call/components/CallNotification.tsx +++ b/phone/src/os/call/components/CallNotification.tsx @@ -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 ( -
+
{children} - +
diff --git a/phone/src/os/call/hooks/useModal.ts b/phone/src/os/call/hooks/useCallModal.ts similarity index 84% rename from phone/src/os/call/hooks/useModal.ts rename to phone/src/os/call/hooks/useCallModal.ts index 3ac7069..89e2624 100644 --- a/phone/src/os/call/hooks/useModal.ts +++ b/phone/src/os/call/hooks/useCallModal.ts @@ -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 } } \ No newline at end of file diff --git a/phone/src/os/call/hooks/useCallService.tsx b/phone/src/os/call/hooks/useCallService.tsx index 90a94f7..65edc18 100644 --- a/phone/src/os/call/hooks/useCallService.tsx +++ b/phone/src/os/call/hooks/useCallService.tsx @@ -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([ +/* InjectDebugData([ { app: 'CALL', method: 'setCaller', @@ -20,14 +22,22 @@ InjectDebugData([ 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(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: ( {t('APPS_DIALER_TRANSMITTER_IS_CALLING', { diff --git a/phone/src/os/keyboard/hooks/useKeyboard.ts b/phone/src/os/keyboard/hooks/useKeyboardService.ts similarity index 98% rename from phone/src/os/keyboard/hooks/useKeyboard.ts rename to phone/src/os/keyboard/hooks/useKeyboardService.ts index b2f9dfe..db45bf9 100644 --- a/phone/src/os/keyboard/hooks/useKeyboard.ts +++ b/phone/src/os/keyboard/hooks/useKeyboardService.ts @@ -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 = { diff --git a/phone/src/os/navigation-bar/components/Navigation.tsx b/phone/src/os/navigation-bar/components/Navigation.tsx index 92406d8..6e9918a 100644 --- a/phone/src/os/navigation-bar/components/Navigation.tsx +++ b/phone/src/os/navigation-bar/components/Navigation.tsx @@ -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 ( value()} + onChange={(_e, value) => { + setBarUncollapsed(false); + value(); + }} > { /> !isExact && history.goBack()} icon={} /> diff --git a/phone/src/os/notifications/components/NotificationAlert.tsx b/phone/src/os/notifications/components/NotificationAlert.tsx index bba4a13..c7d3044 100644 --- a/phone/src/os/notifications/components/NotificationAlert.tsx +++ b/phone/src/os/notifications/components/NotificationAlert.tsx @@ -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 (
- {currentAlert ? ( + currentAlert.onClick?.(currentAlert)} - icon={currentAlert.icon || false} + action={ + { + e.stopPropagation(); + currentAlert?.onCloseAlert(e); + }} + > + + + } + onClick={(e) => currentAlert?.onClickAlert(e)} + icon={currentAlert?.icon || false} className={classes.alert} elevation={6} > - {currentAlert.title} - {currentAlert.content} + + + + {currentAlert?.title} + + + + + {currentAlert?.content} + - ) : null} +
); }; diff --git a/phone/src/os/notifications/components/NotificationBar.tsx b/phone/src/os/notifications/components/NotificationBar.tsx index af0232a..ec15c8d 100644 --- a/phone/src/os/notifications/components/NotificationBar.tsx +++ b/phone/src/os/notifications/components/NotificationBar.tsx @@ -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(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); }} > @@ -115,28 +119,29 @@ export const NotificationBar = () => { - + - + {notifications.map((notification, idx) => ( { 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} /> ))} @@ -145,7 +150,7 @@ export const NotificationBar = () => { setUncollapsed(false)} + onClick={() => setBarUncollapsed(false)} > diff --git a/phone/src/os/notifications/components/NotificationItem.tsx b/phone/src/os/notifications/components/NotificationItem.tsx index e37d751..602c50e 100644 --- a/phone/src/os/notifications/components/NotificationItem.tsx +++ b/phone/src/os/notifications/components/NotificationItem.tsx @@ -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) => ({ 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 ( 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(false); + const [notifications, setNotifications] = useState([]); const alertTimeout = useRef(); const [alerts, setAlerts] = useState< Array<[INotification, boolean, Partial]> >([]); - const [currentAlert, setCurrentAlert] = useState(); + const [currentAlert, setCurrentAlert] = useState(); + + 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 ( { + 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 }; }; diff --git a/phone/src/os/phone/hooks/usePhoneVisibility.ts b/phone/src/os/phone/hooks/usePhoneVisibility.ts index 6cc41ce..e279dfa 100644 --- a/phone/src/os/phone/hooks/usePhoneVisibility.ts +++ b/phone/src/os/phone/hooks/usePhoneVisibility.ts @@ -12,35 +12,36 @@ export const usePhoneVisibility = () => { const [notifVisibility, setNotifVisibility] = useState(false); - const [isNotificationVisibleOnly, setNotificationVisibleOnly] = useState< - boolean - >(false); - - useEffect(() => { - setNotificationVisibleOnly(!!(!visibility && currentAlert)); - }, [visibility, currentAlert]); - const notificationTimer = useRef(); 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, diff --git a/phone/src/ui/components/AppIcon.tsx b/phone/src/ui/components/AppIcon.tsx index e1b9b7d..1bfd94d 100644 --- a/phone/src/ui/components/AppIcon.tsx +++ b/phone/src/ui/components/AppIcon.tsx @@ -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) => ({ 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 ( - + + + ); }; diff --git a/phone/src/ui/components/GridMenu.tsx b/phone/src/ui/components/GridMenu.tsx index bb023c9..f18c5c9 100644 --- a/phone/src/ui/components/GridMenu.tsx +++ b/phone/src/ui/components/GridMenu.tsx @@ -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 ( - - - {items && - items.length && - items.map((item) => ( - - + + {items && + items.length && + items.map((item) => ( + + + - - - ))} - + + + + ))} ); }; diff --git a/phone/src/ui/components/StatusIconButton.tsx b/phone/src/ui/components/StatusIconButton.tsx new file mode 100644 index 0000000..1f2fb98 --- /dev/null +++ b/phone/src/ui/components/StatusIconButton.tsx @@ -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 & { color: StatusButtonStyleColor }) => { + const classes = useStyles({ color }); + return ; +};