mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Add phone service, rename phone app to dialer, etc improvements
This commit is contained in:
1 parent
bf2e7fa295
commit
b2e0cba844
24 files changed
+311
-255
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import React from "react";
|
||||
import { useConfig } from "../../../config/hooks/useConfig";
|
||||
import { blue, grey, green, orange, purple } from "@material-ui/core/colors";
|
||||
import ContactsIcon from "@material-ui/icons/Contacts";
|
||||
import SettingsIcon from "@material-ui/icons/Settings";
|
||||
import PhoneIcon from "@material-ui/icons/Phone";
|
||||
import AccountBalanceIcon from "@material-ui/icons/AccountBalance";
|
||||
import { atom } from "recoil";
|
||||
import { CalculatorIcon } from "../../../apps/calculator/components/CalculatorIcon";
|
||||
|
||||
const appsState = atom({
|
||||
key: "apps",
|
||||
default: {
|
||||
preinstalled: [
|
||||
{
|
||||
id: "DIALER",
|
||||
nameLocale: "APPS_DIALER",
|
||||
icon: <PhoneIcon />,
|
||||
backgroundColor: green[400],
|
||||
color: green[50],
|
||||
path: "/phone",
|
||||
},
|
||||
{
|
||||
id: "CONTACTS",
|
||||
nameLocale: "APPS_CONTACTS",
|
||||
icon: <ContactsIcon />,
|
||||
backgroundColor: blue[500],
|
||||
color: blue[50],
|
||||
path: "/contacts",
|
||||
},
|
||||
{
|
||||
id: "CALCULATOR",
|
||||
nameLocale: "APPS_CALCULATOR",
|
||||
icon: <CalculatorIcon />,
|
||||
backgroundColor: purple[500],
|
||||
color: grey[50],
|
||||
path: "/calculator",
|
||||
},
|
||||
{
|
||||
id: "SETTINGS",
|
||||
nameLocale: "APPS_SETTINGS",
|
||||
icon: <SettingsIcon />,
|
||||
backgroundColor: grey[700],
|
||||
color: grey[50],
|
||||
path: "/settings",
|
||||
},
|
||||
{
|
||||
id: "BANK",
|
||||
nameLocale: "APPS_BANK",
|
||||
icon: <AccountBalanceIcon />,
|
||||
backgroundColor: orange[600],
|
||||
color: orange[50],
|
||||
path: "/bank",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
export const useApps = () => {
|
||||
const [apps, setApps] = useConfig(appsState);
|
||||
const allApps = [...apps.preinstalled];
|
||||
|
||||
const getApp = (id) => allApps.find((a) => a.id === id) || null;
|
||||
|
||||
return { apps, allApps, setApps, getApp };
|
||||
};
|
||||
|
||||
export const useApp = (id) => {
|
||||
const { getApp } = useApps();
|
||||
return getApp(id);
|
||||
};
|
||||
@@ -6,16 +6,16 @@ export const useNuiEvent = (app, method, handler, options = {}) => {
|
||||
const { capture, passive, once } = options;
|
||||
|
||||
useEffect(() => {
|
||||
savedHandler.current = event => {
|
||||
const { data } = event;
|
||||
if (handler && handler.call) {
|
||||
handler(data);
|
||||
}
|
||||
};
|
||||
savedHandler.current = handler;
|
||||
}, [handler]);
|
||||
|
||||
useEffect(() => {
|
||||
const eventListener = (event) => savedHandler.current(event);
|
||||
const eventListener = (event) => {
|
||||
const { data } = event;
|
||||
if (savedHandler.current && savedHandler.current.call) {
|
||||
savedHandler.current(data);
|
||||
}
|
||||
};
|
||||
const opts = { capture, passive, once };
|
||||
const eventName = eventNameFactory(app, method);
|
||||
window.addEventListener(eventName, eventListener, opts);
|
||||
|
||||
@@ -4,9 +4,8 @@ import { eventNameFactory } from "../utils/nuiUtils";
|
||||
export const useNuiService = (options = {}) => {
|
||||
const { capture, passive, once } = options;
|
||||
const eventListener = (event) => {
|
||||
console.log(event);
|
||||
const { app, method, data } = event.data;
|
||||
if (app && method && data) {
|
||||
if (app && method && data !== undefined) {
|
||||
window.dispatchEvent(
|
||||
new MessageEvent(eventNameFactory(app, method), {
|
||||
data,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { atom } from "recoil";
|
||||
|
||||
export const phoneState = {
|
||||
visibility: atom({
|
||||
key: "phoneVisibility",
|
||||
default: false,
|
||||
}),
|
||||
powerOff: atom({
|
||||
key: "phonePowerOff",
|
||||
default: true,
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
import { useRecoilValue } from "recoil";
|
||||
import { phoneState } from "./state";
|
||||
|
||||
export const usePhone = () => {
|
||||
const visibility = useRecoilValue(phoneState.visibility);
|
||||
const powerOff = useRecoilValue(phoneState.powerOff);
|
||||
return { visibility, powerOff };
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useSetRecoilState } from "recoil";
|
||||
import { phoneState } from "./state";
|
||||
import { useNuiEvent } from "../../nui-events/hooks/useNuiEvent";
|
||||
import { usePhone } from "./usePhone";
|
||||
|
||||
export const usePhoneService = () => {
|
||||
const setVisibility = useSetRecoilState(phoneState.visibility);
|
||||
const setPowerOff = useSetRecoilState(phoneState.powerOff);
|
||||
useNuiEvent("PHONE", "setPowerOff", setPowerOff);
|
||||
useNuiEvent("PHONE", "setVisibility", setVisibility);
|
||||
const { visibility, powerOff } = usePhone();
|
||||
return { visibility, powerOff };
|
||||
};
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useNuiEvent } from "../../nui-events/hooks/useNuiEvent";
|
||||
import { useSetRecoilState } from "recoil";
|
||||
import { simcardState } from "./state";
|
||||
import { useSimcard } from "./useSimcard";
|
||||
|
||||
export const useSimcardService = () => {
|
||||
const setNumber = useSetRecoilState(simcardState.number);
|
||||
useNuiEvent("SIMCARD", "setNumber", (data) => {
|
||||
setNumber(data);
|
||||
});
|
||||
useNuiEvent("SIMCARD", "setNumber", setNumber);
|
||||
return useSimcard();
|
||||
};
|
||||
Reference in new issue
Block a user