mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Task/improve hardcoded styles and types (#107)
* Add working notifications with only twitter for now * feat(notification-bar): I didnt copy from NP * feat(notifications): Collapse when no more notifications after closing one * Improve overall messages styling code * Improve Routing performance * improve use keyboard hook * Remove unused returns * Button hover color :) * Button hover color :) x2 * Added hover style to containedPrimary msg btn * Replace custom components for custom theme providers for Messages and Contacts apps * Improve createAppThemeProvider * Improve createAppThemeProvider * Final housekeeping for messages styles * Change placeholder to label in Contacts app text fields * Fix alerts style with navigation and fix calc copy alerrt * Split Phone code for snackbar * Add more options and style Context Menu * Enable Sellout theme provider and make it work with light themes
This commit is contained in:
1 parent
75e23b783c
commit
4acb214ec9
56 files changed
+738
-578
No files matched your search
@@ -0,0 +1,16 @@
|
||||
import React from 'react';
|
||||
import { Route } from 'react-router-dom';
|
||||
import { AppWithStartup } from './AppWithStartup';
|
||||
|
||||
export const AppRoute = ({ id, component: Component, ...rest }) => {
|
||||
return (
|
||||
<Route
|
||||
{...rest}
|
||||
render={() => (
|
||||
<AppWithStartup id={id}>
|
||||
<Component />
|
||||
</AppWithStartup>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { useEffect } from 'react';
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
|
||||
export const AppWithStartup = ({ children, id }) => {
|
||||
useEffect(() => {
|
||||
Nui.send(`phone:app:${id}`);
|
||||
}, [id]);
|
||||
return children;
|
||||
};
|
||||
@@ -0,0 +1,189 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
blue,
|
||||
common,
|
||||
grey,
|
||||
green,
|
||||
purple,
|
||||
yellow,
|
||||
red,
|
||||
} from '@material-ui/core/colors';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import {
|
||||
faAd,
|
||||
faPlaneArrival,
|
||||
faPhoneAlt,
|
||||
faWonSign,
|
||||
faStickyNote,
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
import { faTwitter } from '@fortawesome/free-brands-svg-icons';
|
||||
|
||||
import ContactsIcon from '@material-ui/icons/Contacts';
|
||||
import SettingsIcon from '@material-ui/icons/Settings';
|
||||
import MessageIcon from '@material-ui/icons/Message';
|
||||
import { CalculatorIcon } from '../../../apps/calculator/components/CalculatorIcon';
|
||||
import CameraAltIcon from '@material-ui/icons/CameraAlt';
|
||||
import { DialerApp } from '../../../apps/dialer/components/DialerApp';
|
||||
import { ContactsApp } from '../../../apps/contacts/components/ContactsApp';
|
||||
import { CalculatorApp } from '../../../apps/calculator/components/CalculatorApp';
|
||||
import { SettingsApp } from '../../../apps/settings/components/SettingsApp';
|
||||
import { BankApp } from '../../../apps/bank/components/BankApp';
|
||||
import { MessagesApp } from '../../../apps/messages/components/MessagesApp';
|
||||
import { TwitterApp } from '../../../apps/twitter/components/TwitterApp';
|
||||
import { ExampleApp } from '../../../apps/example/components/ExampleApp';
|
||||
import { SelloutApp } from '../../../apps/sellout/components/SelloutApp';
|
||||
import { NotesApp } from '../../../apps/notes/NotesApp';
|
||||
import CameraApp from '../../../apps/camera/components/CameraApp';
|
||||
import { AppRoute } from '../components/AppRoute';
|
||||
import {
|
||||
MESSAGES_APP_PRIMARY_COLOR,
|
||||
MESSAGES_APP_TEXT_COLOR,
|
||||
} from '../../../apps/messages/messages.theme';
|
||||
import {
|
||||
CONTACTS_APP_PRIMARY_COLOR,
|
||||
CONTACTS_APP_TEXT_COLOR,
|
||||
} from '../../../apps/contacts/contacts.theme';
|
||||
|
||||
export interface IAppConfig {
|
||||
id: string;
|
||||
nameLocale: string;
|
||||
icon: JSX.Element;
|
||||
notificationIcon: JSX.Element;
|
||||
backgroundColor: string;
|
||||
color: string;
|
||||
path: string;
|
||||
Route: React.FC;
|
||||
}
|
||||
|
||||
export const APPS: IAppConfig[] = [
|
||||
{
|
||||
id: 'DIALER',
|
||||
nameLocale: 'APPS_DIALER',
|
||||
icon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
|
||||
backgroundColor: green[600],
|
||||
color: common.white,
|
||||
path: '/phone',
|
||||
Route: () => <AppRoute id='DIALER' path='/phone' component={DialerApp} />,
|
||||
},
|
||||
{
|
||||
id: 'MESSAGES',
|
||||
nameLocale: 'APPS_MESSAGES',
|
||||
icon: <MessageIcon fontSize='default' />,
|
||||
notificationIcon: <MessageIcon fontSize='small' />,
|
||||
backgroundColor: MESSAGES_APP_PRIMARY_COLOR,
|
||||
color: MESSAGES_APP_TEXT_COLOR,
|
||||
path: '/messages',
|
||||
Route: () => (
|
||||
<AppRoute id='MESSAGE' path='/messages' component={MessagesApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'CONTACTS',
|
||||
nameLocale: 'APPS_CONTACTS',
|
||||
icon: <ContactsIcon />,
|
||||
notificationIcon: <ContactsIcon fontSize='small' />,
|
||||
backgroundColor: CONTACTS_APP_PRIMARY_COLOR,
|
||||
color: CONTACTS_APP_TEXT_COLOR,
|
||||
path: '/contacts',
|
||||
Route: () => (
|
||||
<AppRoute id='CONTACTS' path='/contacts' component={ContactsApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'CALCULATOR',
|
||||
nameLocale: 'APPS_CALCULATOR',
|
||||
icon: <CalculatorIcon />,
|
||||
notificationIcon: <CalculatorIcon fontSize='small' />,
|
||||
backgroundColor: purple[500],
|
||||
color: grey[50],
|
||||
path: '/calculator',
|
||||
Route: () => (
|
||||
<AppRoute id='CALCULATOR' path='/calculator' component={CalculatorApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'SETTINGS',
|
||||
nameLocale: 'APPS_SETTINGS',
|
||||
icon: <SettingsIcon />,
|
||||
notificationIcon: <SettingsIcon fontSize='small' />,
|
||||
backgroundColor: '#383838',
|
||||
color: grey[50],
|
||||
path: '/settings',
|
||||
Route: () => (
|
||||
<AppRoute id='SETTINGS' path='/settings' component={SettingsApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'BANK',
|
||||
nameLocale: 'APPS_BANK',
|
||||
icon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
|
||||
backgroundColor: blue[900],
|
||||
color: common.white,
|
||||
path: '/bank',
|
||||
Route: () => <AppRoute id='BANK' path='/bank' component={BankApp} />,
|
||||
},
|
||||
{
|
||||
id: 'TWITTER',
|
||||
nameLocale: 'APPS_TWITTER',
|
||||
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
|
||||
backgroundColor: blue[600],
|
||||
color: common.white,
|
||||
path: '/twitter',
|
||||
Route: () => (
|
||||
<AppRoute id='TWITTER' path='/twitter' component={TwitterApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'SELLOUT',
|
||||
nameLocale: 'APPS_SELLOUT',
|
||||
icon: <FontAwesomeIcon icon={faAd} fixedWidth />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faAd} fixedWidth size='xs' />,
|
||||
backgroundColor: red[500],
|
||||
color: common.white,
|
||||
path: '/sellout',
|
||||
Route: () => (
|
||||
<AppRoute id='SELLOUT' path='/sellout' component={SelloutApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'NOTES',
|
||||
nameLocale: 'APPS_NOTES',
|
||||
icon: <FontAwesomeIcon icon={faStickyNote} fixedWidth />,
|
||||
notificationIcon: (
|
||||
<FontAwesomeIcon icon={faStickyNote} fixedWidth size='xs' />
|
||||
),
|
||||
backgroundColor: yellow[800],
|
||||
color: common.white,
|
||||
path: '/notes',
|
||||
Route: () => <AppRoute id='NOTES' path='/notes' component={NotesApp} />,
|
||||
},
|
||||
{
|
||||
id: 'CAMERA',
|
||||
nameLocale: 'APPS_CAMERA',
|
||||
icon: <CameraAltIcon fontSize='large' />,
|
||||
notificationIcon: <CameraAltIcon fontSize='small' />,
|
||||
backgroundColor: grey['A400'],
|
||||
color: common.white,
|
||||
path: '/camera',
|
||||
Route: () => <AppRoute id='CAMERA' path='/camera' component={CameraApp} />,
|
||||
},
|
||||
];
|
||||
|
||||
// Example app only in dev
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
APPS.push({
|
||||
id: 'EXAMPLE',
|
||||
nameLocale: 'APPS_EXAMPLE',
|
||||
icon: <FontAwesomeIcon icon={faPlaneArrival} size='sm' />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faPlaneArrival} size='xs' />,
|
||||
backgroundColor: blue[500],
|
||||
color: blue[50],
|
||||
path: '/example',
|
||||
Route: () => (
|
||||
<AppRoute id='EXAMPLE' path='/example' component={ExampleApp} />
|
||||
),
|
||||
});
|
||||
}
|
||||
@@ -1,238 +1,22 @@
|
||||
import React, { useCallback, useEffect, useMemo } from 'react';
|
||||
import {
|
||||
blue,
|
||||
common,
|
||||
grey,
|
||||
green,
|
||||
purple,
|
||||
yellow,
|
||||
red,
|
||||
amber,
|
||||
} from '@material-ui/core/colors';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import {
|
||||
faAd,
|
||||
faPlaneArrival,
|
||||
faPhoneAlt,
|
||||
faWonSign,
|
||||
faStickyNote,
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
import { faTwitter } from '@fortawesome/free-brands-svg-icons';
|
||||
|
||||
import ContactsIcon from '@material-ui/icons/Contacts';
|
||||
import SettingsIcon from '@material-ui/icons/Settings';
|
||||
import MessageIcon from '@material-ui/icons/Message';
|
||||
import { atom, useRecoilState } from 'recoil';
|
||||
import { CalculatorIcon } from '../../../apps/calculator/components/CalculatorIcon';
|
||||
import CameraAltIcon from '@material-ui/icons/CameraAlt';
|
||||
import { Route } from 'react-router-dom';
|
||||
import { DialerApp } from '../../../apps/dialer/components/DialerApp';
|
||||
import { ContactsApp } from '../../../apps/contacts/components/ContactsApp';
|
||||
import { CalculatorApp } from '../../../apps/calculator/components/CalculatorApp';
|
||||
import { SettingsApp } from '../../../apps/settings/components/SettingsApp';
|
||||
import { BankApp } from '../../../apps/bank/components/BankApp';
|
||||
import { MessagesApp } from '../../../apps/messages/components/MessagesApp';
|
||||
import { TwitterApp } from '../../../apps/twitter/components/TwitterApp';
|
||||
import { ExampleApp } from '../../../apps/example/components/ExampleApp';
|
||||
import { SelloutApp } from '../../../apps/sellout/components/SelloutApp';
|
||||
import { NotesApp } from '../../../apps/notes/NotesApp';
|
||||
import CameraApp from '../../../apps/camera/components/CameraApp';
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
||||
|
||||
export interface IAppConfig {
|
||||
id: string;
|
||||
nameLocale: string;
|
||||
icon: JSX.Element;
|
||||
notificationIcon: JSX.Element;
|
||||
backgroundColor: string;
|
||||
color: string;
|
||||
path: string;
|
||||
Route: React.FC;
|
||||
}
|
||||
|
||||
type AppsRepository = { preinstalled: IAppConfig[] };
|
||||
|
||||
const AppWithStartup = ({ children, id }) => {
|
||||
useEffect(() => {
|
||||
Nui.send(`phone:app:${id}`);
|
||||
}, [id]);
|
||||
return children;
|
||||
};
|
||||
|
||||
const AppRoute = ({ id, component: Component, ...rest }) => {
|
||||
return (
|
||||
<Route
|
||||
{...rest}
|
||||
render={() => (
|
||||
<AppWithStartup id={id}>
|
||||
<Component />
|
||||
</AppWithStartup>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const appsState = atom<AppsRepository>({
|
||||
key: 'apps',
|
||||
default: {
|
||||
preinstalled: [
|
||||
{
|
||||
id: 'DIALER',
|
||||
nameLocale: 'APPS_DIALER',
|
||||
icon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faPhoneAlt} size='xs' />,
|
||||
backgroundColor: green[600],
|
||||
color: common.white,
|
||||
path: '/phone',
|
||||
Route: () => (
|
||||
<AppRoute id='DIALER' path='/phone' component={DialerApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'MESSAGES',
|
||||
nameLocale: 'APPS_MESSAGES',
|
||||
icon: <MessageIcon fontSize='default' />,
|
||||
notificationIcon: <MessageIcon fontSize='small' />,
|
||||
backgroundColor: amber[700],
|
||||
color: common.white,
|
||||
path: '/messages',
|
||||
Route: () => (
|
||||
<AppRoute id='MESSAGE' path='/messages' component={MessagesApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'CONTACTS',
|
||||
nameLocale: 'APPS_CONTACTS',
|
||||
icon: <ContactsIcon />,
|
||||
notificationIcon: <ContactsIcon fontSize='small' />,
|
||||
backgroundColor: blue[500],
|
||||
color: common.white,
|
||||
path: '/contacts',
|
||||
Route: () => (
|
||||
<AppRoute id='CONTACTS' path='/contacts' component={ContactsApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'CALCULATOR',
|
||||
nameLocale: 'APPS_CALCULATOR',
|
||||
icon: <CalculatorIcon />,
|
||||
notificationIcon: <CalculatorIcon fontSize='small' />,
|
||||
backgroundColor: purple[500],
|
||||
color: grey[50],
|
||||
path: '/calculator',
|
||||
Route: () => (
|
||||
<AppRoute
|
||||
id='CALCULATOR'
|
||||
path='/calculator'
|
||||
component={CalculatorApp}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'SETTINGS',
|
||||
nameLocale: 'APPS_SETTINGS',
|
||||
icon: <SettingsIcon />,
|
||||
notificationIcon: <SettingsIcon fontSize='small' />,
|
||||
backgroundColor: '#383838',
|
||||
color: grey[50],
|
||||
path: '/settings',
|
||||
Route: () => (
|
||||
<AppRoute id='SETTINGS' path='/settings' component={SettingsApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'BANK',
|
||||
nameLocale: 'APPS_BANK',
|
||||
icon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faWonSign} size='xs' />,
|
||||
backgroundColor: blue[900],
|
||||
color: common.white,
|
||||
path: '/bank',
|
||||
Route: () => <AppRoute id='BANK' path='/bank' component={BankApp} />,
|
||||
},
|
||||
{
|
||||
id: 'TWITTER',
|
||||
nameLocale: 'APPS_TWITTER',
|
||||
icon: <FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />,
|
||||
notificationIcon: (
|
||||
<FontAwesomeIcon icon={faTwitter} fixedWidth size='xs' />
|
||||
),
|
||||
backgroundColor: blue[600],
|
||||
color: common.white,
|
||||
path: '/twitter',
|
||||
Route: () => (
|
||||
<AppRoute id='TWITTER' path='/twitter' component={TwitterApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'SELLOUT',
|
||||
nameLocale: 'APPS_SELLOUT',
|
||||
icon: <FontAwesomeIcon icon={faAd} fixedWidth />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faAd} fixedWidth size='xs' />,
|
||||
backgroundColor: red[500],
|
||||
color: common.white,
|
||||
path: '/sellout',
|
||||
Route: () => (
|
||||
<AppRoute id='SELLOUT' path='/sellout' component={SelloutApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'NOTES',
|
||||
nameLocale: 'APPS_NOTES',
|
||||
icon: <FontAwesomeIcon icon={faStickyNote} fixedWidth />,
|
||||
notificationIcon: (
|
||||
<FontAwesomeIcon icon={faStickyNote} fixedWidth size='xs' />
|
||||
),
|
||||
backgroundColor: yellow[800],
|
||||
color: common.white,
|
||||
path: '/notes',
|
||||
Route: () => <AppRoute id='NOTES' path='/notes' component={NotesApp} />,
|
||||
},
|
||||
{
|
||||
id: 'CAMERA',
|
||||
nameLocale: 'APPS_CAMERA',
|
||||
icon: <CameraAltIcon fontSize='large' />,
|
||||
notificationIcon: <CameraAltIcon fontSize='small' />,
|
||||
backgroundColor: grey['A400'],
|
||||
color: common.white,
|
||||
path: '/camera',
|
||||
Route: () => (
|
||||
<AppRoute id='CAMERA' path='/camera' component={CameraApp} />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'EXAMPLE',
|
||||
nameLocale: 'APPS_EXAMPLE',
|
||||
icon: <FontAwesomeIcon icon={faPlaneArrival} size='sm' />,
|
||||
notificationIcon: <FontAwesomeIcon icon={faPlaneArrival} size='xs' />,
|
||||
backgroundColor: blue[500],
|
||||
color: blue[50],
|
||||
path: '/example',
|
||||
Route: () => (
|
||||
<AppRoute id='EXAMPLE' path='/example' component={ExampleApp} />
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
import { APPS, IAppConfig } from '../config/apps';
|
||||
|
||||
export const useApps = () => {
|
||||
const { icons } = useNotifications();
|
||||
const [apps, setApps] = useRecoilState<AppsRepository>(appsState);
|
||||
const allApps = useMemo(
|
||||
const apps = useMemo(
|
||||
() =>
|
||||
[...apps.preinstalled].map((a) => ({
|
||||
APPS.map((a) => ({
|
||||
...a,
|
||||
notification: icons.find((i) => i.key === a.id),
|
||||
})),
|
||||
[apps.preinstalled, icons]
|
||||
[icons]
|
||||
);
|
||||
const getApp = useCallback(
|
||||
(id: string): IAppConfig => allApps.find((a) => a.id === id) || null,
|
||||
[allApps]
|
||||
(id: string): IAppConfig => apps.find((a) => a.id === id) || null,
|
||||
[apps]
|
||||
);
|
||||
return { apps, allApps, setApps, getApp };
|
||||
return { apps, getApp };
|
||||
};
|
||||
|
||||
export const useApp = (id: string): IAppConfig => {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { createMuiTheme, ThemeProvider } from '@material-ui/core';
|
||||
import { deepMergeObjects } from './deepMergeObjects';
|
||||
import { usePhoneTheme } from '../../phone/hooks/usePhoneTheme';
|
||||
|
||||
export function createAppThemeProvider(theme: {} = {}) {
|
||||
const AppThemeProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const phoneTheme = usePhoneTheme();
|
||||
const mergedTheme = useMemo(() => {
|
||||
return createMuiTheme(deepMergeObjects(phoneTheme, theme));
|
||||
}, [phoneTheme]);
|
||||
return <ThemeProvider theme={mergedTheme}>{children}</ThemeProvider>;
|
||||
};
|
||||
|
||||
return AppThemeProvider;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @credits https://stackoverflow.com/questions/27936772/how-to-deep-merge-instead-of-shallow-merge
|
||||
* Simple object check.
|
||||
* @param item
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isObject(item) {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep merge two objects.
|
||||
* @param target
|
||||
* @param ...sources
|
||||
*/
|
||||
export function deepMergeObjects(target, ...sources) {
|
||||
if (!sources.length) return target;
|
||||
const source = sources.shift();
|
||||
|
||||
if (isObject(target) && isObject(source)) {
|
||||
for (const key in source) {
|
||||
if (isObject(source[key])) {
|
||||
if (!target[key]) Object.assign(target, { [key]: {} });
|
||||
deepMergeObjects(target[key], source[key]);
|
||||
} else {
|
||||
Object.assign(target, { [key]: source[key] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return deepMergeObjects(target, ...sources);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { atom, useSetRecoilState, useRecoilValue } from 'recoil';
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
|
||||
const keyboardState = {
|
||||
ArrowRight: atom({
|
||||
@@ -45,6 +47,7 @@ const validKeys = [
|
||||
const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
|
||||
|
||||
export const useInitKeyboard = () => {
|
||||
const history = useHistory();
|
||||
const getters = {
|
||||
ArrowRight: useRecoilValue(keyboardState.ArrowRight),
|
||||
ArrowLeft: useRecoilValue(keyboardState.ArrowLeft),
|
||||
@@ -56,6 +59,7 @@ export const useInitKeyboard = () => {
|
||||
};
|
||||
|
||||
const setEscape = useSetRecoilState<any>(keyboardState.Escape);
|
||||
const setBackspace = useSetRecoilState(keyboardState.Backspace);
|
||||
|
||||
useEffect(
|
||||
function handleNUIKeyboardMessage() {
|
||||
@@ -68,7 +72,7 @@ export const useInitKeyboard = () => {
|
||||
callback.handler &&
|
||||
callback.handler.call
|
||||
) {
|
||||
return callback.handler();
|
||||
return callback.handler(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,11 +82,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]);
|
||||
|
||||
useEffect(
|
||||
function registerEscapeHandler() {
|
||||
setEscape({ handler: () => console.log('close phone') });
|
||||
function registerDefaultHandlers() {
|
||||
setEscape({ handler: escapeHandler });
|
||||
setBackspace({ handler: backspaceHandler });
|
||||
},
|
||||
[setEscape]
|
||||
[setEscape, setBackspace, history, escapeHandler, backspaceHandler]
|
||||
);
|
||||
};
|
||||
|
||||
@@ -92,7 +107,6 @@ export const useKeyboard = () => {
|
||||
ArrowLeft: useSetRecoilState(keyboardState.ArrowLeft),
|
||||
ArrowUp: useSetRecoilState(keyboardState.ArrowUp),
|
||||
ArrowDown: useSetRecoilState(keyboardState.ArrowDown),
|
||||
Backspace: useSetRecoilState(keyboardState.Backspace),
|
||||
Enter: useSetRecoilState(keyboardState.Enter),
|
||||
};
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
height: '30px',
|
||||
width: '100%',
|
||||
color: theme.palette.text.primary,
|
||||
zIndex: 10,
|
||||
zIndex: 99,
|
||||
paddingLeft: '15px',
|
||||
paddingRight: '10px',
|
||||
position: 'relative',
|
||||
@@ -52,7 +52,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
width: '100%',
|
||||
position: 'absolute',
|
||||
top: '30px',
|
||||
zIndex: 9,
|
||||
zIndex: 98,
|
||||
},
|
||||
closeNotifBtn: {
|
||||
position: 'absolute',
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { matchPath, useHistory } from 'react-router-dom';
|
||||
import { atom, useRecoilState } from 'recoil';
|
||||
import { IAppConfig, useApps } from '../../apps/hooks/useApps';
|
||||
import { IAppConfig } from '../../apps/config/apps';
|
||||
import { useApps } from '../../apps/hooks/useApps';
|
||||
|
||||
const state = {
|
||||
recentlyUsed: atom({
|
||||
@@ -23,24 +24,27 @@ const unshiftApp = (arr: IAppConfig[], app) => {
|
||||
|
||||
export const useQuickAccess = () => {
|
||||
const history = useHistory();
|
||||
const { allApps, getApp } = useApps();
|
||||
const { apps, getApp } = useApps();
|
||||
const [recentlyUsed, setRecentlyUsed] = useRecoilState<IAppConfig[]>(
|
||||
state.recentlyUsed
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setRecentlyUsed([getApp("SETTINGS")])
|
||||
}, [getApp, setRecentlyUsed])
|
||||
setRecentlyUsed([getApp('SETTINGS')]);
|
||||
}, [getApp, setRecentlyUsed]);
|
||||
|
||||
const listener = useCallback((location) => {
|
||||
const newState = [...recentlyUsed];
|
||||
allApps.forEach((app) => {
|
||||
if (matchPath(location.pathname, { path: app.path, exact: true })) {
|
||||
unshiftApp(newState, app);
|
||||
}
|
||||
});
|
||||
setRecentlyUsed(newState.slice(0, MAX_QUICK_ACCESS_ITEMS));
|
||||
}, [allApps, recentlyUsed, setRecentlyUsed]);
|
||||
const listener = useCallback(
|
||||
(location) => {
|
||||
const newState = [...recentlyUsed];
|
||||
apps.forEach((app) => {
|
||||
if (matchPath(location.pathname, { path: app.path, exact: true })) {
|
||||
unshiftApp(newState, app);
|
||||
}
|
||||
});
|
||||
setRecentlyUsed(newState.slice(0, MAX_QUICK_ACCESS_ITEMS));
|
||||
},
|
||||
[apps, recentlyUsed, setRecentlyUsed]
|
||||
);
|
||||
|
||||
history.listen(listener);
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { useMemo } from 'react';
|
||||
import { createMuiTheme } from '@material-ui/core';
|
||||
import { useSettings } from '../../../apps/settings/hooks/useSettings';
|
||||
import * as config from '../../../config/default.json';
|
||||
|
||||
export const usePhoneTheme = () => {
|
||||
const [settings] = useSettings();
|
||||
|
||||
return useMemo(() => createMuiTheme(config.themes[settings.theme]), [
|
||||
settings.theme,
|
||||
]);
|
||||
};
|
||||
Reference in new issue
Block a user