mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Feature/floating notifications calling and twitter (#112)
* Add floating notifications :O * Add phone notifications and refactor calling ui * This is unsafe * Fix controls null check * Remove go to alert * Fix phone stuck after call * Remove lazy mount for Phone * Fix open/close cl_main * Use effect for notification visibility * Remove all alerts when phone closes * Avoid re-render useNuiEvent * It works now :c
This commit is contained in:
1 parent
4633146d40
commit
f6d7a3dbe1
42 files changed
+825
-635
No files matched your search
+9
-18
@@ -2,9 +2,9 @@ import React from 'react';
|
|||||||
import './Phone.css';
|
import './Phone.css';
|
||||||
import './i18n';
|
import './i18n';
|
||||||
import { Route } from 'react-router-dom';
|
import { Route } from 'react-router-dom';
|
||||||
import { CallModal } from './modal/components/CallModal';
|
import { CallModal } from './os/call/components/CallModal';
|
||||||
import { HomeApp } from './apps/home/components/Home';
|
import { HomeApp } from './apps/home/components/Home';
|
||||||
import { ThemeProvider, Slide } from '@material-ui/core';
|
import { Slide } from '@material-ui/core';
|
||||||
import { useInitKeyboard } from './os/keyboard/hooks/useKeyboard';
|
import { useInitKeyboard } from './os/keyboard/hooks/useKeyboard';
|
||||||
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';
|
||||||
@@ -21,13 +21,13 @@ import { useMessagesService } from './apps/messages/hooks/useMessageService';
|
|||||||
import { useNotesService } from './apps/notes/hooks/useNotesService';
|
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 './modal/hooks/useCallService';
|
import { useCallService } from './os/call/hooks/useCallService';
|
||||||
import { useModal } from './modal/hooks/useModal';
|
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 { usePhoneTheme } from './os/phone/hooks/usePhoneTheme';
|
|
||||||
import { Snackbar } from './ui/components/Snackbar';
|
import { Snackbar } from './ui/components/Snackbar';
|
||||||
|
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
|
||||||
|
|
||||||
function Phone() {
|
function Phone() {
|
||||||
const { modal } = useModal();
|
const { modal } = useModal();
|
||||||
@@ -35,12 +35,7 @@ function Phone() {
|
|||||||
|
|
||||||
const [settings] = useSettings();
|
const [settings] = useSettings();
|
||||||
|
|
||||||
const {
|
const { bottom, visibility } = usePhoneVisibility();
|
||||||
bottom,
|
|
||||||
visibility,
|
|
||||||
uncollapseNotifications,
|
|
||||||
clickEventOverride,
|
|
||||||
} = usePhoneVisibility();
|
|
||||||
|
|
||||||
useNuiService();
|
useNuiService();
|
||||||
usePhoneService();
|
usePhoneService();
|
||||||
@@ -56,15 +51,11 @@ function Phone() {
|
|||||||
useCallService();
|
useCallService();
|
||||||
useDialService();
|
useDialService();
|
||||||
|
|
||||||
const currentTheme = usePhoneTheme();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={currentTheme}>
|
<Slide direction='up' in={visibility}>
|
||||||
<Slide direction='up' in={visibility} mountOnEnter unmountOnExit>
|
|
||||||
<div className='PhoneWrapper'>
|
<div className='PhoneWrapper'>
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
onClick={clickEventOverride}
|
|
||||||
className='Phone'
|
className='Phone'
|
||||||
style={{
|
style={{
|
||||||
transformOrigin: 'right bottom',
|
transformOrigin: 'right bottom',
|
||||||
@@ -86,7 +77,7 @@ function Phone() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<NotificationBar forceUncollapse={uncollapseNotifications} />
|
<NotificationBar />
|
||||||
<div className='PhoneAppContainer'>
|
<div className='PhoneAppContainer'>
|
||||||
{modal ? (
|
{modal ? (
|
||||||
<CallModal />
|
<CallModal />
|
||||||
@@ -98,6 +89,7 @@ function Phone() {
|
|||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
<NotificationAlert />
|
||||||
<Snackbar />
|
<Snackbar />
|
||||||
</div>
|
</div>
|
||||||
<Navigation />
|
<Navigation />
|
||||||
@@ -107,7 +99,6 @@ function Phone() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Slide>
|
</Slide>
|
||||||
</ThemeProvider>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { ThemeProvider } from '@material-ui/core';
|
||||||
|
import { BankNotification } from './apps/bank/components/notification/BankNotification';
|
||||||
|
import { NotificationsProvider } from './os/notifications/providers/NotificationsProvider';
|
||||||
|
import { usePhoneTheme } from './os/phone/hooks/usePhoneTheme';
|
||||||
|
import SnackbarProvider from './ui/providers/SnackbarProvider';
|
||||||
|
import Phone from './Phone';
|
||||||
|
|
||||||
|
export const PhoneContainer = () => {
|
||||||
|
const currentTheme = usePhoneTheme();
|
||||||
|
return (
|
||||||
|
<ThemeProvider theme={currentTheme}>
|
||||||
|
<NotificationsProvider>
|
||||||
|
<BankNotification />
|
||||||
|
<SnackbarProvider>
|
||||||
|
<Phone />
|
||||||
|
</SnackbarProvider>
|
||||||
|
</NotificationsProvider>
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -39,7 +39,7 @@ export const DialerApp = () => {
|
|||||||
|
|
||||||
InjectDebugData([
|
InjectDebugData([
|
||||||
{
|
{
|
||||||
app: 'DAILER',
|
app: 'DIALER',
|
||||||
method: 'setHistory',
|
method: 'setHistory',
|
||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,100 +21,6 @@ import { useProfile } from '../hooks/useProfile';
|
|||||||
import ProfilePrompt from './profile/ProfilePrompt';
|
import ProfilePrompt from './profile/ProfilePrompt';
|
||||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||||
|
|
||||||
InjectDebugData([
|
|
||||||
{
|
|
||||||
app: 'TWITTER',
|
|
||||||
method: 'getOrCreateTwitterProfile',
|
|
||||||
data: {
|
|
||||||
profile_name: 'Angular_Dev',
|
|
||||||
bio: 'Angular FTW',
|
|
||||||
job: 'Googler @ Google',
|
|
||||||
location: '1600 Amphitheatre Parkway, CA, USA',
|
|
||||||
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',
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: 59,
|
|
||||||
message: 'XSS\n<script src="test.js">Test</script>\nBro',
|
|
||||||
avatar_url: 'http://i.tasoagc.dev/jtKL',
|
|
||||||
seconds_since_tweet: 500,
|
|
||||||
isMine: false,
|
|
||||||
updateAt: '2021-02-08 14:37:46',
|
|
||||||
visible: 1,
|
|
||||||
likes: 50000,
|
|
||||||
profile_name: 'jQuery Main',
|
|
||||||
images: 'http://i.tasoagc.dev/0xdp',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
message: 'GCPhone will never die',
|
|
||||||
avatar_url: 'http://i.tasoagc.dev/jtKL',
|
|
||||||
seconds_since_tweet: 500,
|
|
||||||
isMine: false,
|
|
||||||
updateAt: '2021-02-08 14:37:46',
|
|
||||||
visible: 1,
|
|
||||||
likes: 50000,
|
|
||||||
profile_name: 'GCPhone_v9999',
|
|
||||||
images: 'http://i.tasoagc.dev/0xdp',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
message: 'I love angular',
|
|
||||||
avatar_url: 'https://i.tasoagc.dev/i9Ig',
|
|
||||||
seconds_since_tweet: 800,
|
|
||||||
isMine: true,
|
|
||||||
updateAt: '2021-02-08 14:37:46',
|
|
||||||
visible: 1,
|
|
||||||
likes: 50000,
|
|
||||||
profile_name: 'Angular_Dev',
|
|
||||||
images: 'http://i.tasoagc.dev/i9Ig',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
message:
|
|
||||||
'Anyways uhm... I bought a whole bunch of shungite, rocks, ' +
|
|
||||||
'do you know what shungite is? Anybody know what shungite is. No, no ' +
|
|
||||||
'Suge Knight, I think hes locked up in prison.',
|
|
||||||
avatar_url: 'http://i.tasoagc.dev/0v64',
|
|
||||||
seconds_since_tweet: 800,
|
|
||||||
isMine: true,
|
|
||||||
updateAt: '2021-02-08 14:37:46',
|
|
||||||
visible: 1,
|
|
||||||
likes: 50000,
|
|
||||||
profile_name: 'The_Doc',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const useStyles = makeStyles(() => ({
|
const useStyles = makeStyles(() => ({
|
||||||
backgroundModal: {
|
backgroundModal: {
|
||||||
background: 'black',
|
background: 'black',
|
||||||
@@ -188,3 +94,103 @@ export const TwitterApp = () => {
|
|||||||
</AppWrapper>
|
</AppWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
InjectDebugData([
|
||||||
|
{
|
||||||
|
app: 'TWITTER',
|
||||||
|
method: 'getOrCreateTwitterProfile',
|
||||||
|
data: {
|
||||||
|
profile_name: 'Angular_Dev',
|
||||||
|
bio: 'Angular FTW',
|
||||||
|
job: 'Googler @ Google',
|
||||||
|
location: '1600 Amphitheatre Parkway, CA, USA',
|
||||||
|
avatar_url: 'https://i.tasoagc.dev/i9Ig',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
app: 'TWITTER',
|
||||||
|
method: 'fetchTweets',
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: 59,
|
||||||
|
message: 'XSS\n<script src="test.js">Test</script>\nBro',
|
||||||
|
avatar_url: 'http://i.tasoagc.dev/jtKL',
|
||||||
|
seconds_since_tweet: 500,
|
||||||
|
isMine: false,
|
||||||
|
updateAt: '2021-02-08 14:37:46',
|
||||||
|
visible: 1,
|
||||||
|
likes: 50000,
|
||||||
|
profile_name: 'jQuery Main',
|
||||||
|
images: 'http://i.tasoagc.dev/0xdp',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
message: 'GCPhone will never die',
|
||||||
|
avatar_url: 'http://i.tasoagc.dev/jtKL',
|
||||||
|
seconds_since_tweet: 500,
|
||||||
|
isMine: false,
|
||||||
|
updateAt: '2021-02-08 14:37:46',
|
||||||
|
visible: 1,
|
||||||
|
likes: 50000,
|
||||||
|
profile_name: 'GCPhone_v9999',
|
||||||
|
images: 'http://i.tasoagc.dev/0xdp',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
message: 'I love angular',
|
||||||
|
avatar_url: 'https://i.tasoagc.dev/i9Ig',
|
||||||
|
seconds_since_tweet: 800,
|
||||||
|
isMine: true,
|
||||||
|
updateAt: '2021-02-08 14:37:46',
|
||||||
|
visible: 1,
|
||||||
|
likes: 50000,
|
||||||
|
profile_name: 'Angular_Dev',
|
||||||
|
images: 'http://i.tasoagc.dev/i9Ig',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
message:
|
||||||
|
'Anyways uhm... I bought a whole bunch of shungite, rocks, ' +
|
||||||
|
'do you know what shungite is? Anybody know what shungite is. No, no ' +
|
||||||
|
'Suge Knight, I think hes locked up in prison.',
|
||||||
|
avatar_url: 'http://i.tasoagc.dev/0v64',
|
||||||
|
seconds_since_tweet: 800,
|
||||||
|
isMine: true,
|
||||||
|
updateAt: '2021-02-08 14:37:46',
|
||||||
|
visible: 1,
|
||||||
|
likes: 50000,
|
||||||
|
profile_name: 'The_Doc',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
InjectDebugData(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
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',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
2000
|
||||||
|
);
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { shallow } from 'enzyme';
|
|
||||||
import TwitterNotification from './TwitterNotification';
|
|
||||||
|
|
||||||
jest.mock('react-i18next', () => ({
|
|
||||||
useTranslation: () => ({ t: (key) => key }),
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('../../../../os/phone/hooks/usePhone', () => ({
|
|
||||||
usePhone: jest.fn().mockReturnValue({
|
|
||||||
config: {
|
|
||||||
twitter: {
|
|
||||||
showNotifications: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('../../hooks/useTwitterNotification', () => ({
|
|
||||||
useTwitterNotification: jest.fn().mockReturnValue({
|
|
||||||
notification: {
|
|
||||||
profile_name: 'test',
|
|
||||||
message: 'test message',
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('TwitterNotification', () => {
|
|
||||||
let wrapper;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
wrapper = shallow(<TwitterNotification />);
|
|
||||||
});
|
|
||||||
it('renders', () => {
|
|
||||||
expect(wrapper).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders profile name', () => {
|
|
||||||
expect(wrapper.find('.makeStyles-profileName-5').text()).toEqual('@test');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders message', () => {
|
|
||||||
expect(wrapper.find('.makeStyles-message-7').text()).toEqual(
|
|
||||||
'test message'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles';
|
|
||||||
import TwitterIcon from '@material-ui/icons/Twitter';
|
|
||||||
import { useTwitterNotification } from '../../hooks/useTwitterNotification';
|
|
||||||
import Notification from '../../../../ui/components/Notification';
|
|
||||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) =>
|
|
||||||
createStyles({
|
|
||||||
content: {
|
|
||||||
padding: theme.spacing(2),
|
|
||||||
overflowY: 'hidden',
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
display: 'flex',
|
|
||||||
flexFlow: 'row nowrap',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
titleLeft: {
|
|
||||||
display: 'flex',
|
|
||||||
flexFlow: 'row nowrap',
|
|
||||||
justifyContent: 'flex-start',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
icon: {
|
|
||||||
marginTop: '3px',
|
|
||||||
marginRight: '5px',
|
|
||||||
},
|
|
||||||
profileName: {
|
|
||||||
marginBottom: '3px',
|
|
||||||
},
|
|
||||||
justNow: {
|
|
||||||
fontSize: '18px',
|
|
||||||
fontStyle: 'italic',
|
|
||||||
paddingRight: '3px',
|
|
||||||
},
|
|
||||||
message: {
|
|
||||||
fontSize: '16px',
|
|
||||||
overflow: 'hidden',
|
|
||||||
display: '-webkit-box',
|
|
||||||
WebkitLineClamp: 2,
|
|
||||||
WebkitBoxOrient: 'vertical',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
function TwitterNotification() {
|
|
||||||
const classes = useStyles();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [visible, setVisible] = useState(false);
|
|
||||||
const { notification } = useTwitterNotification();
|
|
||||||
const { config } = usePhone();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (notification && notification.id) {
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
}, [notification]);
|
|
||||||
|
|
||||||
if (!config?.twitter.showNotifications || !notification) return null;
|
|
||||||
|
|
||||||
const profileName = `@${notification.profile_name?.trim()}`;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Notification
|
|
||||||
key={notification.id}
|
|
||||||
open={visible}
|
|
||||||
handleClose={() => setVisible(false)}
|
|
||||||
>
|
|
||||||
<div className={classes.content}>
|
|
||||||
<div className={classes.title}>
|
|
||||||
<div className={classes.titleLeft}>
|
|
||||||
<div className={classes.icon}>
|
|
||||||
<TwitterIcon />
|
|
||||||
</div>
|
|
||||||
<div className={classes.profileName}>{profileName}</div>
|
|
||||||
</div>
|
|
||||||
<div className={classes.justNow}>{t('APPS_TWITTER_JUST_NOW')}</div>
|
|
||||||
</div>
|
|
||||||
<div className={classes.message}>{notification.message}</div>
|
|
||||||
</div>
|
|
||||||
</Notification>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default TwitterNotification;
|
|
||||||
@@ -2,15 +2,23 @@ import React, { useEffect } from 'react';
|
|||||||
|
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||||
import { useTweets } from '../../hooks/useTweets';
|
import { useTweets } from '../../hooks/useTweets';
|
||||||
|
import { useTwitterNotifications } from '../../hooks/useTwitterNotifications';
|
||||||
import TweetList from './TweetList';
|
import TweetList from './TweetList';
|
||||||
|
|
||||||
export function TweetListContainer() {
|
export function TweetListContainer() {
|
||||||
const { tweets } = useTweets();
|
const { tweets } = useTweets();
|
||||||
|
const { setUnreadCount } = useTwitterNotifications();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Nui.send('phone:fetchTweets', {});
|
Nui.send('phone:fetchTweets', {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (tweets?.length) {
|
||||||
|
setUnreadCount(0);
|
||||||
|
}
|
||||||
|
}, [setUnreadCount, tweets]);
|
||||||
|
|
||||||
return <TweetList tweets={tweets} />;
|
return <TweetList tweets={tweets} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ export const twitterState = {
|
|||||||
key: 'updateProfileSuccess',
|
key: 'updateProfileSuccess',
|
||||||
default: null,
|
default: null,
|
||||||
}),
|
}),
|
||||||
notification: atom({
|
unreadTweetsCount: atom({
|
||||||
key: 'notification',
|
key: 'unreadTweetsCount',
|
||||||
default: null,
|
default: 0,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { useRecoilValue } from 'recoil';
|
|
||||||
|
|
||||||
import { Tweet } from '../../../common/typings/twitter';
|
|
||||||
import { twitterState } from './state';
|
|
||||||
|
|
||||||
interface ITwitterNotification {
|
|
||||||
notification: Tweet | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useTwitterNotification = (): ITwitterNotification => {
|
|
||||||
const notification = useRecoilValue<Tweet | null>(twitterState.notification);
|
|
||||||
return { notification };
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { useCallback } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useHistory } from "react-router-dom";
|
||||||
|
import { useRecoilState } from "recoil";
|
||||||
|
import { useApp } from "../../../os/apps/hooks/useApps";
|
||||||
|
import { useNotifications } from "../../../os/notifications/hooks/useNotifications";
|
||||||
|
import { twitterState } from "./state";
|
||||||
|
|
||||||
|
export const useTwitterNotifications = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const history = useHistory();
|
||||||
|
const { addNotificationAlert } = useNotifications();
|
||||||
|
const { icon, notificationIcon } = useApp('TWITTER');
|
||||||
|
const [unreadCount, setUnreadCount] = useRecoilState(twitterState.unreadTweetsCount);
|
||||||
|
const setNotification = useCallback(
|
||||||
|
({ profile_name, message }) => {
|
||||||
|
setUnreadCount((curr) => {
|
||||||
|
const unread = curr + 1;
|
||||||
|
addNotificationAlert(
|
||||||
|
{
|
||||||
|
app: 'TWITTER',
|
||||||
|
title: t('APPS_TWITTER_NEW_BROADCAST', { profile_name }),
|
||||||
|
onClick: () => history.push('/twitter'),
|
||||||
|
content: message,
|
||||||
|
icon,
|
||||||
|
notificationIcon,
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
title: t('APPS_TWITTER_UNREAD_MESSAGES', {
|
||||||
|
count: unread,
|
||||||
|
}),
|
||||||
|
content: null,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return unread;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[setUnreadCount, addNotificationAlert, t, icon, notificationIcon, history]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { setNotification, setUnreadCount, unreadCount }
|
||||||
|
};
|
||||||
@@ -5,10 +5,7 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
|||||||
import { IMAGE_DELIMITER } from '../utils/images';
|
import { IMAGE_DELIMITER } from '../utils/images';
|
||||||
import { APP_TWITTER } from '../utils/constants';
|
import { APP_TWITTER } from '../utils/constants';
|
||||||
import { twitterState } from './state';
|
import { twitterState } from './state';
|
||||||
import { useNotifications } from '../../../os/notifications/hooks/useNotifications';
|
import { useTwitterNotifications } from './useTwitterNotifications';
|
||||||
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
|
* Perform all necessary processing/transforms from the raw database
|
||||||
@@ -32,22 +29,7 @@ function processTweet(tweet) {
|
|||||||
* there and have moved that logic here instead.
|
* there and have moved that logic here instead.
|
||||||
*/
|
*/
|
||||||
export const useTwitterService = () => {
|
export const useTwitterService = () => {
|
||||||
const { t } = useTranslation();
|
const { setNotification } = useTwitterNotifications();
|
||||||
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 setProfile = useSetRecoilState(twitterState.profile);
|
||||||
const setUpdateProfileLoading = useSetRecoilState(
|
const setUpdateProfileLoading = useSetRecoilState(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export interface CallProps {
|
export interface CallProps {
|
||||||
|
active: boolean;
|
||||||
accepted: boolean;
|
accepted: boolean;
|
||||||
isTransmitter: boolean;
|
isTransmitter: boolean;
|
||||||
transmitter: string;
|
transmitter: string;
|
||||||
|
|||||||
+2
-12
@@ -6,12 +6,8 @@ import { RecoilRoot } from 'recoil';
|
|||||||
import * as Sentry from '@sentry/react';
|
import * as Sentry from '@sentry/react';
|
||||||
import { Integrations } from '@sentry/tracing';
|
import { Integrations } from '@sentry/tracing';
|
||||||
import './main.css';
|
import './main.css';
|
||||||
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 PhoneConfig from './config/default.json';
|
||||||
import SnackbarProvider from './ui/providers/SnackbarProvider';
|
import { PhoneContainer } from './PhoneContainer';
|
||||||
import { NotificationsProvider } from './os/notifications/providers/NotificationsProvider';
|
|
||||||
|
|
||||||
// Enable Sentry when config setting is true
|
// Enable Sentry when config setting is true
|
||||||
if (PhoneConfig.SentryErrorMetrics) {
|
if (PhoneConfig.SentryErrorMetrics) {
|
||||||
@@ -29,13 +25,7 @@ if (PhoneConfig.SentryErrorMetrics) {
|
|||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<HashRouter>
|
<HashRouter>
|
||||||
<RecoilRoot>
|
<RecoilRoot>
|
||||||
<TwitterNotification />
|
<PhoneContainer />
|
||||||
<BankNotification />
|
|
||||||
<SnackbarProvider>
|
|
||||||
<NotificationsProvider>
|
|
||||||
<Phone />
|
|
||||||
</NotificationsProvider>
|
|
||||||
</SnackbarProvider>
|
|
||||||
</RecoilRoot>
|
</RecoilRoot>
|
||||||
</HashRouter>,
|
</HashRouter>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
|
|||||||
@@ -17,6 +17,14 @@
|
|||||||
"APPS_SELLOUT": "Market",
|
"APPS_SELLOUT": "Market",
|
||||||
"APPS_CAMERA": "Camera",
|
"APPS_CAMERA": "Camera",
|
||||||
|
|
||||||
|
"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_ACCEPT_CALL": "Accept",
|
||||||
|
"APPS_DIALER_REJECT_CALL": "Reject",
|
||||||
|
"APPS_DIALER_END_CALL": "End",
|
||||||
|
|
||||||
"APPS_BANK_TRANSFER": "Transfer",
|
"APPS_BANK_TRANSFER": "Transfer",
|
||||||
"APPS_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper",
|
"APPS_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper",
|
||||||
"APPS_SETTINGS_OPTIONS_FRAME": "Frame",
|
"APPS_SETTINGS_OPTIONS_FRAME": "Frame",
|
||||||
@@ -48,6 +56,7 @@
|
|||||||
"APPS_TWITTER_TIME_HOURS": "h",
|
"APPS_TWITTER_TIME_HOURS": "h",
|
||||||
"APPS_TWITTER_TIME_DAYS": "d",
|
"APPS_TWITTER_TIME_DAYS": "d",
|
||||||
"APPS_TWITTER_NEW_BROADCAST": "New tweet from @{{ profile_name }}!",
|
"APPS_TWITTER_NEW_BROADCAST": "New tweet from @{{ profile_name }}!",
|
||||||
|
"APPS_TWITTER_UNREAD_MESSAGES": "You have {{ count }} new tweets in your timeline!",
|
||||||
|
|
||||||
"APPS_BANK_HOME_TITLE": "Welcome",
|
"APPS_BANK_HOME_TITLE": "Welcome",
|
||||||
"APPS_BANK_ACCOUNT_LINK": "Account",
|
"APPS_BANK_ACCOUNT_LINK": "Account",
|
||||||
|
|||||||
@@ -1,110 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Fab } from '@material-ui/core';
|
|
||||||
import { AppWrapper } from '../../ui/components/AppWrapper';
|
|
||||||
import { AppContent } from '../../ui/components/AppContent';
|
|
||||||
import { useCall } from '../hooks/useCall';
|
|
||||||
import CallIcon from '@material-ui/icons/Call';
|
|
||||||
import CallEndIcon from '@material-ui/icons/CallEnd';
|
|
||||||
import useStyles from './modal.styles';
|
|
||||||
import { useModal } from '../hooks/useModal';
|
|
||||||
import Nui from '../../os/nui-events/utils/Nui';
|
|
||||||
import CallTimer from './CallTimer';
|
|
||||||
import InjectDebugData from '../../os/debug/InjectDebugData';
|
|
||||||
|
|
||||||
InjectDebugData([
|
|
||||||
{
|
|
||||||
app: 'CALL',
|
|
||||||
method: 'setCaller',
|
|
||||||
data: {
|
|
||||||
accepted: true,
|
|
||||||
isTransmitter: true,
|
|
||||||
transmitter: 'Chip',
|
|
||||||
receiver: 'Taso',
|
|
||||||
phone_number: '860-4504',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const CallModal = () => {
|
|
||||||
const { call } = useCall();
|
|
||||||
const { setModal } = useModal();
|
|
||||||
|
|
||||||
const classes = useStyles();
|
|
||||||
|
|
||||||
const handleAcceptCall = () => {
|
|
||||||
Nui.send('phone:acceptCall', {
|
|
||||||
transmitterNumber: call.transmitter,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRejectCall = () => {
|
|
||||||
setModal(false);
|
|
||||||
Nui.send('phone:rejectCall', {
|
|
||||||
phoneNumber: call.transmitter,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleEndCall = () => {
|
|
||||||
setModal(false);
|
|
||||||
Nui.send('phone:endCall', {
|
|
||||||
transmitterNumber: call.transmitter,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (call.isTransmitter) {
|
|
||||||
return (
|
|
||||||
<AppWrapper>
|
|
||||||
<AppContent>
|
|
||||||
<h1 style={{ textAlign: 'center' }}>{call.receiver}</h1>
|
|
||||||
<CallTimer isAccepted={call.accepted} />
|
|
||||||
<div className={classes.actions}>
|
|
||||||
<Fab
|
|
||||||
onClick={handleEndCall}
|
|
||||||
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
|
|
||||||
className={classes.actionButton}
|
|
||||||
>
|
|
||||||
<CallEndIcon />
|
|
||||||
</Fab>
|
|
||||||
</div>
|
|
||||||
</AppContent>
|
|
||||||
</AppWrapper>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AppWrapper>
|
|
||||||
<AppContent>
|
|
||||||
<h1 style={{ textAlign: 'center' }}>{call.transmitter}</h1>
|
|
||||||
<CallTimer isAccepted={call.accepted} />
|
|
||||||
<div className={classes.actions}>
|
|
||||||
{!call.accepted ? (
|
|
||||||
<>
|
|
||||||
<Fab
|
|
||||||
onClick={handleRejectCall}
|
|
||||||
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
|
|
||||||
className={classes.actionButton}
|
|
||||||
>
|
|
||||||
<CallEndIcon />
|
|
||||||
</Fab>
|
|
||||||
<Fab
|
|
||||||
onClick={handleAcceptCall}
|
|
||||||
style={{ backgroundColor: '#27ae60', color: '#fff' }}
|
|
||||||
className={classes.actionButton}
|
|
||||||
>
|
|
||||||
<CallIcon />
|
|
||||||
</Fab>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<Fab
|
|
||||||
onClick={handleEndCall}
|
|
||||||
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
|
|
||||||
className={classes.actionButton}
|
|
||||||
>
|
|
||||||
<CallEndIcon />
|
|
||||||
</Fab>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</AppContent>
|
|
||||||
</AppWrapper>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { useRecoilState } from 'recoil';
|
|
||||||
import { CallProps } from '../../common/typings/call';
|
|
||||||
import { callerState } from './state';
|
|
||||||
|
|
||||||
interface CallHook {
|
|
||||||
call: CallProps;
|
|
||||||
setCall: (details: any) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useCall = (): CallHook => {
|
|
||||||
const [call, setCall] = useRecoilState(callerState.currentCall);
|
|
||||||
return { call, setCall };
|
|
||||||
};
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent';
|
|
||||||
import { useRecoilState, useSetRecoilState } from 'recoil';
|
|
||||||
import { callerState } from './state';
|
|
||||||
|
|
||||||
export const useCallService = () => {
|
|
||||||
const [caller, setCaller] = useRecoilState(callerState.currentCall);
|
|
||||||
const setModal = useSetRecoilState(callerState.callModal);
|
|
||||||
|
|
||||||
useNuiEvent('CALL', 'setCaller', setCaller, {}, caller);
|
|
||||||
useNuiEvent('CALL', 'callModal', setModal);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
export const CallControls = ({
|
||||||
|
size,
|
||||||
|
}: {
|
||||||
|
size?: 'small' | 'medium' | 'large';
|
||||||
|
}) => {
|
||||||
|
const classes = useStyles();
|
||||||
|
const { setModal } = useModal();
|
||||||
|
const { call, endCall, acceptCall, rejectCall } = useCall();
|
||||||
|
|
||||||
|
if (!call) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleRejectCall = () => {
|
||||||
|
setModal(false);
|
||||||
|
rejectCall();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEndCall = () => {
|
||||||
|
setModal(false);
|
||||||
|
endCall();
|
||||||
|
};
|
||||||
|
|
||||||
|
const { accepted, isTransmitter } = call;
|
||||||
|
|
||||||
|
if (accepted || isTransmitter) {
|
||||||
|
return (
|
||||||
|
<Fab
|
||||||
|
size={size}
|
||||||
|
onClick={handleEndCall}
|
||||||
|
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
|
||||||
|
className={classes.actionButton}
|
||||||
|
>
|
||||||
|
<CallEndIcon />
|
||||||
|
</Fab>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Fab
|
||||||
|
size={size}
|
||||||
|
onClick={handleRejectCall}
|
||||||
|
style={{ backgroundColor: '#e74c3c', color: '#fff' }}
|
||||||
|
className={classes.actionButton}
|
||||||
|
>
|
||||||
|
<CallEndIcon />
|
||||||
|
</Fab>
|
||||||
|
<Fab
|
||||||
|
size={size}
|
||||||
|
onClick={acceptCall}
|
||||||
|
style={{ backgroundColor: '#27ae60', color: '#fff' }}
|
||||||
|
className={classes.actionButton}
|
||||||
|
>
|
||||||
|
<CallIcon />
|
||||||
|
</Fab>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { AppWrapper } from '../../../ui/components/AppWrapper';
|
||||||
|
import { AppContent } from '../../../ui/components/AppContent';
|
||||||
|
import { useCall } from '../hooks/useCall';
|
||||||
|
import useStyles from './modal.styles';
|
||||||
|
import CallTimer from './CallTimer';
|
||||||
|
import { CallControls } from './CallControls';
|
||||||
|
import { Box } from '@material-ui/core';
|
||||||
|
|
||||||
|
export const CallModal = () => {
|
||||||
|
const classes = useStyles();
|
||||||
|
const { call } = useCall();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AppWrapper>
|
||||||
|
<AppContent>
|
||||||
|
<Box pt={16}>
|
||||||
|
<h1 style={{ textAlign: 'center' }}>{call?.transmitter}</h1>
|
||||||
|
<CallTimer isAccepted={call?.accepted} />
|
||||||
|
</Box>
|
||||||
|
<div className={classes.actions}>
|
||||||
|
<CallControls />
|
||||||
|
</div>
|
||||||
|
</AppContent>
|
||||||
|
</AppWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Box } from '@material-ui/core';
|
||||||
|
import { CallControls } from './CallControls';
|
||||||
|
|
||||||
|
interface ICallNotificationProps {
|
||||||
|
onAccept(): void;
|
||||||
|
onReject(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CallNotification = ({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div style={{ paddingBottom: '48px' }}>
|
||||||
|
<Box>{children}</Box>
|
||||||
|
<Box style={{ position: 'absolute', bottom: 0, right: 0 }}>
|
||||||
|
<CallControls size='small' />
|
||||||
|
</Box>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
File renamed without changes.
+1
-1
@@ -11,7 +11,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
|||||||
bottom: '10%',
|
bottom: '10%',
|
||||||
},
|
},
|
||||||
actionButton: {
|
actionButton: {
|
||||||
margin: 20,
|
margin: 10,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
File renamed without changes.
@@ -0,0 +1,36 @@
|
|||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
import { CallProps } from '../../../common/typings/call';
|
||||||
|
import Nui from '../../nui-events/utils/Nui';
|
||||||
|
import { callerState } from './state';
|
||||||
|
|
||||||
|
interface CallHook {
|
||||||
|
call: CallProps;
|
||||||
|
setCall: (details: any) => void;
|
||||||
|
acceptCall(): void;
|
||||||
|
rejectCall(): void;
|
||||||
|
endCall(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useCall = (): CallHook => {
|
||||||
|
const [call, setCall] = useRecoilState(callerState.currentCall);
|
||||||
|
|
||||||
|
const acceptCall = () => {
|
||||||
|
Nui.send('phone:acceptCall', {
|
||||||
|
transmitterNumber: call.transmitter,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const rejectCall = () => {
|
||||||
|
Nui.send('phone:rejectCall', {
|
||||||
|
phoneNumber: call.transmitter,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const endCall = () => {
|
||||||
|
Nui.send('phone:endCall', {
|
||||||
|
transmitterNumber: call.transmitter,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return { call, setCall, acceptCall, rejectCall, endCall };
|
||||||
|
};
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
|
||||||
|
import { useSetRecoilState } from 'recoil';
|
||||||
|
import { callerState } from './state';
|
||||||
|
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { CallNotification } from '../components/CallNotification';
|
||||||
|
import { useCall } from './useCall';
|
||||||
|
import { CallProps } from '../../../common/typings/call';
|
||||||
|
import { useApp } from '../../apps/hooks/useApps';
|
||||||
|
import InjectDebugData from '../../debug/InjectDebugData';
|
||||||
|
|
||||||
|
const NOTIFICATION_ID = 'call:current';
|
||||||
|
|
||||||
|
InjectDebugData<CallProps>([
|
||||||
|
{
|
||||||
|
app: 'CALL',
|
||||||
|
method: 'setCaller',
|
||||||
|
data: {
|
||||||
|
accepted: false,
|
||||||
|
isTransmitter: false,
|
||||||
|
transmitter: 'Chip',
|
||||||
|
receiver: 'Taso',
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const useCallService = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const {
|
||||||
|
addNotificationAlert,
|
||||||
|
removeId,
|
||||||
|
addNotification,
|
||||||
|
} = useNotifications();
|
||||||
|
|
||||||
|
const { call, setCall } = useCall();
|
||||||
|
|
||||||
|
const { icon, notificationIcon } = useApp('DIALER');
|
||||||
|
|
||||||
|
const setModal = useSetRecoilState(callerState.callModal);
|
||||||
|
|
||||||
|
const callNotificationBase = {
|
||||||
|
app: 'CALL',
|
||||||
|
id: NOTIFICATION_ID,
|
||||||
|
cantClose: true,
|
||||||
|
icon,
|
||||||
|
notificationIcon,
|
||||||
|
};
|
||||||
|
|
||||||
|
const _setCall = (_call: CallProps) => {
|
||||||
|
setCall(_call);
|
||||||
|
if (!_call || !_call.active) {
|
||||||
|
removeId(NOTIFICATION_ID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_call.accepted) {
|
||||||
|
removeId(NOTIFICATION_ID);
|
||||||
|
addNotification({
|
||||||
|
...callNotificationBase,
|
||||||
|
content: (
|
||||||
|
<CallNotification>
|
||||||
|
{t('APPS_DIALER_CURRENT_CALL_WITH', {
|
||||||
|
transmitter: _call.transmitter,
|
||||||
|
})}
|
||||||
|
</CallNotification>
|
||||||
|
),
|
||||||
|
title: t('APPS_DIALER_CURRENT_CALL_TITLE'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!_call.isTransmitter && !_call.accepted) {
|
||||||
|
removeId(NOTIFICATION_ID);
|
||||||
|
addNotificationAlert(
|
||||||
|
{
|
||||||
|
...callNotificationBase,
|
||||||
|
title: t('APPS_DIALER_INCOMING_CALL_TITLE', {
|
||||||
|
transmitter: _call.transmitter,
|
||||||
|
}),
|
||||||
|
content: (
|
||||||
|
<CallNotification>
|
||||||
|
{t('APPS_DIALER_TRANSMITTER_IS_CALLING', {
|
||||||
|
transmitter: _call.transmitter,
|
||||||
|
})}
|
||||||
|
</CallNotification>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useNuiEvent<CallProps>('CALL', 'setCaller', _setCall, call);
|
||||||
|
useNuiEvent<boolean>('CALL', 'callModal', setModal);
|
||||||
|
};
|
||||||
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,7 @@
|
|||||||
interface DebugEvent {
|
interface DebugEvent<P = any> {
|
||||||
app: string;
|
app: string;
|
||||||
method: string;
|
method: string;
|
||||||
data: any;
|
data: P;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This should be unit tested
|
// TODO: This should be unit tested
|
||||||
@@ -27,7 +27,7 @@ interface DebugEvent {
|
|||||||
* }
|
* }
|
||||||
* ])
|
* ])
|
||||||
**/
|
**/
|
||||||
const InjectDebugData = (events: DebugEvent[], timer = 1000) => {
|
const InjectDebugData = <P>(events: DebugEvent<P>[], timer = 1000) => {
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect, useRef } from 'react';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { atom, useSetRecoilState, useRecoilValue } from 'recoil';
|
import { atom, useSetRecoilState, useRecoilValue } from 'recoil';
|
||||||
import Nui from '../../nui-events/utils/Nui';
|
import { usePhone } from '../../phone/hooks/usePhone';
|
||||||
|
|
||||||
const keyboardState = {
|
const keyboardState = {
|
||||||
ArrowRight: atom({
|
ArrowRight: atom({
|
||||||
@@ -48,6 +48,7 @@ const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
|
|||||||
|
|
||||||
export const useInitKeyboard = () => {
|
export const useInitKeyboard = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { closePhone } = usePhone();
|
||||||
const getters = {
|
const getters = {
|
||||||
ArrowRight: useRecoilValue(keyboardState.ArrowRight),
|
ArrowRight: useRecoilValue(keyboardState.ArrowRight),
|
||||||
ArrowLeft: useRecoilValue(keyboardState.ArrowLeft),
|
ArrowLeft: useRecoilValue(keyboardState.ArrowLeft),
|
||||||
@@ -58,21 +59,26 @@ export const useInitKeyboard = () => {
|
|||||||
Escape: useRecoilValue(keyboardState.Escape),
|
Escape: useRecoilValue(keyboardState.Escape),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlers = useRef(new Map());
|
||||||
const setEscape = useSetRecoilState<any>(keyboardState.Escape);
|
const setEscape = useSetRecoilState<any>(keyboardState.Escape);
|
||||||
const setBackspace = useSetRecoilState(keyboardState.Backspace);
|
const setBackspace = useSetRecoilState(keyboardState.Backspace);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
function registerCustomKeys() {
|
||||||
|
Object.keys(getters).forEach((g) => {
|
||||||
|
handlers.current.set(g, getters[g]);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[getters]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
function handleNUIKeyboardMessage() {
|
function handleNUIKeyboardMessage() {
|
||||||
function onKeyUp(event) {
|
function onKeyUp(event) {
|
||||||
const { key } = event;
|
const { key } = event;
|
||||||
const callback = getters[key];
|
const callback = handlers.current.get(key);
|
||||||
if (
|
if (isKeyValid(key) && callback && callback.call) {
|
||||||
isKeyValid(key) &&
|
return callback(event);
|
||||||
callback &&
|
|
||||||
callback.handler &&
|
|
||||||
callback.handler.call
|
|
||||||
) {
|
|
||||||
return callback.handler(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,35 +88,22 @@ export const useInitKeyboard = () => {
|
|||||||
[getters]
|
[getters]
|
||||||
);
|
);
|
||||||
|
|
||||||
const escapeHandler = useCallback(() => Nui.send('phone:close'), []);
|
const backspaceHandler = useCallback(
|
||||||
|
(event) => {
|
||||||
const backspaceHandler = useCallback((event) => {
|
|
||||||
if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) {
|
if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) {
|
||||||
// Dont anything if we are typing something :)
|
// Dont anything if we are typing something :)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
history.goBack();
|
history.goBack();
|
||||||
}, [history]);
|
},
|
||||||
|
[history]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
function registerDefaultHandlers() {
|
function registerDefaultHandlers() {
|
||||||
setEscape({ handler: escapeHandler });
|
handlers.current.set('Escape', () => closePhone());
|
||||||
setBackspace({ handler: backspaceHandler });
|
handlers.current.set('Backspace', backspaceHandler);
|
||||||
},
|
},
|
||||||
[setEscape, setBackspace, history, escapeHandler, backspaceHandler]
|
[setEscape, setBackspace, history, backspaceHandler, closePhone]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useKeyboard = () => {
|
|
||||||
const setters = {
|
|
||||||
ArrowRight: useSetRecoilState(keyboardState.ArrowRight),
|
|
||||||
ArrowLeft: useSetRecoilState(keyboardState.ArrowLeft),
|
|
||||||
ArrowUp: useSetRecoilState(keyboardState.ArrowUp),
|
|
||||||
ArrowDown: useSetRecoilState(keyboardState.ArrowDown),
|
|
||||||
Enter: useSetRecoilState(keyboardState.Enter),
|
|
||||||
};
|
|
||||||
|
|
||||||
return (key, handler) => {
|
|
||||||
setters[key]({ handler });
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -8,8 +8,7 @@ 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 } from 'react-router-dom';
|
||||||
|
import { usePhone } from '../../phone/hooks/usePhone';
|
||||||
import Nui from '../../nui-events/utils/Nui';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -19,10 +18,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const Navigation = () => {
|
export const Navigation = () => {
|
||||||
const closePhone = () => {
|
const { closePhone } = usePhone();
|
||||||
console.log('Phone closed');
|
|
||||||
Nui.send('phone:close');
|
|
||||||
};
|
|
||||||
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -38,12 +34,12 @@ export const Navigation = () => {
|
|||||||
/>
|
/>
|
||||||
<BottomNavigationAction
|
<BottomNavigationAction
|
||||||
label='Close'
|
label='Close'
|
||||||
value={() => closePhone()}
|
value={closePhone}
|
||||||
icon={<RadioButtonUncheckedIcon />}
|
icon={<RadioButtonUncheckedIcon />}
|
||||||
/>
|
/>
|
||||||
<BottomNavigationAction
|
<BottomNavigationAction
|
||||||
label='Back'
|
label='Back'
|
||||||
value={() => history.goBack()}
|
value={history.goBack}
|
||||||
icon={<KeyboardArrowLeftIcon />}
|
icon={<KeyboardArrowLeftIcon />}
|
||||||
/>
|
/>
|
||||||
</BottomNavigation>
|
</BottomNavigation>
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Box, makeStyles } from '@material-ui/core';
|
||||||
|
import { useNotifications } from '../hooks/useNotifications';
|
||||||
|
import { Alert, AlertTitle } from '@material-ui/lab';
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
snackbar: {
|
||||||
|
marginTop: '-710px',
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
alert: {
|
||||||
|
position: 'relative',
|
||||||
|
cursor: 'pointer',
|
||||||
|
width: '370px',
|
||||||
|
height: '120px',
|
||||||
|
zIndex: 50,
|
||||||
|
backgroundColor: theme.palette.background.paper,
|
||||||
|
color: theme.palette.text.primary,
|
||||||
|
'& .MuiAlert-icon': {
|
||||||
|
color: theme.palette.text.primary,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const NotificationAlert = () => {
|
||||||
|
const classes = useStyles();
|
||||||
|
const { currentAlert } = useNotifications();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes.snackbar}>
|
||||||
|
{currentAlert ? (
|
||||||
|
<Alert
|
||||||
|
onClick={() => currentAlert.onClick?.(currentAlert)}
|
||||||
|
icon={currentAlert.icon || false}
|
||||||
|
className={classes.alert}
|
||||||
|
elevation={6}
|
||||||
|
>
|
||||||
|
<AlertTitle>{currentAlert.title}</AlertTitle>
|
||||||
|
<Box width='100%'>{currentAlert.content}</Box>
|
||||||
|
</Alert>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -8,18 +8,14 @@ import {
|
|||||||
Paper,
|
Paper,
|
||||||
Box,
|
Box,
|
||||||
List,
|
List,
|
||||||
ListItem,
|
|
||||||
ListItemText,
|
|
||||||
Divider,
|
Divider,
|
||||||
ListItemAvatar,
|
|
||||||
} from '@material-ui/core';
|
} from '@material-ui/core';
|
||||||
import SignalIcon from '@material-ui/icons/SignalCellular3Bar';
|
import SignalIcon from '@material-ui/icons/SignalCellular3Bar';
|
||||||
import CloseIcon from '@material-ui/icons/Close';
|
|
||||||
import Battery90Icon from '@material-ui/icons/Battery90';
|
import Battery90Icon from '@material-ui/icons/Battery90';
|
||||||
import ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp';
|
import ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp';
|
||||||
import Default from '../../../config/default.json';
|
import Default from '../../../config/default.json';
|
||||||
import { useNotifications } from '../hooks/useNotifications';
|
import { useNotifications } from '../hooks/useNotifications';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { NotificationItem } from './NotificationItem';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -67,9 +63,8 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean }) => {
|
export const NotificationBar = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const history = useHistory();
|
|
||||||
|
|
||||||
const { icons, notifications, removeNotification } = useNotifications();
|
const { icons, notifications, removeNotification } = useNotifications();
|
||||||
|
|
||||||
@@ -120,41 +115,29 @@ export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Slide direction='down' in={forceUncollapse || uncollapsed}>
|
<Slide direction='down' in={uncollapsed}>
|
||||||
<Paper square className={classes.drawer}>
|
<Paper square className={classes.drawer}>
|
||||||
<Box p={2}>
|
<Box p={2}>
|
||||||
<List>
|
<List>
|
||||||
<Divider />
|
<Divider />
|
||||||
{notifications.map(({ href, title, content, icon }, idx) => (
|
{notifications.map((notification, idx) => (
|
||||||
<ListItem
|
<NotificationItem
|
||||||
divider
|
|
||||||
button
|
|
||||||
onClick={() => {
|
|
||||||
if (href) {
|
|
||||||
history.push(href);
|
|
||||||
setUncollapsed(false);
|
|
||||||
removeNotification(idx);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
className={classes.notificationItem}
|
|
||||||
key={idx}
|
key={idx}
|
||||||
>
|
onClose={(e) => {
|
||||||
{icon && <ListItemAvatar>{icon}</ListItemAvatar>}
|
|
||||||
<ListItemText secondary={content}>{title}</ListItemText>
|
|
||||||
<IconButton
|
|
||||||
className={classes.closeNotifBtn}
|
|
||||||
size='small'
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (notifications.length === 1) {
|
if (notifications.length === 1) {
|
||||||
setUncollapsed(false);
|
setUncollapsed(false);
|
||||||
}
|
}
|
||||||
removeNotification(idx);
|
removeNotification(idx);
|
||||||
}}
|
}}
|
||||||
>
|
onClickClose={() => {
|
||||||
<CloseIcon color='primary' />
|
setUncollapsed(false);
|
||||||
</IconButton>
|
if (!notification.cantClose) {
|
||||||
</ListItem>
|
removeNotification(idx);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
{...notification}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import CloseIcon from '@material-ui/icons/Close';
|
||||||
|
import {
|
||||||
|
IconButton,
|
||||||
|
ListItem,
|
||||||
|
ListItemAvatar,
|
||||||
|
ListItemText,
|
||||||
|
makeStyles,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import { INotification } from '../providers/NotificationsProvider';
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
closeNotifBtn: {
|
||||||
|
position: 'absolute',
|
||||||
|
right: '8px',
|
||||||
|
top: '8px',
|
||||||
|
},
|
||||||
|
notificationItem: {
|
||||||
|
position: 'relative',
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const NotificationItem = ({
|
||||||
|
onClose,
|
||||||
|
onClickClose,
|
||||||
|
...notification
|
||||||
|
}: INotification & {
|
||||||
|
onClose: (e: any) => void;
|
||||||
|
onClickClose: (e: any) => void;
|
||||||
|
}) => {
|
||||||
|
const { title, icon, content, cantClose, onClick } = notification;
|
||||||
|
const classes = useStyles();
|
||||||
|
return (
|
||||||
|
<ListItem
|
||||||
|
divider
|
||||||
|
button
|
||||||
|
onClick={(e) => {
|
||||||
|
if (onClick) {
|
||||||
|
onClick(notification);
|
||||||
|
onClickClose(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className={classes.notificationItem}
|
||||||
|
>
|
||||||
|
{icon && <ListItemAvatar>{icon}</ListItemAvatar>}
|
||||||
|
<ListItemText secondary={content}>{title}</ListItemText>
|
||||||
|
{!cantClose && (
|
||||||
|
<IconButton
|
||||||
|
className={classes.closeNotifBtn}
|
||||||
|
size='small'
|
||||||
|
onClick={onClose}
|
||||||
|
>
|
||||||
|
<CloseIcon color='primary' />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export const DEFAULT_ALERT_HIDE_TIME = 3000;
|
||||||
@@ -1,12 +1,22 @@
|
|||||||
import React, { createContext, useState, useCallback, useMemo } from 'react';
|
import React, {
|
||||||
|
createContext,
|
||||||
|
useState,
|
||||||
|
useCallback,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useEffect,
|
||||||
|
} from 'react';
|
||||||
|
import { DEFAULT_ALERT_HIDE_TIME } from '../notifications.constants';
|
||||||
|
|
||||||
export interface INotification {
|
export interface INotification {
|
||||||
app: string;
|
app: string;
|
||||||
|
id?: string;
|
||||||
title: string;
|
title: string;
|
||||||
content?: React.ReactNode;
|
content?: React.ReactNode;
|
||||||
icon?: JSX.Element;
|
icon?: JSX.Element;
|
||||||
notificationIcon?: JSX.Element;
|
notificationIcon?: JSX.Element;
|
||||||
href?: string;
|
cantClose?: boolean;
|
||||||
|
onClick?: (notification: INotification) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface INotificationIcon {
|
interface INotificationIcon {
|
||||||
@@ -17,39 +27,143 @@ interface INotificationIcon {
|
|||||||
|
|
||||||
export const NotificationsContext = createContext<{
|
export const NotificationsContext = createContext<{
|
||||||
notifications: INotification[];
|
notifications: INotification[];
|
||||||
|
currentAlert: INotification;
|
||||||
icons: INotificationIcon[];
|
icons: INotificationIcon[];
|
||||||
count: number;
|
count: number;
|
||||||
|
removeAlerts(): void;
|
||||||
|
addOrUpdateNotification(add: INotification, update?: INotification): void;
|
||||||
addNotification(value: INotification): void;
|
addNotification(value: INotification): void;
|
||||||
updateNotification(idx: number, value: INotification): void;
|
|
||||||
removeNotification(idx: number): void;
|
removeNotification(idx: number): void;
|
||||||
|
updateId(id: string, value: Partial<INotification>): void;
|
||||||
|
removeId(id: string): void;
|
||||||
|
hasNotification(app: string): number;
|
||||||
|
addNotificationAlert(
|
||||||
|
n: INotification,
|
||||||
|
persist: boolean,
|
||||||
|
update?: Partial<INotification>
|
||||||
|
);
|
||||||
}>(null);
|
}>(null);
|
||||||
|
|
||||||
export function NotificationsProvider({ children }) {
|
export function NotificationsProvider({ children }) {
|
||||||
const [notifications, setNotifications] = useState<INotification[]>([]);
|
const [notifications, setNotifications] = useState<INotification[]>([]);
|
||||||
|
|
||||||
|
const alertTimeout = useRef<NodeJS.Timeout>();
|
||||||
|
const [alerts, setAlerts] = useState<
|
||||||
|
Array<[INotification, boolean, Partial<INotification>]>
|
||||||
|
>([]);
|
||||||
|
const [currentAlert, setCurrentAlert] = useState<INotification>();
|
||||||
|
|
||||||
const updateNotification = useCallback(
|
const updateNotification = useCallback(
|
||||||
(idx: number, value: INotification) => {
|
(idx: number, value: INotification) => {
|
||||||
setNotifications((all) => {
|
setNotifications((all) => {
|
||||||
const updated = [...all];
|
const updated = [...all];
|
||||||
updated.splice(idx, 0, value);
|
updated.splice(idx, 1, value);
|
||||||
return updated;
|
return updated;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const removeNotification = useCallback((idx) => {
|
const removeNotification = (idx) => {
|
||||||
setNotifications((all) => {
|
setNotifications((all) => {
|
||||||
const updated = [...all];
|
const updated = all;
|
||||||
updated.splice(idx, 1);
|
updated.splice(idx, 1);
|
||||||
return updated;
|
return [...updated];
|
||||||
});
|
});
|
||||||
}, []);
|
};
|
||||||
|
|
||||||
const addNotification = useCallback((value: INotification) => {
|
const addNotification = useCallback((value: INotification) => {
|
||||||
setNotifications((all) => [value, ...all]);
|
setNotifications((all) => [value, ...all]);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a notification exists for current app
|
||||||
|
* and returns its index or -1 if not found.
|
||||||
|
*/
|
||||||
|
const hasNotification = useCallback(
|
||||||
|
(appId: string): number => {
|
||||||
|
return notifications.findIndex((n) => n.app === appId);
|
||||||
|
},
|
||||||
|
[notifications]
|
||||||
|
);
|
||||||
|
|
||||||
|
const addOrUpdateNotification = useCallback(
|
||||||
|
(add: INotification, update?: INotification) => {
|
||||||
|
const exists = hasNotification(add.app);
|
||||||
|
if (update && exists !== -1) {
|
||||||
|
updateNotification(exists, update);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addNotification(add);
|
||||||
|
},
|
||||||
|
[addNotification, hasNotification, updateNotification]
|
||||||
|
);
|
||||||
|
|
||||||
|
const _showAlert = useCallback(
|
||||||
|
(n: INotification, persist: boolean, update: Partial<INotification>) => {
|
||||||
|
return new Promise<void>((res) => {
|
||||||
|
const resolve = () => {
|
||||||
|
if (persist) {
|
||||||
|
addOrUpdateNotification(n, update ? { ...n, ...update } : null);
|
||||||
|
}
|
||||||
|
res();
|
||||||
|
};
|
||||||
|
|
||||||
|
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]
|
||||||
|
);
|
||||||
|
|
||||||
|
const addNotificationAlert = (
|
||||||
|
n: INotification,
|
||||||
|
persist?: boolean,
|
||||||
|
update?: Partial<INotification>
|
||||||
|
) => {
|
||||||
|
setAlerts((curr) => [...curr, [n, persist, update]]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeId = (id: string) => {
|
||||||
|
const idx = notifications.findIndex((n) => n.id === id);
|
||||||
|
if (idx !== -1) {
|
||||||
|
removeNotification(idx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateId = (id: string, value: Partial<INotification>) => {
|
||||||
|
const idx = notifications.findIndex((n) => n.id === id);
|
||||||
|
if (idx !== -1) {
|
||||||
|
const curr = { ...notifications[idx], ...value };
|
||||||
|
updateNotification(idx, curr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!currentAlert && alerts.length) {
|
||||||
|
_showAlert(...alerts[0]).then(() => {
|
||||||
|
setAlerts((curr) => {
|
||||||
|
const newQueue = curr;
|
||||||
|
curr.shift();
|
||||||
|
return newQueue;
|
||||||
|
});
|
||||||
|
setCurrentAlert(null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [_showAlert, alerts, currentAlert]);
|
||||||
|
|
||||||
const icons: INotificationIcon[] = useMemo(
|
const icons: INotificationIcon[] = useMemo(
|
||||||
() =>
|
() =>
|
||||||
notifications.reduce((icons, curr) => {
|
notifications.reduce((icons, curr) => {
|
||||||
@@ -64,13 +178,24 @@ export function NotificationsProvider({ children }) {
|
|||||||
[notifications]
|
[notifications]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const removeAlerts = () => {
|
||||||
|
setAlerts([]);
|
||||||
|
setCurrentAlert(null);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NotificationsContext.Provider
|
<NotificationsContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
currentAlert,
|
||||||
notifications,
|
notifications,
|
||||||
|
removeAlerts,
|
||||||
addNotification,
|
addNotification,
|
||||||
updateNotification,
|
|
||||||
removeNotification,
|
removeNotification,
|
||||||
|
updateId,
|
||||||
|
removeId,
|
||||||
|
hasNotification,
|
||||||
|
addNotificationAlert,
|
||||||
|
addOrUpdateNotification,
|
||||||
icons,
|
icons,
|
||||||
count: notifications.length,
|
count: notifications.length,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -16,17 +16,16 @@ interface IOptions {
|
|||||||
* @param options Any options to pass to the addEventListener
|
* @param options Any options to pass to the addEventListener
|
||||||
**/
|
**/
|
||||||
|
|
||||||
export const useNuiEvent = (
|
const defaultOptions = {};
|
||||||
|
|
||||||
|
export const useNuiEvent = <S = Record<string, unknown>>(
|
||||||
app: string,
|
app: string,
|
||||||
method: string,
|
method: string,
|
||||||
handler: Function,
|
handler: Function,
|
||||||
options: IOptions = {},
|
currentState?: S,
|
||||||
currentState?: Record<string, unknown>
|
options: IOptions = defaultOptions
|
||||||
) => {
|
) => {
|
||||||
|
|
||||||
const savedHandler: MutableRefObject<any> = useRef();
|
const savedHandler: MutableRefObject<any> = useRef();
|
||||||
// Destructure passed options
|
|
||||||
const { capture, passive, once } = options;
|
|
||||||
|
|
||||||
// When handler value changes set mutable ref to handler val
|
// When handler value changes set mutable ref to handler val
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -44,15 +43,13 @@ export const useNuiEvent = (
|
|||||||
data: event.data,
|
data: event.data,
|
||||||
level: 1,
|
level: 1,
|
||||||
});
|
});
|
||||||
const newData = currentState ? { ...currentState, ...data } : data
|
const newData = currentState ? { ...currentState, ...data } : data;
|
||||||
savedHandler.current(newData)
|
savedHandler.current(newData);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Why are destructing then restructuring option data?
|
|
||||||
const opts = { capture, passive, once };
|
|
||||||
|
|
||||||
window.addEventListener(eventName, eventListener, opts);
|
window.addEventListener(eventName, eventListener, options);
|
||||||
// Remove Event Listener on component cleanup
|
// Remove Event Listener on component cleanup
|
||||||
return () => window.removeEventListener(eventName, eventListener, opts);
|
return () => window.removeEventListener(eventName, eventListener, options);
|
||||||
}, [app, method, capture, passive, once, currentState]);
|
}, [app, method, currentState, options]);
|
||||||
};
|
};
|
||||||
@@ -1,15 +1,24 @@
|
|||||||
import { useRecoilState } from 'recoil';
|
|
||||||
import { phoneState } from './state';
|
|
||||||
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 Nui from '../../nui-events/utils/Nui';
|
||||||
|
|
||||||
interface IUsePhone {
|
interface IUsePhone {
|
||||||
visibility: boolean;
|
|
||||||
setVisibility(v: boolean): void;
|
|
||||||
config?: IServerConfig;
|
config?: IServerConfig;
|
||||||
|
openPhone(): void;
|
||||||
|
closePhone(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const usePhone = (): IUsePhone => {
|
export const usePhone = (): IUsePhone => {
|
||||||
const [visibility, setVisibility] = useRecoilState(phoneState.visibility);
|
const { removeAlerts } = useNotifications();
|
||||||
return { visibility, setVisibility, config: ServerConfig as any };
|
|
||||||
|
const closePhone = () => {
|
||||||
|
removeAlerts();
|
||||||
|
Nui.send('phone:close');
|
||||||
|
};
|
||||||
|
const openPhone = () => {
|
||||||
|
Nui.send('phone:open');
|
||||||
|
};
|
||||||
|
|
||||||
|
return { config: ServerConfig as any, closePhone, openPhone };
|
||||||
};
|
};
|
||||||
@@ -1,56 +1,53 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
import { useSettings } from '../../../apps/settings/hooks/useSettings';
|
import { useSettings } from '../../../apps/settings/hooks/useSettings';
|
||||||
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
||||||
import { usePhone } from './usePhone';
|
import { DEFAULT_ALERT_HIDE_TIME } from '../../notifications/notifications.constants';
|
||||||
|
import { phoneState } from './state';
|
||||||
|
|
||||||
export const usePhoneVisibility = () => {
|
export const usePhoneVisibility = () => {
|
||||||
const { setVisibility, visibility } = usePhone();
|
const [visibility, setVisibility] = useRecoilState(phoneState.visibility);
|
||||||
const { count } = useNotifications();
|
const { currentAlert } = useNotifications();
|
||||||
const [{ zoom }] = useSettings();
|
const [{ zoom }] = useSettings();
|
||||||
|
|
||||||
const [notifVisibility, setNotifVisibility] = useState<boolean>(false);
|
const [notifVisibility, setNotifVisibility] = useState<boolean>(false);
|
||||||
|
|
||||||
const isNotificationVisibleOnly = useMemo(
|
const [isNotificationVisibleOnly, setNotificationVisibleOnly] = useState<
|
||||||
() => !!(!visibility && count > 0),
|
boolean
|
||||||
[visibility, count]
|
>(false);
|
||||||
);
|
|
||||||
|
useEffect(() => {
|
||||||
|
setNotificationVisibleOnly(!!(!visibility && currentAlert));
|
||||||
|
}, [visibility, currentAlert]);
|
||||||
|
|
||||||
const notificationTimer = useRef<NodeJS.Timeout>();
|
const notificationTimer = useRef<NodeJS.Timeout>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isNotificationVisibleOnly) {
|
if (isNotificationVisibleOnly) {
|
||||||
setNotifVisibility(true);
|
setNotifVisibility(true);
|
||||||
|
if (notificationTimer.current) {
|
||||||
clearTimeout(notificationTimer.current);
|
clearTimeout(notificationTimer.current);
|
||||||
notificationTimer.current = setTimeout(() => {
|
notificationTimer.current = undefined;
|
||||||
setVisibility(false);
|
|
||||||
setNotifVisibility(false);
|
|
||||||
}, 5000);
|
|
||||||
}
|
}
|
||||||
return () => clearTimeout(notificationTimer.current);
|
notificationTimer.current = setTimeout(() => {
|
||||||
|
setNotifVisibility(false);
|
||||||
|
}, DEFAULT_ALERT_HIDE_TIME);
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
clearTimeout(notificationTimer.current);
|
||||||
|
notificationTimer.current = undefined;
|
||||||
|
};
|
||||||
}, [isNotificationVisibleOnly, setVisibility]);
|
}, [isNotificationVisibleOnly, setVisibility]);
|
||||||
|
|
||||||
const bottom = useMemo(() => {
|
const bottom = useMemo(() => {
|
||||||
if (isNotificationVisibleOnly) {
|
if (isNotificationVisibleOnly) {
|
||||||
return `calc(-60% * ${zoom})`;
|
return `calc(-70% * ${zoom})`;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}, [isNotificationVisibleOnly, zoom]);
|
}, [isNotificationVisibleOnly, zoom]);
|
||||||
|
|
||||||
const clickEventOverride = useCallback(
|
|
||||||
(e) => {
|
|
||||||
if (isNotificationVisibleOnly) {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
setVisibility(true);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[setVisibility, isNotificationVisibleOnly]
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bottom,
|
bottom,
|
||||||
visibility: notifVisibility || visibility,
|
visibility: notifVisibility || visibility,
|
||||||
uncollapseNotifications: isNotificationVisibleOnly,
|
|
||||||
clickEventOverride,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Box, makeStyles, Backdrop, Paper } from '@material-ui/core';
|
import { Box, makeStyles, Backdrop, Paper, BoxProps } from '@material-ui/core';
|
||||||
import { AppContentTypes } from '../interface/InterfaceUI';
|
import { AppContentTypes } from '../interface/InterfaceUI';
|
||||||
|
|
||||||
const useStyles = makeStyles(() => ({
|
const useStyles = makeStyles(() => ({
|
||||||
@@ -29,7 +29,7 @@ export const AppContent = ({
|
|||||||
backdrop,
|
backdrop,
|
||||||
onClickBackdrop,
|
onClickBackdrop,
|
||||||
...props
|
...props
|
||||||
}: AppContentTypes) => {
|
}: AppContentTypes & BoxProps) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
return (
|
return (
|
||||||
<Paper className={classes.wrapper} square>
|
<Paper className={classes.wrapper} square>
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React from 'react';
|
||||||
import { AppIcon } from './AppIcon';
|
import { AppIcon } from './AppIcon';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Grid, makeStyles, Tooltip, Zoom } 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';
|
||||||
import { useKeyboard } from '../../os/keyboard/hooks/useKeyboard';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -19,16 +18,9 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const GridMenu = ({ items, Component = AppIcon }) => {
|
export const GridMenu = ({ items, Component = AppIcon }) => {
|
||||||
const setKey = useKeyboard();
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
useEffect(function registerKeyHandlers() {
|
|
||||||
setKey('ArrowLeft', () => {
|
|
||||||
console.log(':v');
|
|
||||||
});
|
|
||||||
// eslint-disable-next-line
|
|
||||||
}, []);
|
|
||||||
// TODO: Fix tooltip position to be closer to app icon
|
// TODO: Fix tooltip position to be closer to app icon
|
||||||
return (
|
return (
|
||||||
<Grid container justify='center'>
|
<Grid container justify='center'>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import events from '../utils/events';
|
import events from '../utils/events';
|
||||||
import { ICall } from '../../phone/src/common/typings/call';
|
import { ICall } from '../../phone/src/common/typings/call';
|
||||||
import {phoneCallStartAnim, phoneCallEndAnim} from './functions';
|
import { phoneCallStartAnim, phoneCallEndAnim } from './functions';
|
||||||
|
|
||||||
const exp = (global as any).exports;
|
const exp = (global as any).exports;
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ onNet(
|
|||||||
app: 'CALL',
|
app: 'CALL',
|
||||||
method: 'setCaller',
|
method: 'setCaller',
|
||||||
data: {
|
data: {
|
||||||
|
active: true,
|
||||||
transmitter: transmitter,
|
transmitter: transmitter,
|
||||||
receiver: receiver,
|
receiver: receiver,
|
||||||
isTransmitter: isTransmitter,
|
isTransmitter: isTransmitter,
|
||||||
@@ -41,12 +42,13 @@ onNet(
|
|||||||
events.PHONE_CALL_WAS_ACCEPTED,
|
events.PHONE_CALL_WAS_ACCEPTED,
|
||||||
(channelId: number, currentCall: ICall, isTransmitter: boolean) => {
|
(channelId: number, currentCall: ICall, isTransmitter: boolean) => {
|
||||||
exp['mumble-voip'].SetCallChannel(channelId);
|
exp['mumble-voip'].SetCallChannel(channelId);
|
||||||
phoneCallStartAnim() // Trigger call animation only if the call was accepted.
|
phoneCallStartAnim(); // Trigger call animation only if the call was accepted.
|
||||||
SendNuiMessage(
|
SendNuiMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
app: 'CALL',
|
app: 'CALL',
|
||||||
method: 'setCaller',
|
method: 'setCaller',
|
||||||
data: {
|
data: {
|
||||||
|
active: true,
|
||||||
transmitter: currentCall.transmitter,
|
transmitter: currentCall.transmitter,
|
||||||
receiver: currentCall.receiver,
|
receiver: currentCall.receiver,
|
||||||
isTransmitter: isTransmitter,
|
isTransmitter: isTransmitter,
|
||||||
@@ -75,13 +77,14 @@ onNet(events.PHONE_CALL_WAS_REJECTED, () => {
|
|||||||
receiver: null,
|
receiver: null,
|
||||||
isTransmitter: null,
|
isTransmitter: null,
|
||||||
accepted: false,
|
accepted: false,
|
||||||
|
active: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(events.PHONE_CALL_SEND_HANGUP_ANIM, () => {
|
onNet(events.PHONE_CALL_SEND_HANGUP_ANIM, () => {
|
||||||
phoneCallEndAnim()
|
phoneCallEndAnim();
|
||||||
});
|
});
|
||||||
|
|
||||||
RegisterNuiCallbackType(events.PHONE_END_CALL); // Fires when ending an ACTIVE call
|
RegisterNuiCallbackType(events.PHONE_END_CALL); // Fires when ending an ACTIVE call
|
||||||
@@ -104,6 +107,7 @@ onNet(events.PHONE_CALL_WAS_ENDED, () => {
|
|||||||
receiver: null,
|
receiver: null,
|
||||||
isTransmitter: null,
|
isTransmitter: null,
|
||||||
accepted: false,
|
accepted: false,
|
||||||
|
active: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
+36
-62
@@ -1,51 +1,12 @@
|
|||||||
import config from '../utils/config';
|
import config from '../utils/config';
|
||||||
import events from '../utils/events';
|
import events from '../utils/events';
|
||||||
import {phoneCloseAnim, phoneOpenAnim, removePhoneProp} from './functions';
|
import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions';
|
||||||
|
|
||||||
let prop = 0;
|
let prop = 0;
|
||||||
let isPhoneOpen = false;
|
let isPhoneOpen = false;
|
||||||
let propCreated = false;
|
let propCreated = false;
|
||||||
let phoneModel = 'prop_amb_phone'; // Refered to in newphoneProp function. Requires custom phone being streamed.
|
let phoneModel = 'prop_amb_phone'; // Refered to in newphoneProp function. Requires custom phone being streamed.
|
||||||
|
|
||||||
/* * * * * * * * * * * * *
|
|
||||||
*
|
|
||||||
* Register Command and Keybinding
|
|
||||||
*
|
|
||||||
* * * * * * * * * * * * */
|
|
||||||
|
|
||||||
RegisterCommand(
|
|
||||||
'phone:close',
|
|
||||||
async (source: any, args: string[], raw: any) => {
|
|
||||||
await phoneCloseAnim();
|
|
||||||
SetNuiFocus(false, false);
|
|
||||||
SendNuiMessage(
|
|
||||||
JSON.stringify({
|
|
||||||
app: 'PHONE',
|
|
||||||
method: 'setVisibility',
|
|
||||||
data: false,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
RegisterCommand(
|
|
||||||
'phone',
|
|
||||||
async () => {
|
|
||||||
//-- Toggles Phone
|
|
||||||
await Phone();
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
RegisterCommand(
|
|
||||||
'phone:open',
|
|
||||||
async () => {
|
|
||||||
await Phone();
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
|
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
|
||||||
|
|
||||||
/* * * * * * * * * * * * *
|
/* * * * * * * * * * * * *
|
||||||
@@ -66,7 +27,6 @@ const showPhone = async (): Promise<void> => {
|
|||||||
data: true,
|
data: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
sendPhoneConfig();
|
|
||||||
SetNuiFocus(true, true);
|
SetNuiFocus(true, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -84,13 +44,36 @@ const hidePhone = async (): Promise<void> => {
|
|||||||
SetNuiFocus(false, false);
|
SetNuiFocus(false, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const togglePhoneVisible = async (): Promise<void> => {
|
/* * * * * * * * * * * * *
|
||||||
if (isPhoneOpen) {
|
*
|
||||||
|
* Register Command and Keybinding
|
||||||
|
*
|
||||||
|
* * * * * * * * * * * * */
|
||||||
|
|
||||||
|
RegisterCommand(
|
||||||
|
'phone:close',
|
||||||
|
async () => {
|
||||||
await hidePhone();
|
await hidePhone();
|
||||||
} else {
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
RegisterCommand(
|
||||||
|
'phone',
|
||||||
|
async () => {
|
||||||
|
//-- Toggles Phone
|
||||||
|
await Phone();
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
RegisterCommand(
|
||||||
|
'phone:open',
|
||||||
|
async () => {
|
||||||
await showPhone();
|
await showPhone();
|
||||||
}
|
},
|
||||||
};
|
false
|
||||||
|
);
|
||||||
|
|
||||||
/* * * * * * * * * * * * *
|
/* * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
@@ -99,24 +82,17 @@ const togglePhoneVisible = async (): Promise<void> => {
|
|||||||
* * * * * * * * * * * * */
|
* * * * * * * * * * * * */
|
||||||
|
|
||||||
async function Phone(): Promise<void> {
|
async function Phone(): Promise<void> {
|
||||||
fetchOnInitialize()
|
fetchOnInitialize();
|
||||||
if (config.PhoneAsItem) {
|
if (config.PhoneAsItem) {
|
||||||
// TODO: Do promise callback here
|
// TODO: Do promise callback here
|
||||||
// const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem')
|
// const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem')
|
||||||
// if (!hasPhoneItem) return
|
// if (!hasPhoneItem) return
|
||||||
return await togglePhoneVisible();
|
|
||||||
}
|
}
|
||||||
await togglePhoneVisible();
|
if (isPhoneOpen) {
|
||||||
}
|
await hidePhone();
|
||||||
|
} else {
|
||||||
function sendPhoneConfig() {
|
await showPhone();
|
||||||
SendNuiMessage(
|
}
|
||||||
JSON.stringify({
|
|
||||||
app: 'PHONE',
|
|
||||||
method: 'phoneConfig',
|
|
||||||
data: config,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AddEventHandler('onResourceStop', function (resource: string) {
|
AddEventHandler('onResourceStop', function (resource: string) {
|
||||||
@@ -144,7 +120,6 @@ onNet('phone:sendCredentials', (number: string) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
|
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
|
||||||
|
|
||||||
/* * * * * * * * * * * * *
|
/* * * * * * * * * * * * *
|
||||||
@@ -157,7 +132,6 @@ function fetchOnInitialize() {
|
|||||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
|
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
|
||||||
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
|
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
|
||||||
emitNet(events.SELLOUT_FETCH_LISTING);
|
emitNet(events.SELLOUT_FETCH_LISTING);
|
||||||
@@ -191,7 +165,7 @@ on(`__cfx_nui:${events.OPEN_APP_DAILER}`, (data: any, cb: Function) => {
|
|||||||
|
|
||||||
RegisterNuiCallbackType('phone:close');
|
RegisterNuiCallbackType('phone:close');
|
||||||
on(`__cfx_nui:phone:close`, async (data: any, cb: Function) => {
|
on(`__cfx_nui:phone:close`, async (data: any, cb: Function) => {
|
||||||
await Phone();
|
await hidePhone();
|
||||||
cb();
|
cb();
|
||||||
}); // Called for when the phone is closed via the UI.
|
}); // Called for when the phone is closed via the UI.
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user