mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
feat(phone/useApps): startup event for apps | remove onClick
This commit is contained in:
1 parent
640643e086
commit
4e1d85b35f
2 files changed
+31
-17
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, {useEffect} from 'react';
|
||||||
import { useConfig } from '../../../config/hooks/useConfig';
|
import { useConfig } from '../../../config/hooks/useConfig';
|
||||||
import {
|
import {
|
||||||
blue,
|
blue,
|
||||||
@@ -38,6 +38,23 @@ import { ExampleApp } from '../../../apps/example/components/ExampleApp';
|
|||||||
import { SelloutApp } from '../../../apps/sellout/components/SelloutApp';
|
import { SelloutApp } from '../../../apps/sellout/components/SelloutApp';
|
||||||
import { NotesApp } from '../../../apps/notes/NotesApp';
|
import { NotesApp } from '../../../apps/notes/NotesApp';
|
||||||
import CameraApp from '../../../apps/camera/components/CameraApp';
|
import CameraApp from '../../../apps/camera/components/CameraApp';
|
||||||
|
import Nui from "../../nui-events/utils/Nui";
|
||||||
|
|
||||||
|
const AppWithStartup = ({ children, id }) => {
|
||||||
|
useEffect(() => {
|
||||||
|
Nui.send(`phone:app:${id}`);
|
||||||
|
}, []);
|
||||||
|
return children;
|
||||||
|
};
|
||||||
|
|
||||||
|
const AppRoute = ({ id, component: Component, ...rest }) => {
|
||||||
|
return (
|
||||||
|
<Route
|
||||||
|
{...rest}
|
||||||
|
render={() => <AppWithStartup id={id}><Component /></AppWithStartup>}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const appsState = atom({
|
const appsState = atom({
|
||||||
key: 'apps',
|
key: 'apps',
|
||||||
@@ -50,7 +67,7 @@ const appsState = atom({
|
|||||||
backgroundColor: green[600],
|
backgroundColor: green[600],
|
||||||
color: common.white,
|
color: common.white,
|
||||||
path: '/phone',
|
path: '/phone',
|
||||||
Route: () => <Route path='/phone' component={DialerApp} />,
|
Route: () => <AppRoute id="DIALER" path='/phone' component={DialerApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'MESSAGES',
|
id: 'MESSAGES',
|
||||||
@@ -60,7 +77,7 @@ const appsState = atom({
|
|||||||
color: common.white,
|
color: common.white,
|
||||||
path: '/messages',
|
path: '/messages',
|
||||||
sharePath: '/messages/new',
|
sharePath: '/messages/new',
|
||||||
Route: () => <Route path='/messages' component={MessagesApp} />,
|
Route: () => <AppRoute id="MESSAGE" path='/messages' component={MessagesApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'CONTACTS',
|
id: 'CONTACTS',
|
||||||
@@ -69,7 +86,7 @@ const appsState = atom({
|
|||||||
backgroundColor: blue[500],
|
backgroundColor: blue[500],
|
||||||
color: common.white,
|
color: common.white,
|
||||||
path: '/contacts',
|
path: '/contacts',
|
||||||
Route: () => <Route path='/contacts' component={ContactsApp} />,
|
Route: () => <AppRoute id="CONTACTS" path='/contacts' component={ContactsApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'CALCULATOR',
|
id: 'CALCULATOR',
|
||||||
@@ -78,7 +95,7 @@ const appsState = atom({
|
|||||||
backgroundColor: purple[500],
|
backgroundColor: purple[500],
|
||||||
color: grey[50],
|
color: grey[50],
|
||||||
path: '/calculator',
|
path: '/calculator',
|
||||||
Route: () => <Route path='/calculator' component={CalculatorApp} />,
|
Route: () => <AppRoute id="CALCULATOR" path='/calculator' component={CalculatorApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'SETTINGS',
|
id: 'SETTINGS',
|
||||||
@@ -87,7 +104,7 @@ const appsState = atom({
|
|||||||
backgroundColor: '#383838',
|
backgroundColor: '#383838',
|
||||||
color: grey[50],
|
color: grey[50],
|
||||||
path: '/settings',
|
path: '/settings',
|
||||||
Route: () => <Route path='/settings' component={SettingsApp} />,
|
Route: () => <AppRoute id="SETTINGS" path='/settings' component={SettingsApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'BANK',
|
id: 'BANK',
|
||||||
@@ -96,7 +113,7 @@ const appsState = atom({
|
|||||||
backgroundColor: blue[900],
|
backgroundColor: blue[900],
|
||||||
color: common.white,
|
color: common.white,
|
||||||
path: '/bank',
|
path: '/bank',
|
||||||
Route: () => <Route path='/bank' component={BankApp} />,
|
Route: () => <AppRoute id="BANK" path='/bank' component={BankApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'TWITTER',
|
id: 'TWITTER',
|
||||||
@@ -105,7 +122,7 @@ const appsState = atom({
|
|||||||
backgroundColor: blue[600],
|
backgroundColor: blue[600],
|
||||||
color: common.white,
|
color: common.white,
|
||||||
path: '/twitter',
|
path: '/twitter',
|
||||||
Route: () => <Route path='/twitter' component={TwitterApp} />,
|
Route: () => <AppRoute id="TWITTER" path='/twitter' component={TwitterApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'SELLOUT',
|
id: 'SELLOUT',
|
||||||
@@ -114,7 +131,7 @@ const appsState = atom({
|
|||||||
backgroundColor: red[500],
|
backgroundColor: red[500],
|
||||||
color: common.white,
|
color: common.white,
|
||||||
path: '/sellout',
|
path: '/sellout',
|
||||||
Route: () => <Route path='/sellout' component={SelloutApp} />,
|
Route: () => <AppRoute id="SELLOUT" path='/sellout' component={SelloutApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'NOTES',
|
id: 'NOTES',
|
||||||
@@ -123,7 +140,7 @@ const appsState = atom({
|
|||||||
backgroundColor: yellow[800],
|
backgroundColor: yellow[800],
|
||||||
color: common.white,
|
color: common.white,
|
||||||
path: '/notes',
|
path: '/notes',
|
||||||
Route: () => <Route path='/notes' component={NotesApp} />,
|
Route: () => <AppRoute id="NOTES" path='/notes' component={NotesApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'CAMERA',
|
id: 'CAMERA',
|
||||||
@@ -132,7 +149,7 @@ const appsState = atom({
|
|||||||
backgroundColor: grey['A400'],
|
backgroundColor: grey['A400'],
|
||||||
color: common.white,
|
color: common.white,
|
||||||
path: '/camera',
|
path: '/camera',
|
||||||
Route: () => <Route path='/camera' component={CameraApp} />,
|
Route: () => <AppRoute id="CAMERA" path='/camera' component={CameraApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'EXAMPLE',
|
id: 'EXAMPLE',
|
||||||
@@ -141,7 +158,7 @@ const appsState = atom({
|
|||||||
backgroundColor: blue[500],
|
backgroundColor: blue[500],
|
||||||
color: blue[50],
|
color: blue[50],
|
||||||
path: '/example',
|
path: '/example',
|
||||||
Route: () => <Route path='/example' component={ExampleApp} />,
|
Route: () => <AppRoute id="EXAMPLE" path='/example' component={ExampleApp}/>,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -158,5 +175,6 @@ export const useApps = () => {
|
|||||||
|
|
||||||
export const useApp = (id) => {
|
export const useApp = (id) => {
|
||||||
const { getApp } = useApps();
|
const { getApp } = useApps();
|
||||||
|
|
||||||
return getApp(id);
|
return getApp(id);
|
||||||
};
|
};
|
||||||
@@ -35,12 +35,8 @@ export const AppIcon = ({ id, name, icon, backgroundColor, color }) => {
|
|||||||
color: color || green[400],
|
color: color || green[400],
|
||||||
});
|
});
|
||||||
|
|
||||||
const openAppCallback = () => {
|
|
||||||
Nui.send(`phone:app:${id}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button onClick={openAppCallback} className={classes.root}>
|
<Button className={classes.root}>
|
||||||
<Avatar className={classes.avatar}>
|
<Avatar className={classes.avatar}>
|
||||||
{icon || name[0].toUpperCase()}
|
{icon || name[0].toUpperCase()}
|
||||||
</Avatar>
|
</Avatar>
|
||||||
|
|||||||
Reference in new issue
Block a user