mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 22:16:54 +00:00
Feature / Add working notifications with only twitter for now (#102)
* Add working notifications with only twitter for now * feat(notification-bar): I didnt copy from NP * Make default browser visibility true * feat(notifications): Collapse when no more notifications after closing one
This commit is contained in:
1 parent
11af8bfb5a
commit
40ec19a349
19 files changed
+497
-153
No files matched your search
+2
-9
@@ -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);
|
||||
}
|
||||
+41
-47
@@ -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() {
|
||||
<div className='PhoneWrapper'>
|
||||
<div>
|
||||
<div
|
||||
onClick={clickEventOverride}
|
||||
className='Phone'
|
||||
style={{
|
||||
transformOrigin: 'right bottom',
|
||||
transform: `scale(${settings.zoom}`,
|
||||
bottom,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
@@ -99,40 +101,32 @@ function Phone() {
|
||||
}}
|
||||
>
|
||||
<>
|
||||
<NotificationBar
|
||||
notifications={quickAccess.map((qa) => ({
|
||||
key: qa.id,
|
||||
icon: (
|
||||
<NotificationIcon
|
||||
icon={qa.notificationIcon}
|
||||
to={qa.path}
|
||||
/>
|
||||
),
|
||||
}))}
|
||||
/>
|
||||
<NotificationBar forceUncollapse={uncollapseNotifications} />
|
||||
<div className='PhoneAppContainer'>
|
||||
{modal ? (
|
||||
<CallModal />
|
||||
) : (
|
||||
<>
|
||||
<Route exact path='/' component={HomeApp} />
|
||||
{allApps.map((App) => (
|
||||
<App.Route key={App.id} />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
{alert ? (
|
||||
<div style={{
|
||||
{modal ? (
|
||||
<CallModal />
|
||||
) : (
|
||||
<>
|
||||
<Route exact path='/' component={HomeApp} />
|
||||
{allApps.map((App) => (
|
||||
<App.Route key={App.id} />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
{alert ? (
|
||||
<div
|
||||
style={{
|
||||
marginTop: '-100px',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center'
|
||||
}}>
|
||||
<Alert severity={alert.type} variant="filled">
|
||||
{t("APPS_"+alert.message)}
|
||||
</Alert>
|
||||
</div>
|
||||
) : null}
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
<Alert severity={alert.type} variant='filled'>
|
||||
{t('APPS_' + alert.message)}
|
||||
</Alert>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<Navigation />
|
||||
</>
|
||||
|
||||
@@ -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 (
|
||||
<AppWrapper>
|
||||
<Box width='100%' mt={6} px={1}>
|
||||
{apps && <GridMenu items={apps.preinstalled} />}
|
||||
{allApps && <GridMenu items={allApps} />}
|
||||
</Box>
|
||||
</AppWrapper>
|
||||
);
|
||||
|
||||
@@ -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<IPhoneSettings>(settingsState);
|
||||
};
|
||||
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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": {
|
||||
|
||||
+5
-2
@@ -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(
|
||||
<TwitterNotification />
|
||||
<BankNotification />
|
||||
<SnackbarProvider>
|
||||
<Phone />
|
||||
<NotificationsProvider>
|
||||
<Phone />
|
||||
</NotificationsProvider>
|
||||
</SnackbarProvider>
|
||||
</RecoilRoot>
|
||||
</HashRouter>,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 (
|
||||
<Route
|
||||
{...rest}
|
||||
render={() => <AppWithStartup id={id}><Component /></AppWithStartup>}
|
||||
render={() => (
|
||||
<AppWithStartup id={id}>
|
||||
<Component />
|
||||
</AppWithStartup>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -80,7 +85,9 @@ const appsState = atom<AppsRepository>({
|
||||
backgroundColor: green[600],
|
||||
color: common.white,
|
||||
path: '/phone',
|
||||
Route: () => <AppRoute id="DIALER" path='/phone' component={DialerApp} />,
|
||||
Route: () => (
|
||||
<AppRoute id='DIALER' path='/phone' component={DialerApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'MESSAGES',
|
||||
@@ -90,37 +97,49 @@ const appsState = atom<AppsRepository>({
|
||||
backgroundColor: amber[700],
|
||||
color: common.white,
|
||||
path: '/messages',
|
||||
Route: () => <AppRoute id="MESSAGE" path='/messages' component={MessagesApp} />,
|
||||
Route: () => (
|
||||
<AppRoute id='MESSAGE' path='/messages' component={MessagesApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'CONTACTS',
|
||||
nameLocale: 'APPS_CONTACTS',
|
||||
icon: <ContactsIcon />,
|
||||
notificationIcon: <ContactsIcon fontSize="small" />,
|
||||
notificationIcon: <ContactsIcon fontSize='small' />,
|
||||
backgroundColor: blue[500],
|
||||
color: common.white,
|
||||
path: '/contacts',
|
||||
Route: () => <AppRoute id="CONTACTS" path='/contacts' component={ContactsApp} />,
|
||||
Route: () => (
|
||||
<AppRoute id='CONTACTS' path='/contacts' component={ContactsApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'CALCULATOR',
|
||||
nameLocale: 'APPS_CALCULATOR',
|
||||
icon: <CalculatorIcon />,
|
||||
notificationIcon: <CalculatorIcon fontSize="small"/>,
|
||||
notificationIcon: <CalculatorIcon fontSize='small' />,
|
||||
backgroundColor: purple[500],
|
||||
color: grey[50],
|
||||
path: '/calculator',
|
||||
Route: () => <AppRoute id="CALCULATOR" path='/calculator' component={CalculatorApp} />,
|
||||
Route: () => (
|
||||
<AppRoute
|
||||
id='CALCULATOR'
|
||||
path='/calculator'
|
||||
component={CalculatorApp}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'SETTINGS',
|
||||
nameLocale: 'APPS_SETTINGS',
|
||||
icon: <SettingsIcon />,
|
||||
notificationIcon: <SettingsIcon fontSize="small"/>,
|
||||
notificationIcon: <SettingsIcon fontSize='small' />,
|
||||
backgroundColor: '#383838',
|
||||
color: grey[50],
|
||||
path: '/settings',
|
||||
Route: () => <AppRoute id="SETTINGS" path='/settings' component={SettingsApp} />,
|
||||
Route: () => (
|
||||
<AppRoute id='SETTINGS' path='/settings' component={SettingsApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'BANK',
|
||||
@@ -130,37 +149,45 @@ const appsState = atom<AppsRepository>({
|
||||
backgroundColor: blue[900],
|
||||
color: common.white,
|
||||
path: '/bank',
|
||||
Route: () => <AppRoute id="BANK" path='/bank' component={BankApp} />,
|
||||
Route: () => <AppRoute id='BANK' path='/bank' component={BankApp} />,
|
||||
},
|
||||
{
|
||||
id: 'TWITTER',
|
||||
nameLocale: 'APPS_TWITTER',
|
||||
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
|
||||
notificationIcon: (
|
||||
<FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />
|
||||
),
|
||||
backgroundColor: blue[600],
|
||||
color: common.white,
|
||||
path: '/twitter',
|
||||
Route: () => <AppRoute id="TWITTER" path='/twitter' component={TwitterApp} />,
|
||||
Route: () => (
|
||||
<AppRoute id='TWITTER' path='/twitter' component={TwitterApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'SELLOUT',
|
||||
nameLocale: 'APPS_SELLOUT',
|
||||
icon: <FontAwesomeIcon icon={faAd} fixedWidth />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faAd} fixedWidth size="xs" />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faAd} fixedWidth size='xs' />,
|
||||
backgroundColor: red[500],
|
||||
color: common.white,
|
||||
path: '/sellout',
|
||||
Route: () => <AppRoute id="SELLOUT" path='/sellout' component={SelloutApp} />,
|
||||
Route: () => (
|
||||
<AppRoute id='SELLOUT' path='/sellout' component={SelloutApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'NOTES',
|
||||
nameLocale: 'APPS_NOTES',
|
||||
icon: <FontAwesomeIcon icon={faStickyNote} fixedWidth />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faStickyNote} fixedWidth size="xs" />,
|
||||
notificationIcon: (
|
||||
<FontAwesomeIcon icon={faStickyNote} fixedWidth size='xs' />
|
||||
),
|
||||
backgroundColor: yellow[800],
|
||||
color: common.white,
|
||||
path: '/notes',
|
||||
Route: () => <AppRoute id="NOTES" path='/notes' component={NotesApp} />,
|
||||
Route: () => <AppRoute id='NOTES' path='/notes' component={NotesApp} />,
|
||||
},
|
||||
{
|
||||
id: 'CAMERA',
|
||||
@@ -170,7 +197,9 @@ const appsState = atom<AppsRepository>({
|
||||
backgroundColor: grey['A400'],
|
||||
color: common.white,
|
||||
path: '/camera',
|
||||
Route: () => <AppRoute id="CAMERA" path='/camera' component={CameraApp} />,
|
||||
Route: () => (
|
||||
<AppRoute id='CAMERA' path='/camera' component={CameraApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'EXAMPLE',
|
||||
@@ -180,16 +209,29 @@ const appsState = atom<AppsRepository>({
|
||||
backgroundColor: blue[500],
|
||||
color: blue[50],
|
||||
path: '/example',
|
||||
Route: () => <AppRoute id="EXAMPLE" path='/example' component={ExampleApp}/>,
|
||||
Route: () => (
|
||||
<AppRoute id='EXAMPLE' path='/example' component={ExampleApp} />
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
export const useApps = () => {
|
||||
const { icons } = useNotifications();
|
||||
const [apps, setApps] = useRecoilState<AppsRepository>(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 };
|
||||
};
|
||||
|
||||
|
||||
@@ -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<boolean>(false);
|
||||
|
||||
return (
|
||||
<Grid
|
||||
className={classes.root}
|
||||
container
|
||||
justify='space-between'
|
||||
wrap='nowrap'
|
||||
>
|
||||
<Grid container item wrap='nowrap'>
|
||||
{notifications.map((notification) => (
|
||||
<Grid
|
||||
item
|
||||
key={notification.key}
|
||||
component={IconButton}
|
||||
className={classes.icon}
|
||||
>
|
||||
{notification.icon}
|
||||
<>
|
||||
<Grid
|
||||
className={classes.root}
|
||||
container
|
||||
justify='space-between'
|
||||
wrap='nowrap'
|
||||
onClick={() => {
|
||||
setUncollapsed(!uncollapsed);
|
||||
}}
|
||||
>
|
||||
<Grid container item wrap='nowrap'>
|
||||
{icons.map((notifIcon) => (
|
||||
<Grid
|
||||
item
|
||||
key={notifIcon.key}
|
||||
component={IconButton}
|
||||
className={classes.icon}
|
||||
>
|
||||
{notifIcon.icon}
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
<Grid
|
||||
container
|
||||
item
|
||||
wrap='nowrap'
|
||||
justify='flex-end'
|
||||
alignItems='center'
|
||||
>
|
||||
<Grid item>
|
||||
<SignalIcon fontSize='small' />
|
||||
</Grid>
|
||||
<Grid item className={classes.item}>
|
||||
<Typography className={classes.text} variant='button'>
|
||||
{Default.cellProvider}
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Battery90Icon
|
||||
style={{ transform: 'rotate(90deg)', display: 'block' }}
|
||||
/>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
<Grid container item wrap='nowrap' justify='flex-end' alignItems='center'>
|
||||
<Grid item>
|
||||
<SignalIcon fontSize='small' />
|
||||
</Grid>
|
||||
<Grid item className={classes.item}>
|
||||
<Typography className={classes.text} variant='button'>
|
||||
{Default.cellProvider}
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item>
|
||||
<Battery90Icon
|
||||
style={{ transform: 'rotate(90deg)', display: 'block' }}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Slide direction='down' in={forceUncollapse || uncollapsed}>
|
||||
<Paper square className={classes.drawer}>
|
||||
<Box p={2}>
|
||||
<List>
|
||||
<Divider />
|
||||
{notifications.map(({ href, title, content, icon }, idx) => (
|
||||
<ListItem
|
||||
divider
|
||||
button
|
||||
onClick={() => {
|
||||
if (href) {
|
||||
history.push(href);
|
||||
setUncollapsed(false);
|
||||
removeNotification(idx);
|
||||
}
|
||||
}}
|
||||
className={classes.notificationItem}
|
||||
key={idx}
|
||||
>
|
||||
{icon && <ListItemAvatar>{icon}</ListItemAvatar>}
|
||||
<ListItemText secondary={content}>{title}</ListItemText>
|
||||
<IconButton
|
||||
className={classes.closeNotifBtn}
|
||||
size='small'
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (notifications.length === 1) {
|
||||
setUncollapsed(false);
|
||||
}
|
||||
removeNotification(idx);
|
||||
}}
|
||||
>
|
||||
<CloseIcon color='primary' />
|
||||
</IconButton>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</Box>
|
||||
<Box display='flex'>
|
||||
<IconButton
|
||||
className={classes.collapseBtn}
|
||||
size='small'
|
||||
onClick={() => setUncollapsed(false)}
|
||||
>
|
||||
<ArrowDropUpIcon />
|
||||
</IconButton>
|
||||
</Box>
|
||||
</Paper>
|
||||
</Slide>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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<INotification[]>([]);
|
||||
|
||||
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 (
|
||||
<NotificationsContext.Provider
|
||||
value={{
|
||||
notifications,
|
||||
addNotification,
|
||||
updateNotification,
|
||||
removeNotification,
|
||||
icons,
|
||||
count: notifications.length,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</NotificationsContext.Provider>
|
||||
);
|
||||
}
|
||||
@@ -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 };
|
||||
};
|
||||
@@ -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();
|
||||
};
|
||||
@@ -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<boolean>(false);
|
||||
|
||||
const isNotificationVisibleOnly = useMemo(
|
||||
() => !!(!visibility && count > 0),
|
||||
[visibility, count]
|
||||
);
|
||||
|
||||
const notificationTimer = useRef<NodeJS.Timeout>();
|
||||
|
||||
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,
|
||||
};
|
||||
};
|
||||
@@ -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 (
|
||||
<Button className={classes.root}>
|
||||
<Avatar className={classes.avatar}>
|
||||
{icon || name[0].toUpperCase()}
|
||||
</Avatar>
|
||||
<Badge
|
||||
color="error"
|
||||
badgeContent={notification?.badge}
|
||||
invisible={!notification || notification.badge < 2}
|
||||
>
|
||||
<Avatar className={classes.avatar}>
|
||||
{icon || name[0].toUpperCase()}
|
||||
</Avatar>
|
||||
</Badge>
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useContext } from 'react';
|
||||
import { SnackbarContext } from '../components/SnackbarProvider';
|
||||
import { SnackbarContext } from '../providers/SnackbarProvider';
|
||||
|
||||
|
||||
export interface IAlert {
|
||||
|
||||
+7
-12
@@ -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 (
|
||||
<SnackbarContext.Provider value={value}>
|
||||
<>
|
||||
{children}
|
||||
</>
|
||||
<SnackbarContext.Provider value={{ addAlert, alert }}>
|
||||
{children}
|
||||
</SnackbarContext.Provider>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default SnackbarProvider;
|
||||
export default SnackbarProvider;
|
||||
Reference in new issue
Block a user