diff --git a/phone/src/Phone.css b/phone/src/Phone.css
index 2ba3b93..4c89d5e 100644
--- a/phone/src/Phone.css
+++ b/phone/src/Phone.css
@@ -25,8 +25,6 @@
overflow: hidden;
position: absolute;
background-color: black;
- /* border-left: 4px solid black;
- border-right: 4px solid black; */
bottom: 100px;
left: 50px;
right: 50px;
@@ -51,17 +49,12 @@
}
*::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
- background-color: #f5f5f5;
+ background-color: #666;
}
*::-webkit-scrollbar {
width: 3px;
background-color: transparent;
}
*::-webkit-scrollbar-thumb {
- background-color: #666;
+ background-color: #f5f5f5;
}
-
-
-.zoomProp {
- transform: scale(10);
-}
\ No newline at end of file
diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx
index 4244f67..60a4dd9 100644
--- a/phone/src/Phone.tsx
+++ b/phone/src/Phone.tsx
@@ -5,9 +5,8 @@ import { Route } from 'react-router-dom';
import { CallModal } from './modal/components/CallModal';
import { Alert } from './ui/components/Alert';
import { HomeApp } from './apps/home/components/Home';
-import { createMuiTheme, ThemeProvider, Slide} from '@material-ui/core';
+import { createMuiTheme, ThemeProvider, Slide } from '@material-ui/core';
import { useInitKeyboard } from './os/keyboard/hooks/useKeyboard';
-import { NotificationIcon } from './os/notifications/components/NotificationIcon';
import { NotificationBar } from './os/notifications/components/NotificationBar';
import { Navigation } from './os/navigation-bar/components/Navigation';
import { useNuiService } from './os/nui-events/hooks/useNuiService';
@@ -23,25 +22,34 @@ import { useMessagesService } from './apps/messages/hooks/useMessageService';
import { useNotesService } from './apps/notes/hooks/useNotesService';
import { usePhotoService } from './apps/camera/hooks/usePhotoService';
import Nui from './os/nui-events/utils/Nui';
-import { usePhone } from './os/phone/hooks/usePhone';
-import { settingsState } from './apps/settings/hooks/useSettings';
+import { useSettings } from './apps/settings/hooks/useSettings';
import config from './config/default.json';
-import { useRecoilState } from 'recoil';
import { useCallService } from './modal/hooks/useCallService';
import { useModal } from './modal/hooks/useModal';
import { useDialService } from './apps/dialer/hooks/useDialService';
import InjectDebugData from './os/debug/InjectDebugData';
-import { useQuickAccess } from './os/notifications/hooks/useQuickAccess';
import { useSnackbar } from './ui/hooks/useSnackbar';
import { useTranslation } from 'react-i18next';
+import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
function Phone() {
- const quickAccess = useQuickAccess();
+ const { t } = useTranslation();
+ const { alert } = useSnackbar();
+ const { modal } = useModal();
+ const { allApps } = useApps();
+
+ const [settings] = useSettings();
+
+ const {
+ bottom,
+ visibility,
+ uncollapseNotifications,
+ clickEventOverride,
+ } = usePhoneVisibility();
+
useNuiService();
usePhoneService();
- const { visibility } = usePhone();
- const { allApps } = useApps();
useSimcardService();
useContactsService();
useTwitterService();
@@ -53,20 +61,12 @@ function Phone() {
usePhotoService();
useCallService();
useDialService();
- const { t } = useTranslation()
-
- const { alert } = useSnackbar();
-
- const { modal } = useModal(); // the calling modal
-
- const [settings] = useRecoilState(settingsState);
const currentTheme = useMemo(
() => createMuiTheme(config.themes[settings.theme]),
[settings.theme]
);
-
document.onkeyup = function (data) {
if (data.which === 27) {
Nui.send('phone:close');
@@ -79,10 +79,12 @@ function Phone() {
<>
-
({
- key: qa.id,
- icon: (
-
- ),
- }))}
- />
+
- {modal ? (
-
- ) : (
- <>
-
- {allApps.map((App) => (
-
- ))}
- >
- )}
- {alert ? (
-
+ ) : (
+ <>
+
+ {allApps.map((App) => (
+
+ ))}
+ >
+ )}
+ {alert ? (
+
-
- {t("APPS_"+alert.message)}
-
-
- ) : null}
+ alignItems: 'center',
+ }}
+ >
+
+ {t('APPS_' + alert.message)}
+
+
+ ) : null}
>
diff --git a/phone/src/apps/home/components/Home.tsx b/phone/src/apps/home/components/Home.tsx
index 92eca40..b6448fd 100644
--- a/phone/src/apps/home/components/Home.tsx
+++ b/phone/src/apps/home/components/Home.tsx
@@ -5,11 +5,11 @@ import { GridMenu } from '../../../ui/components/GridMenu';
import { useApps } from '../../../os/apps/hooks/useApps';
export const HomeApp = () => {
- const { apps } = useApps();
+ const { allApps } = useApps();
return (
- {apps && }
+ {allApps && }
);
diff --git a/phone/src/apps/settings/hooks/useSettings.ts b/phone/src/apps/settings/hooks/useSettings.ts
index 4b2114f..86eae75 100644
--- a/phone/src/apps/settings/hooks/useSettings.ts
+++ b/phone/src/apps/settings/hooks/useSettings.ts
@@ -22,7 +22,15 @@ export const settingsState = atom({
effects_UNSTABLE: [localStorageEffect('settings')],
});
+interface IPhoneSettings {
+ wallpaper: string;
+ frame: string;
+ theme: string;
+ zoom: number;
+ ringtone: string;
+ ringtoneVol: number;
+}
+
export const useSettings = () => {
- const [settings, setSettings] = useRecoilState(settingsState);
- return [settings, setSettings];
+ return useRecoilState
(settingsState);
};
diff --git a/phone/src/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx
index 11c2573..0547669 100644
--- a/phone/src/apps/twitter/components/TwitterApp.tsx
+++ b/phone/src/apps/twitter/components/TwitterApp.tsx
@@ -33,6 +33,30 @@ InjectDebugData([
avatar_url: 'https://i.tasoagc.dev/i9Ig',
},
},
+ {
+ app: 'TWITTER',
+ method: 'createTweetBroadcast',
+ data: {
+ id: 111,
+ profile_id: 111,
+ profile_name: 'Kidz',
+ isMine: false,
+ isReported: false,
+ message: 'I have tweeted this because Im badass'
+ }
+ },
+ {
+ app: 'TWITTER',
+ method: 'createTweetBroadcast',
+ data: {
+ id: 111,
+ profile_id: 111,
+ profile_name: 'ItsChip',
+ isMine: false,
+ isReported: false,
+ message: 'I have tweeted this because Im even more badass'
+ }
+ },
{
app: 'TWITTER',
method: 'fetchTweets',
diff --git a/phone/src/apps/twitter/hooks/useTwitterService.ts b/phone/src/apps/twitter/hooks/useTwitterService.ts
index 0af8c1e..d94a7d0 100644
--- a/phone/src/apps/twitter/hooks/useTwitterService.ts
+++ b/phone/src/apps/twitter/hooks/useTwitterService.ts
@@ -5,6 +5,10 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { IMAGE_DELIMITER } from '../utils/images';
import { APP_TWITTER } from '../utils/constants';
import { twitterState } from './state';
+import { useNotifications } from '../../../os/notifications/hooks/useNotifications';
+import { useApp } from '../../../os/apps/hooks/useApps';
+import { useTranslation } from 'react-i18next';
+import { useCallback } from 'react';
/**
* Perform all necessary processing/transforms from the raw database
@@ -28,6 +32,23 @@ function processTweet(tweet) {
* there and have moved that logic here instead.
*/
export const useTwitterService = () => {
+ const { t } = useTranslation();
+ const { addNotification } = useNotifications();
+ const { icon, notificationIcon } = useApp('TWITTER');
+
+ const setNotification = useCallback(
+ ({ profile_name, message }) =>
+ addNotification({
+ app: 'TWITTER',
+ title: t('APPS_TWITTER_NEW_BROADCAST', { profile_name }),
+ href: '/twitter',
+ content: message,
+ icon,
+ notificationIcon,
+ }),
+ [addNotification, icon, notificationIcon, t]
+ );
+
const setProfile = useSetRecoilState(twitterState.profile);
const setUpdateProfileLoading = useSetRecoilState(
twitterState.updateProfileLoading
@@ -41,7 +62,6 @@ export const useTwitterService = () => {
const setCreateSuccess = useSetRecoilState(
twitterState.createTweetSuccessful
);
- const setNotification = useSetRecoilState(twitterState.notification);
const _setUpdateProfileSuccess = (isSuccessful) => {
setUpdateProfileSuccess(isSuccessful);
diff --git a/phone/src/config/default.json b/phone/src/config/default.json
index 85f671f..c748c01 100644
--- a/phone/src/config/default.json
+++ b/phone/src/config/default.json
@@ -14,7 +14,15 @@
"printDebugLogs": true,
"logLevel": 1
},
- "frames": ["default.png", "blue.png", "gold.png", "kawaii.png", "minimal.png", "pink.png", "white.png"],
+ "frames": [
+ "default.png",
+ "blue.png",
+ "gold.png",
+ "kawaii.png",
+ "minimal.png",
+ "pink.png",
+ "white.png"
+ ],
"zoomOptions": [1, 0.9, 0.8],
"ringtones": ["marimba", "pixel"],
"themes": {
diff --git a/phone/src/index.tsx b/phone/src/index.tsx
index 8d1fcef..1834931 100644
--- a/phone/src/index.tsx
+++ b/phone/src/index.tsx
@@ -10,7 +10,8 @@ import Phone from './Phone';
import TwitterNotification from './apps/twitter/components/notification/TwitterNotification';
import { BankNotification } from './apps/bank/components/notification/BankNotification';
import PhoneConfig from './config/default.json';
-import SnackbarProvider from './ui/components/SnackbarProvider';
+import SnackbarProvider from './ui/providers/SnackbarProvider';
+import { NotificationsProvider } from './os/notifications/providers/NotificationsProvider';
// Enable Sentry when config setting is true
if (PhoneConfig.SentryErrorMetrics) {
@@ -31,7 +32,9 @@ ReactDOM.render(
-
+
+
+
,
diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json
index 9e8e908..0c39a35 100644
--- a/phone/src/locale/en.json
+++ b/phone/src/locale/en.json
@@ -47,6 +47,7 @@
"APPS_TWITTER_TIME_MINUTES": "m",
"APPS_TWITTER_TIME_HOURS": "h",
"APPS_TWITTER_TIME_DAYS": "d",
+ "APPS_TWITTER_NEW_BROADCAST": "New tweet from @{{ profile_name }}!",
"APPS_BANK_HOME_TITLE": "Welcome",
"APPS_BANK_ACCOUNT_LINK": "Account",
diff --git a/phone/src/os/apps/hooks/useApps.tsx b/phone/src/os/apps/hooks/useApps.tsx
index fdfbe24..7eeba8b 100644
--- a/phone/src/os/apps/hooks/useApps.tsx
+++ b/phone/src/os/apps/hooks/useApps.tsx
@@ -1,4 +1,4 @@
-import React, {useCallback, useEffect, useMemo} from 'react';
+import React, { useCallback, useEffect, useMemo } from 'react';
import {
blue,
common,
@@ -37,7 +37,8 @@ import { ExampleApp } from '../../../apps/example/components/ExampleApp';
import { SelloutApp } from '../../../apps/sellout/components/SelloutApp';
import { NotesApp } from '../../../apps/notes/NotesApp';
import CameraApp from '../../../apps/camera/components/CameraApp';
-import Nui from "../../nui-events/utils/Nui";
+import Nui from '../../nui-events/utils/Nui';
+import { useNotifications } from '../../notifications/hooks/useNotifications';
export interface IAppConfig {
id: string;
@@ -63,7 +64,11 @@ const AppRoute = ({ id, component: Component, ...rest }) => {
return (
}
+ render={() => (
+
+
+
+ )}
/>
);
};
@@ -80,7 +85,9 @@ const appsState = atom({
backgroundColor: green[600],
color: common.white,
path: '/phone',
- Route: () => ,
+ Route: () => (
+
+ ),
},
{
id: 'MESSAGES',
@@ -90,37 +97,49 @@ const appsState = atom({
backgroundColor: amber[700],
color: common.white,
path: '/messages',
- Route: () => ,
+ Route: () => (
+
+ ),
},
{
id: 'CONTACTS',
nameLocale: 'APPS_CONTACTS',
icon: ,
- notificationIcon: ,
+ notificationIcon: ,
backgroundColor: blue[500],
color: common.white,
path: '/contacts',
- Route: () => ,
+ Route: () => (
+
+ ),
},
{
id: 'CALCULATOR',
nameLocale: 'APPS_CALCULATOR',
icon: ,
- notificationIcon: ,
+ notificationIcon: ,
backgroundColor: purple[500],
color: grey[50],
path: '/calculator',
- Route: () => ,
+ Route: () => (
+
+ ),
},
{
id: 'SETTINGS',
nameLocale: 'APPS_SETTINGS',
icon: ,
- notificationIcon: ,
+ notificationIcon: ,
backgroundColor: '#383838',
color: grey[50],
path: '/settings',
- Route: () => ,
+ Route: () => (
+
+ ),
},
{
id: 'BANK',
@@ -130,37 +149,45 @@ const appsState = atom({
backgroundColor: blue[900],
color: common.white,
path: '/bank',
- Route: () => ,
+ Route: () => ,
},
{
id: 'TWITTER',
nameLocale: 'APPS_TWITTER',
icon: ,
- notificationIcon: ,
+ notificationIcon: (
+
+ ),
backgroundColor: blue[600],
color: common.white,
path: '/twitter',
- Route: () => ,
+ Route: () => (
+
+ ),
},
{
id: 'SELLOUT',
nameLocale: 'APPS_SELLOUT',
icon: ,
- notificationIcon: ,
+ notificationIcon: ,
backgroundColor: red[500],
color: common.white,
path: '/sellout',
- Route: () => ,
+ Route: () => (
+
+ ),
},
{
id: 'NOTES',
nameLocale: 'APPS_NOTES',
icon: ,
- notificationIcon: ,
+ notificationIcon: (
+
+ ),
backgroundColor: yellow[800],
color: common.white,
path: '/notes',
- Route: () => ,
+ Route: () => ,
},
{
id: 'CAMERA',
@@ -170,7 +197,9 @@ const appsState = atom({
backgroundColor: grey['A400'],
color: common.white,
path: '/camera',
- Route: () => ,
+ Route: () => (
+
+ ),
},
{
id: 'EXAMPLE',
@@ -180,16 +209,29 @@ const appsState = atom({
backgroundColor: blue[500],
color: blue[50],
path: '/example',
- Route: () => ,
+ Route: () => (
+
+ ),
},
],
},
});
export const useApps = () => {
+ const { icons } = useNotifications();
const [apps, setApps] = useRecoilState(appsState);
- const allApps = useMemo(() => [...apps.preinstalled], [apps.preinstalled]);
- const getApp = useCallback((id: string): IAppConfig => allApps.find((a) => a.id === id) || null, [allApps]);
+ const allApps = useMemo(
+ () =>
+ [...apps.preinstalled].map((a) => ({
+ ...a,
+ notification: icons.find((i) => i.key === a.id),
+ })),
+ [apps.preinstalled, icons]
+ );
+ const getApp = useCallback(
+ (id: string): IAppConfig => allApps.find((a) => a.id === id) || null,
+ [allApps]
+ );
return { apps, allApps, setApps, getApp };
};
diff --git a/phone/src/os/notifications/components/NotificationBar.tsx b/phone/src/os/notifications/components/NotificationBar.tsx
index 07c963d..dc29719 100644
--- a/phone/src/os/notifications/components/NotificationBar.tsx
+++ b/phone/src/os/notifications/components/NotificationBar.tsx
@@ -1,8 +1,25 @@
-import React from 'react';
-import { makeStyles, Typography, Grid, IconButton } from '@material-ui/core';
+import React, { useState } from 'react';
+import {
+ makeStyles,
+ Typography,
+ Grid,
+ IconButton,
+ Slide,
+ Paper,
+ Box,
+ List,
+ ListItem,
+ ListItemText,
+ Divider,
+ ListItemAvatar,
+} from '@material-ui/core';
import SignalIcon from '@material-ui/icons/SignalCellular3Bar';
+import CloseIcon from '@material-ui/icons/Close';
import Battery90Icon from '@material-ui/icons/Battery90';
+import ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp';
import Default from '../../../config/default.json';
+import { useNotifications } from '../hooks/useNotifications';
+import { useHistory } from 'react-router-dom';
const useStyles = makeStyles((theme) => ({
root: {
@@ -10,9 +27,13 @@ const useStyles = makeStyles((theme) => ({
height: '30px',
width: '100%',
color: theme.palette.text.primary,
- zIndex: 2,
+ zIndex: 10,
paddingLeft: '15px',
paddingRight: '10px',
+ position: 'relative',
+ '&:hover': {
+ cursor: 'pointer',
+ },
},
item: {
margin: '0 6px',
@@ -26,53 +47,128 @@ const useStyles = makeStyles((theme) => ({
padding: '4px',
color: theme.palette.text.primary,
},
+ drawer: {
+ backgroundColor: theme.palette.background.default,
+ width: '100%',
+ position: 'absolute',
+ top: '30px',
+ zIndex: 9,
+ },
+ closeNotifBtn: {
+ position: 'absolute',
+ right: '8px',
+ top: '8px',
+ },
+ notificationItem: {
+ position: 'relative',
+ },
+ collapseBtn: {
+ margin: '0 auto',
+ },
}));
-interface INotification {
- key: string;
- icon: JSX.Element;
-}
-
-interface IProps {
- notifications?: INotification[];
-}
-
-export const NotificationBar = ({ notifications = [] }: IProps) => {
+export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean }) => {
const classes = useStyles();
+ const history = useHistory();
+
+ const { icons, notifications, removeNotification } = useNotifications();
+
+ const [uncollapsed, setUncollapsed] = useState(false);
+
return (
-
-
- {notifications.map((notification) => (
-
- {notification.icon}
+ <>
+ {
+ setUncollapsed(!uncollapsed);
+ }}
+ >
+
+ {icons.map((notifIcon) => (
+
+ {notifIcon.icon}
+
+ ))}
+
+
+
+
+
+
+
+ {Default.cellProvider}
+
+
+
+
- ))}
-
-
-
-
-
-
-
- {Default.cellProvider}
-
-
-
-
-
+
+
+
+
+
+ {notifications.map(({ href, title, content, icon }, idx) => (
+ {
+ if (href) {
+ history.push(href);
+ setUncollapsed(false);
+ removeNotification(idx);
+ }
+ }}
+ className={classes.notificationItem}
+ key={idx}
+ >
+ {icon && {icon}}
+ {title}
+ {
+ e.stopPropagation();
+ if (notifications.length === 1) {
+ setUncollapsed(false);
+ }
+ removeNotification(idx);
+ }}
+ >
+
+
+
+ ))}
+
+
+
+ setUncollapsed(false)}
+ >
+
+
+
+
+
+ >
);
};
diff --git a/phone/src/os/notifications/hooks/useNotifications.tsx b/phone/src/os/notifications/hooks/useNotifications.tsx
new file mode 100644
index 0000000..89bf34e
--- /dev/null
+++ b/phone/src/os/notifications/hooks/useNotifications.tsx
@@ -0,0 +1,12 @@
+import { useContext } from 'react';
+import { NotificationsContext } from '../providers/NotificationsProvider';
+
+export const useNotifications = () => {
+ const context = useContext(NotificationsContext);
+ if (!context) {
+ throw new Error(
+ 'useNotifications must be wrapped by NotificationsProvider'
+ );
+ }
+ return context;
+};
diff --git a/phone/src/os/notifications/providers/NotificationsProvider.tsx b/phone/src/os/notifications/providers/NotificationsProvider.tsx
new file mode 100644
index 0000000..dacd9c5
--- /dev/null
+++ b/phone/src/os/notifications/providers/NotificationsProvider.tsx
@@ -0,0 +1,81 @@
+import React, { createContext, useState, useCallback, useMemo } from 'react';
+
+export interface INotification {
+ app: string;
+ title: string;
+ content?: React.ReactNode;
+ icon?: JSX.Element;
+ notificationIcon?: JSX.Element;
+ href?: string;
+}
+
+interface INotificationIcon {
+ key: string;
+ icon: JSX.Element;
+ badge: number;
+}
+
+export const NotificationsContext = createContext<{
+ notifications: INotification[];
+ icons: INotificationIcon[];
+ count: number;
+ addNotification(value: INotification): void;
+ updateNotification(idx: number, value: INotification): void;
+ removeNotification(idx: number): void;
+}>(null);
+
+export function NotificationsProvider({ children }) {
+ const [notifications, setNotifications] = useState([]);
+
+ const updateNotification = useCallback(
+ (idx: number, value: INotification) => {
+ setNotifications((all) => {
+ const updated = [...all];
+ updated.splice(idx, 0, value);
+ return updated;
+ });
+ },
+ []
+ );
+
+ const removeNotification = useCallback((idx) => {
+ setNotifications((all) => {
+ const updated = [...all];
+ updated.splice(idx, 1);
+ return updated;
+ });
+ }, []);
+
+ const addNotification = useCallback((value: INotification) => {
+ setNotifications((all) => [value, ...all]);
+ }, []);
+
+ const icons: INotificationIcon[] = useMemo(
+ () =>
+ notifications.reduce((icons, curr) => {
+ const find = icons.findIndex((i) => i.key === curr.app);
+ if (find !== -1) {
+ icons[find].badge++;
+ return icons;
+ }
+ icons.unshift({ key: curr.app, icon: curr.notificationIcon, badge: 1 });
+ return icons;
+ }, []),
+ [notifications]
+ );
+
+ return (
+
+ {children}
+
+ );
+}
diff --git a/phone/src/os/phone/hooks/usePhone.ts b/phone/src/os/phone/hooks/usePhone.ts
index 675944e..fee582e 100644
--- a/phone/src/os/phone/hooks/usePhone.ts
+++ b/phone/src/os/phone/hooks/usePhone.ts
@@ -1,14 +1,15 @@
-import { useRecoilValue } from 'recoil';
+import { useRecoilState } from 'recoil';
import { phoneState } from './state';
import { IServerConfig } from '../../../common/typings/config';
import ServerConfig from '../../../config.autogen.json';
interface IUsePhone {
visibility: boolean;
+ setVisibility(v: boolean): void;
config?: IServerConfig;
}
export const usePhone = (): IUsePhone => {
- const visibility = useRecoilValue(phoneState.visibility);
- return { visibility, config: ServerConfig as any };
+ const [visibility, setVisibility] = useRecoilState(phoneState.visibility);
+ return { visibility, setVisibility, config: ServerConfig as any };
};
diff --git a/phone/src/os/phone/hooks/usePhoneService.ts b/phone/src/os/phone/hooks/usePhoneService.ts
index 78faa4e..de43871 100644
--- a/phone/src/os/phone/hooks/usePhoneService.ts
+++ b/phone/src/os/phone/hooks/usePhoneService.ts
@@ -1,12 +1,10 @@
import { useSetRecoilState } from 'recoil';
import { phoneState } from './state';
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
-import { usePhone } from './usePhone';
export const usePhoneService = () => {
const setVisibility = useSetRecoilState(phoneState.visibility);
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
useNuiEvent('PHONE', 'setVisibility', setVisibility);
useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
- return usePhone();
};
diff --git a/phone/src/os/phone/hooks/usePhoneVisibility.ts b/phone/src/os/phone/hooks/usePhoneVisibility.ts
new file mode 100644
index 0000000..f75f33a
--- /dev/null
+++ b/phone/src/os/phone/hooks/usePhoneVisibility.ts
@@ -0,0 +1,56 @@
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
+import { useSettings } from '../../../apps/settings/hooks/useSettings';
+import { useNotifications } from '../../notifications/hooks/useNotifications';
+import { usePhone } from './usePhone';
+
+export const usePhoneVisibility = () => {
+ const { setVisibility, visibility } = usePhone();
+ const { count } = useNotifications();
+ const [{ zoom }] = useSettings();
+
+ const [notifVisibility, setNotifVisibility] = useState(false);
+
+ const isNotificationVisibleOnly = useMemo(
+ () => !!(!visibility && count > 0),
+ [visibility, count]
+ );
+
+ const notificationTimer = useRef();
+
+ useEffect(() => {
+ if (isNotificationVisibleOnly) {
+ setNotifVisibility(true);
+ clearTimeout(notificationTimer.current);
+ notificationTimer.current = setTimeout(() => {
+ setVisibility(false);
+ setNotifVisibility(false);
+ }, 5000);
+ }
+ return () => clearTimeout(notificationTimer.current);
+ }, [isNotificationVisibleOnly, setVisibility]);
+
+ const bottom = useMemo(() => {
+ if (isNotificationVisibleOnly) {
+ return `calc(-60% * ${zoom})`;
+ }
+ return 0;
+ }, [isNotificationVisibleOnly, zoom]);
+
+ const clickEventOverride = useCallback(
+ (e) => {
+ if (isNotificationVisibleOnly) {
+ e.preventDefault();
+ e.stopPropagation();
+ setVisibility(true);
+ }
+ },
+ [setVisibility, isNotificationVisibleOnly]
+ );
+
+ return {
+ bottom,
+ visibility: notifVisibility,
+ uncollapseNotifications: isNotificationVisibleOnly,
+ clickEventOverride,
+ };
+};
diff --git a/phone/src/ui/components/AppIcon.tsx b/phone/src/ui/components/AppIcon.tsx
index 1504d52..e1b9b7d 100644
--- a/phone/src/ui/components/AppIcon.tsx
+++ b/phone/src/ui/components/AppIcon.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Avatar from '@material-ui/core/Avatar';
import { green } from '@material-ui/core/colors';
-import { Button } from '@material-ui/core';
+import { Badge, Button } from '@material-ui/core';
interface IStyles {
root: any;
@@ -28,7 +28,13 @@ const useStyles = makeStyles(
})
);
-export const AppIcon = ({ id, name, icon, backgroundColor, color }) => {
+export const AppIcon = ({
+ name,
+ icon,
+ backgroundColor,
+ color,
+ notification,
+}) => {
const classes = useStyles({
backgroundColor: backgroundColor || green[50],
color: color || green[400],
@@ -36,9 +42,15 @@ export const AppIcon = ({ id, name, icon, backgroundColor, color }) => {
return (
);
};
diff --git a/phone/src/ui/hooks/useSnackbar.ts b/phone/src/ui/hooks/useSnackbar.ts
index 7433cc6..0dc7588 100644
--- a/phone/src/ui/hooks/useSnackbar.ts
+++ b/phone/src/ui/hooks/useSnackbar.ts
@@ -1,5 +1,5 @@
import { useContext } from 'react';
-import { SnackbarContext } from '../components/SnackbarProvider';
+import { SnackbarContext } from '../providers/SnackbarProvider';
export interface IAlert {
diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/providers/SnackbarProvider.tsx
similarity index 63%
rename from phone/src/ui/components/SnackbarProvider.tsx
rename to phone/src/ui/providers/SnackbarProvider.tsx
index 46ce55c..c1fe553 100644
--- a/phone/src/ui/components/SnackbarProvider.tsx
+++ b/phone/src/ui/providers/SnackbarProvider.tsx
@@ -8,26 +8,21 @@ function SnackbarProvider({ children }) {
useEffect(() => {
if (alert) {
- clearTimeout(timer.current)
+ clearTimeout(timer.current);
timer.current = setTimeout(() => {
- setAlert(null)
+ setAlert(null);
}, 1000);
}
- return () => clearTimeout(timer.current)
+ return () => clearTimeout(timer.current);
}, [alert]);
-
const addAlert = (value) => setAlert(value);
- const value = { addAlert, alert }
-
return (
-
- <>
- {children}
- >
+
+ {children}
- )
+ );
}
-export default SnackbarProvider;
\ No newline at end of file
+export default SnackbarProvider;