mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-02 06:28:52 +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
+869
-679
No files matched your search
+46
-55
@@ -2,9 +2,9 @@ import React from 'react';
|
||||
import './Phone.css';
|
||||
import './i18n';
|
||||
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 { ThemeProvider, Slide } from '@material-ui/core';
|
||||
import { Slide } from '@material-ui/core';
|
||||
import { useInitKeyboard } from './os/keyboard/hooks/useKeyboard';
|
||||
import { NotificationBar } from './os/notifications/components/NotificationBar';
|
||||
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 { usePhotoService } from './apps/camera/hooks/usePhotoService';
|
||||
import { useSettings } from './apps/settings/hooks/useSettings';
|
||||
import { useCallService } from './modal/hooks/useCallService';
|
||||
import { useModal } from './modal/hooks/useModal';
|
||||
import { useCallService } from './os/call/hooks/useCallService';
|
||||
import { useModal } from './os/call/hooks/useModal';
|
||||
import { useDialService } from './apps/dialer/hooks/useDialService';
|
||||
import InjectDebugData from './os/debug/InjectDebugData';
|
||||
import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
|
||||
import { usePhoneTheme } from './os/phone/hooks/usePhoneTheme';
|
||||
import { Snackbar } from './ui/components/Snackbar';
|
||||
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
|
||||
|
||||
function Phone() {
|
||||
const { modal } = useModal();
|
||||
@@ -35,12 +35,7 @@ function Phone() {
|
||||
|
||||
const [settings] = useSettings();
|
||||
|
||||
const {
|
||||
bottom,
|
||||
visibility,
|
||||
uncollapseNotifications,
|
||||
clickEventOverride,
|
||||
} = usePhoneVisibility();
|
||||
const { bottom, visibility } = usePhoneVisibility();
|
||||
|
||||
useNuiService();
|
||||
usePhoneService();
|
||||
@@ -56,58 +51,54 @@ function Phone() {
|
||||
useCallService();
|
||||
useDialService();
|
||||
|
||||
const currentTheme = usePhoneTheme();
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={currentTheme}>
|
||||
<Slide direction='up' in={visibility} mountOnEnter unmountOnExit>
|
||||
<div className='PhoneWrapper'>
|
||||
<div>
|
||||
<Slide direction='up' in={visibility}>
|
||||
<div className='PhoneWrapper'>
|
||||
<div>
|
||||
<div
|
||||
className='Phone'
|
||||
style={{
|
||||
transformOrigin: 'right bottom',
|
||||
transform: `scale(${settings.zoom}`,
|
||||
bottom,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
onClick={clickEventOverride}
|
||||
className='Phone'
|
||||
className='PhoneFrame'
|
||||
style={{
|
||||
transformOrigin: 'right bottom',
|
||||
transform: `scale(${settings.zoom}`,
|
||||
bottom,
|
||||
backgroundImage: `url(./media/frames/${settings.frame})`,
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
id='phone'
|
||||
className='PhoneScreen'
|
||||
style={{
|
||||
backgroundImage: `url(./media/backgrounds/${settings.wallpaper})`,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className='PhoneFrame'
|
||||
style={{
|
||||
backgroundImage: `url(./media/frames/${settings.frame})`,
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
id='phone'
|
||||
className='PhoneScreen'
|
||||
style={{
|
||||
backgroundImage: `url(./media/backgrounds/${settings.wallpaper})`,
|
||||
}}
|
||||
>
|
||||
<>
|
||||
<NotificationBar forceUncollapse={uncollapseNotifications} />
|
||||
<div className='PhoneAppContainer'>
|
||||
{modal ? (
|
||||
<CallModal />
|
||||
) : (
|
||||
<>
|
||||
<Route exact path='/' component={HomeApp} />
|
||||
{apps.map((App) => (
|
||||
<App.Route key={App.id} />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
<Snackbar />
|
||||
</div>
|
||||
<Navigation />
|
||||
</>
|
||||
</div>
|
||||
<>
|
||||
<NotificationBar />
|
||||
<div className='PhoneAppContainer'>
|
||||
{modal ? (
|
||||
<CallModal />
|
||||
) : (
|
||||
<>
|
||||
<Route exact path='/' component={HomeApp} />
|
||||
{apps.map((App) => (
|
||||
<App.Route key={App.id} />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
<NotificationAlert />
|
||||
<Snackbar />
|
||||
</div>
|
||||
<Navigation />
|
||||
</>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Slide>
|
||||
</ThemeProvider>
|
||||
</div>
|
||||
</Slide>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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([
|
||||
{
|
||||
app: 'DAILER',
|
||||
app: 'DIALER',
|
||||
method: 'setHistory',
|
||||
data: [
|
||||
{
|
||||
|
||||
@@ -21,100 +21,6 @@ import { useProfile } from '../hooks/useProfile';
|
||||
import ProfilePrompt from './profile/ProfilePrompt';
|
||||
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(() => ({
|
||||
backgroundModal: {
|
||||
background: 'black',
|
||||
@@ -188,3 +94,103 @@ export const TwitterApp = () => {
|
||||
</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 { useTweets } from '../../hooks/useTweets';
|
||||
import { useTwitterNotifications } from '../../hooks/useTwitterNotifications';
|
||||
import TweetList from './TweetList';
|
||||
|
||||
export function TweetListContainer() {
|
||||
const { tweets } = useTweets();
|
||||
const { setUnreadCount } = useTwitterNotifications();
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send('phone:fetchTweets', {});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (tweets?.length) {
|
||||
setUnreadCount(0);
|
||||
}
|
||||
}, [setUnreadCount, tweets]);
|
||||
|
||||
return <TweetList tweets={tweets} />;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ export const twitterState = {
|
||||
key: 'updateProfileSuccess',
|
||||
default: null,
|
||||
}),
|
||||
notification: atom({
|
||||
key: 'notification',
|
||||
default: null,
|
||||
unreadTweetsCount: atom({
|
||||
key: 'unreadTweetsCount',
|
||||
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 { 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';
|
||||
import { useTwitterNotifications } from './useTwitterNotifications';
|
||||
|
||||
/**
|
||||
* Perform all necessary processing/transforms from the raw database
|
||||
@@ -32,22 +29,7 @@ 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 { setNotification } = useTwitterNotifications();
|
||||
|
||||
const setProfile = useSetRecoilState(twitterState.profile);
|
||||
const setUpdateProfileLoading = useSetRecoilState(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export interface CallProps {
|
||||
active: boolean;
|
||||
accepted: boolean;
|
||||
isTransmitter: boolean;
|
||||
transmitter: string;
|
||||
|
||||
+2
-12
@@ -6,12 +6,8 @@ import { RecoilRoot } from 'recoil';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { Integrations } from '@sentry/tracing';
|
||||
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 SnackbarProvider from './ui/providers/SnackbarProvider';
|
||||
import { NotificationsProvider } from './os/notifications/providers/NotificationsProvider';
|
||||
import { PhoneContainer } from './PhoneContainer';
|
||||
|
||||
// Enable Sentry when config setting is true
|
||||
if (PhoneConfig.SentryErrorMetrics) {
|
||||
@@ -29,13 +25,7 @@ if (PhoneConfig.SentryErrorMetrics) {
|
||||
ReactDOM.render(
|
||||
<HashRouter>
|
||||
<RecoilRoot>
|
||||
<TwitterNotification />
|
||||
<BankNotification />
|
||||
<SnackbarProvider>
|
||||
<NotificationsProvider>
|
||||
<Phone />
|
||||
</NotificationsProvider>
|
||||
</SnackbarProvider>
|
||||
<PhoneContainer />
|
||||
</RecoilRoot>
|
||||
</HashRouter>,
|
||||
document.getElementById('root')
|
||||
|
||||
@@ -17,6 +17,14 @@
|
||||
"APPS_SELLOUT": "Market",
|
||||
"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_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper",
|
||||
"APPS_SETTINGS_OPTIONS_FRAME": "Frame",
|
||||
@@ -48,6 +56,7 @@
|
||||
"APPS_TWITTER_TIME_HOURS": "h",
|
||||
"APPS_TWITTER_TIME_DAYS": "d",
|
||||
"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_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%',
|
||||
},
|
||||
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;
|
||||
method: string;
|
||||
data: any;
|
||||
data: P;
|
||||
}
|
||||
|
||||
// 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') {
|
||||
for (const event of events) {
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { atom, useSetRecoilState, useRecoilValue } from 'recoil';
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
import { usePhone } from '../../phone/hooks/usePhone';
|
||||
|
||||
const keyboardState = {
|
||||
ArrowRight: atom({
|
||||
@@ -48,6 +48,7 @@ const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
|
||||
|
||||
export const useInitKeyboard = () => {
|
||||
const history = useHistory();
|
||||
const { closePhone } = usePhone();
|
||||
const getters = {
|
||||
ArrowRight: useRecoilValue(keyboardState.ArrowRight),
|
||||
ArrowLeft: useRecoilValue(keyboardState.ArrowLeft),
|
||||
@@ -58,21 +59,26 @@ export const useInitKeyboard = () => {
|
||||
Escape: useRecoilValue(keyboardState.Escape),
|
||||
};
|
||||
|
||||
const handlers = useRef(new Map());
|
||||
const setEscape = useSetRecoilState<any>(keyboardState.Escape);
|
||||
const setBackspace = useSetRecoilState(keyboardState.Backspace);
|
||||
|
||||
useEffect(
|
||||
function registerCustomKeys() {
|
||||
Object.keys(getters).forEach((g) => {
|
||||
handlers.current.set(g, getters[g]);
|
||||
});
|
||||
},
|
||||
[getters]
|
||||
);
|
||||
|
||||
useEffect(
|
||||
function handleNUIKeyboardMessage() {
|
||||
function onKeyUp(event) {
|
||||
const { key } = event;
|
||||
const callback = getters[key];
|
||||
if (
|
||||
isKeyValid(key) &&
|
||||
callback &&
|
||||
callback.handler &&
|
||||
callback.handler.call
|
||||
) {
|
||||
return callback.handler(event);
|
||||
const callback = handlers.current.get(key);
|
||||
if (isKeyValid(key) && callback && callback.call) {
|
||||
return callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,35 +88,22 @@ export const useInitKeyboard = () => {
|
||||
[getters]
|
||||
);
|
||||
|
||||
const escapeHandler = useCallback(() => Nui.send('phone:close'), []);
|
||||
|
||||
const backspaceHandler = useCallback((event) => {
|
||||
if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) {
|
||||
// Dont anything if we are typing something :)
|
||||
return;
|
||||
}
|
||||
history.goBack();
|
||||
}, [history]);
|
||||
const backspaceHandler = useCallback(
|
||||
(event) => {
|
||||
if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) {
|
||||
// Dont anything if we are typing something :)
|
||||
return;
|
||||
}
|
||||
history.goBack();
|
||||
},
|
||||
[history]
|
||||
);
|
||||
|
||||
useEffect(
|
||||
function registerDefaultHandlers() {
|
||||
setEscape({ handler: escapeHandler });
|
||||
setBackspace({ handler: backspaceHandler });
|
||||
handlers.current.set('Escape', () => closePhone());
|
||||
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 RadioButtonUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
import { usePhone } from '../../phone/hooks/usePhone';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -19,10 +18,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
}));
|
||||
|
||||
export const Navigation = () => {
|
||||
const closePhone = () => {
|
||||
console.log('Phone closed');
|
||||
Nui.send('phone:close');
|
||||
};
|
||||
const { closePhone } = usePhone();
|
||||
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
@@ -38,12 +34,12 @@ export const Navigation = () => {
|
||||
/>
|
||||
<BottomNavigationAction
|
||||
label='Close'
|
||||
value={() => closePhone()}
|
||||
value={closePhone}
|
||||
icon={<RadioButtonUncheckedIcon />}
|
||||
/>
|
||||
<BottomNavigationAction
|
||||
label='Back'
|
||||
value={() => history.goBack()}
|
||||
value={history.goBack}
|
||||
icon={<KeyboardArrowLeftIcon />}
|
||||
/>
|
||||
</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,
|
||||
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';
|
||||
import { NotificationItem } from './NotificationItem';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -67,9 +63,8 @@ const useStyles = makeStyles((theme) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean }) => {
|
||||
export const NotificationBar = () => {
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
|
||||
const { icons, notifications, removeNotification } = useNotifications();
|
||||
|
||||
@@ -120,41 +115,29 @@ export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Slide direction='down' in={forceUncollapse || uncollapsed}>
|
||||
<Slide direction='down' in={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);
|
||||
{notifications.map((notification, idx) => (
|
||||
<NotificationItem
|
||||
key={idx}
|
||||
onClose={(e) => {
|
||||
e.stopPropagation();
|
||||
if (notifications.length === 1) {
|
||||
setUncollapsed(false);
|
||||
}
|
||||
removeNotification(idx);
|
||||
}}
|
||||
onClickClose={() => {
|
||||
setUncollapsed(false);
|
||||
if (!notification.cantClose) {
|
||||
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>
|
||||
{...notification}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
</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 {
|
||||
app: string;
|
||||
id?: string;
|
||||
title: string;
|
||||
content?: React.ReactNode;
|
||||
icon?: JSX.Element;
|
||||
notificationIcon?: JSX.Element;
|
||||
href?: string;
|
||||
cantClose?: boolean;
|
||||
onClick?: (notification: INotification) => void;
|
||||
}
|
||||
|
||||
interface INotificationIcon {
|
||||
@@ -17,39 +27,143 @@ interface INotificationIcon {
|
||||
|
||||
export const NotificationsContext = createContext<{
|
||||
notifications: INotification[];
|
||||
currentAlert: INotification;
|
||||
icons: INotificationIcon[];
|
||||
count: number;
|
||||
removeAlerts(): void;
|
||||
addOrUpdateNotification(add: INotification, update?: INotification): void;
|
||||
addNotification(value: INotification): void;
|
||||
updateNotification(idx: number, value: INotification): 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);
|
||||
|
||||
export function NotificationsProvider({ children }) {
|
||||
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(
|
||||
(idx: number, value: INotification) => {
|
||||
setNotifications((all) => {
|
||||
const updated = [...all];
|
||||
updated.splice(idx, 0, value);
|
||||
updated.splice(idx, 1, value);
|
||||
return updated;
|
||||
});
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const removeNotification = useCallback((idx) => {
|
||||
const removeNotification = (idx) => {
|
||||
setNotifications((all) => {
|
||||
const updated = [...all];
|
||||
const updated = all;
|
||||
updated.splice(idx, 1);
|
||||
return updated;
|
||||
return [...updated];
|
||||
});
|
||||
}, []);
|
||||
};
|
||||
|
||||
const addNotification = useCallback((value: INotification) => {
|
||||
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(
|
||||
() =>
|
||||
notifications.reduce((icons, curr) => {
|
||||
@@ -64,13 +178,24 @@ export function NotificationsProvider({ children }) {
|
||||
[notifications]
|
||||
);
|
||||
|
||||
const removeAlerts = () => {
|
||||
setAlerts([]);
|
||||
setCurrentAlert(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<NotificationsContext.Provider
|
||||
value={{
|
||||
currentAlert,
|
||||
notifications,
|
||||
removeAlerts,
|
||||
addNotification,
|
||||
updateNotification,
|
||||
removeNotification,
|
||||
updateId,
|
||||
removeId,
|
||||
hasNotification,
|
||||
addNotificationAlert,
|
||||
addOrUpdateNotification,
|
||||
icons,
|
||||
count: notifications.length,
|
||||
}}
|
||||
|
||||
@@ -16,17 +16,16 @@ interface IOptions {
|
||||
* @param options Any options to pass to the addEventListener
|
||||
**/
|
||||
|
||||
export const useNuiEvent = (
|
||||
const defaultOptions = {};
|
||||
|
||||
export const useNuiEvent = <S = Record<string, unknown>>(
|
||||
app: string,
|
||||
method: string,
|
||||
handler: Function,
|
||||
options: IOptions = {},
|
||||
currentState?: Record<string, unknown>
|
||||
currentState?: S,
|
||||
options: IOptions = defaultOptions
|
||||
) => {
|
||||
|
||||
const savedHandler: MutableRefObject<any> = useRef();
|
||||
// Destructure passed options
|
||||
const { capture, passive, once } = options;
|
||||
|
||||
// When handler value changes set mutable ref to handler val
|
||||
useEffect(() => {
|
||||
@@ -44,15 +43,13 @@ export const useNuiEvent = (
|
||||
data: event.data,
|
||||
level: 1,
|
||||
});
|
||||
const newData = currentState ? { ...currentState, ...data } : data
|
||||
savedHandler.current(newData)
|
||||
const newData = currentState ? { ...currentState, ...data } : data;
|
||||
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
|
||||
return () => window.removeEventListener(eventName, eventListener, opts);
|
||||
}, [app, method, capture, passive, once, currentState]);
|
||||
return () => window.removeEventListener(eventName, eventListener, options);
|
||||
}, [app, method, currentState, options]);
|
||||
};
|
||||
@@ -1,15 +1,24 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { phoneState } from './state';
|
||||
import { IServerConfig } from '../../../common/typings/config';
|
||||
import ServerConfig from '../../../config.autogen.json';
|
||||
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
|
||||
interface IUsePhone {
|
||||
visibility: boolean;
|
||||
setVisibility(v: boolean): void;
|
||||
config?: IServerConfig;
|
||||
openPhone(): void;
|
||||
closePhone(): void;
|
||||
}
|
||||
|
||||
export const usePhone = (): IUsePhone => {
|
||||
const [visibility, setVisibility] = useRecoilState(phoneState.visibility);
|
||||
return { visibility, setVisibility, config: ServerConfig as any };
|
||||
const { removeAlerts } = useNotifications();
|
||||
|
||||
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 { 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 = () => {
|
||||
const { setVisibility, visibility } = usePhone();
|
||||
const { count } = useNotifications();
|
||||
const [visibility, setVisibility] = useRecoilState(phoneState.visibility);
|
||||
const { currentAlert } = useNotifications();
|
||||
const [{ zoom }] = useSettings();
|
||||
|
||||
const [notifVisibility, setNotifVisibility] = useState<boolean>(false);
|
||||
|
||||
const isNotificationVisibleOnly = useMemo(
|
||||
() => !!(!visibility && count > 0),
|
||||
[visibility, count]
|
||||
);
|
||||
const [isNotificationVisibleOnly, setNotificationVisibleOnly] = useState<
|
||||
boolean
|
||||
>(false);
|
||||
|
||||
useEffect(() => {
|
||||
setNotificationVisibleOnly(!!(!visibility && currentAlert));
|
||||
}, [visibility, currentAlert]);
|
||||
|
||||
const notificationTimer = useRef<NodeJS.Timeout>();
|
||||
|
||||
useEffect(() => {
|
||||
if (isNotificationVisibleOnly) {
|
||||
setNotifVisibility(true);
|
||||
clearTimeout(notificationTimer.current);
|
||||
if (notificationTimer.current) {
|
||||
clearTimeout(notificationTimer.current);
|
||||
notificationTimer.current = undefined;
|
||||
}
|
||||
notificationTimer.current = setTimeout(() => {
|
||||
setVisibility(false);
|
||||
setNotifVisibility(false);
|
||||
}, 5000);
|
||||
}, DEFAULT_ALERT_HIDE_TIME);
|
||||
}
|
||||
return () => clearTimeout(notificationTimer.current);
|
||||
return () => {
|
||||
clearTimeout(notificationTimer.current);
|
||||
notificationTimer.current = undefined;
|
||||
};
|
||||
}, [isNotificationVisibleOnly, setVisibility]);
|
||||
|
||||
const bottom = useMemo(() => {
|
||||
if (isNotificationVisibleOnly) {
|
||||
return `calc(-60% * ${zoom})`;
|
||||
return `calc(-70% * ${zoom})`;
|
||||
}
|
||||
return 0;
|
||||
}, [isNotificationVisibleOnly, zoom]);
|
||||
|
||||
const clickEventOverride = useCallback(
|
||||
(e) => {
|
||||
if (isNotificationVisibleOnly) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setVisibility(true);
|
||||
}
|
||||
},
|
||||
[setVisibility, isNotificationVisibleOnly]
|
||||
);
|
||||
|
||||
return {
|
||||
bottom,
|
||||
visibility: notifVisibility || visibility,
|
||||
uncollapseNotifications: isNotificationVisibleOnly,
|
||||
clickEventOverride,
|
||||
};
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
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';
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
@@ -29,7 +29,7 @@ export const AppContent = ({
|
||||
backdrop,
|
||||
onClickBackdrop,
|
||||
...props
|
||||
}: AppContentTypes) => {
|
||||
}: AppContentTypes & BoxProps) => {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<Paper className={classes.wrapper} square>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import React from 'react';
|
||||
import { AppIcon } from './AppIcon';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Grid, makeStyles, Tooltip, Zoom } from '@material-ui/core';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useKeyboard } from '../../os/keyboard/hooks/useKeyboard';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -19,16 +18,9 @@ const useStyles = makeStyles((theme) => ({
|
||||
}));
|
||||
|
||||
export const GridMenu = ({ items, Component = AppIcon }) => {
|
||||
const setKey = useKeyboard();
|
||||
const classes = useStyles();
|
||||
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
|
||||
return (
|
||||
<Grid container justify='center'>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import events from '../utils/events';
|
||||
import { ICall } from '../../phone/src/common/typings/call';
|
||||
import {phoneCallStartAnim, phoneCallEndAnim} from './functions';
|
||||
import { phoneCallStartAnim, phoneCallEndAnim } from './functions';
|
||||
|
||||
const exp = (global as any).exports;
|
||||
|
||||
@@ -21,6 +21,7 @@ onNet(
|
||||
app: 'CALL',
|
||||
method: 'setCaller',
|
||||
data: {
|
||||
active: true,
|
||||
transmitter: transmitter,
|
||||
receiver: receiver,
|
||||
isTransmitter: isTransmitter,
|
||||
@@ -41,12 +42,13 @@ onNet(
|
||||
events.PHONE_CALL_WAS_ACCEPTED,
|
||||
(channelId: number, currentCall: ICall, isTransmitter: boolean) => {
|
||||
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(
|
||||
JSON.stringify({
|
||||
app: 'CALL',
|
||||
method: 'setCaller',
|
||||
data: {
|
||||
active: true,
|
||||
transmitter: currentCall.transmitter,
|
||||
receiver: currentCall.receiver,
|
||||
isTransmitter: isTransmitter,
|
||||
@@ -75,13 +77,14 @@ onNet(events.PHONE_CALL_WAS_REJECTED, () => {
|
||||
receiver: null,
|
||||
isTransmitter: null,
|
||||
accepted: false,
|
||||
active: false,
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
onNet(events.PHONE_CALL_SEND_HANGUP_ANIM, () => {
|
||||
phoneCallEndAnim()
|
||||
phoneCallEndAnim();
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(events.PHONE_END_CALL); // Fires when ending an ACTIVE call
|
||||
@@ -104,6 +107,7 @@ onNet(events.PHONE_CALL_WAS_ENDED, () => {
|
||||
receiver: null,
|
||||
isTransmitter: null,
|
||||
accepted: false,
|
||||
active: false,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
+36
-62
@@ -1,51 +1,12 @@
|
||||
import config from '../utils/config';
|
||||
import events from '../utils/events';
|
||||
import {phoneCloseAnim, phoneOpenAnim, removePhoneProp} from './functions';
|
||||
import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions';
|
||||
|
||||
let prop = 0;
|
||||
let isPhoneOpen = false;
|
||||
let propCreated = false;
|
||||
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');
|
||||
|
||||
/* * * * * * * * * * * * *
|
||||
@@ -66,7 +27,6 @@ const showPhone = async (): Promise<void> => {
|
||||
data: true,
|
||||
})
|
||||
);
|
||||
sendPhoneConfig();
|
||||
SetNuiFocus(true, true);
|
||||
};
|
||||
|
||||
@@ -84,13 +44,36 @@ const hidePhone = async (): Promise<void> => {
|
||||
SetNuiFocus(false, false);
|
||||
};
|
||||
|
||||
const togglePhoneVisible = async (): Promise<void> => {
|
||||
if (isPhoneOpen) {
|
||||
/* * * * * * * * * * * * *
|
||||
*
|
||||
* Register Command and Keybinding
|
||||
*
|
||||
* * * * * * * * * * * * */
|
||||
|
||||
RegisterCommand(
|
||||
'phone:close',
|
||||
async () => {
|
||||
await hidePhone();
|
||||
} else {
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
RegisterCommand(
|
||||
'phone',
|
||||
async () => {
|
||||
//-- Toggles Phone
|
||||
await Phone();
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
RegisterCommand(
|
||||
'phone:open',
|
||||
async () => {
|
||||
await showPhone();
|
||||
}
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
/* * * * * * * * * * * * *
|
||||
*
|
||||
@@ -99,24 +82,17 @@ const togglePhoneVisible = async (): Promise<void> => {
|
||||
* * * * * * * * * * * * */
|
||||
|
||||
async function Phone(): Promise<void> {
|
||||
fetchOnInitialize()
|
||||
fetchOnInitialize();
|
||||
if (config.PhoneAsItem) {
|
||||
// TODO: Do promise callback here
|
||||
// const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem')
|
||||
// if (!hasPhoneItem) return
|
||||
return await togglePhoneVisible();
|
||||
}
|
||||
await togglePhoneVisible();
|
||||
}
|
||||
|
||||
function sendPhoneConfig() {
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: 'PHONE',
|
||||
method: 'phoneConfig',
|
||||
data: config,
|
||||
})
|
||||
);
|
||||
if (isPhoneOpen) {
|
||||
await hidePhone();
|
||||
} else {
|
||||
await showPhone();
|
||||
}
|
||||
}
|
||||
|
||||
AddEventHandler('onResourceStop', function (resource: string) {
|
||||
@@ -144,7 +120,6 @@ onNet('phone:sendCredentials', (number: string) => {
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
|
||||
|
||||
/* * * * * * * * * * * * *
|
||||
@@ -157,7 +132,6 @@ function fetchOnInitialize() {
|
||||
emitNet(events.CONTACTS_GET_CONTACTS);
|
||||
}
|
||||
|
||||
|
||||
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
|
||||
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
|
||||
emitNet(events.SELLOUT_FETCH_LISTING);
|
||||
@@ -191,7 +165,7 @@ on(`__cfx_nui:${events.OPEN_APP_DAILER}`, (data: any, cb: Function) => {
|
||||
|
||||
RegisterNuiCallbackType('phone:close');
|
||||
on(`__cfx_nui:phone:close`, async (data: any, cb: Function) => {
|
||||
await Phone();
|
||||
await hidePhone();
|
||||
cb();
|
||||
}); // Called for when the phone is closed via the UI.
|
||||
|
||||
|
||||
Reference in new issue
Block a user