Add phone service, rename phone app to dialer, etc improvements

This commit is contained in:
J Francisco Rader committed 2020-08-25 21:13:01 -03:00
1 parent bf2e7fa295
commit b2e0cba844
24 files changed
+311 -255

No files matched your search

+62 -25
View File
@@ -8,7 +8,7 @@ import MessageIcon from "@material-ui/icons/Email";
import { HomeApp } from "./apps/home/components/Home";
import { ContactsApp } from "./apps/contacts/components/ContactsApp";
import { SettingsApp } from "./apps/settings/components/SettingsApp";
import { PhoneApp } from "./apps/phone/components/PhoneApp";
import { DialerApp } from "./apps/dialer/components/DialerApp";
import { BankApp } from "./apps/bank/components/BankApp";
import { ThemeProvider } from "@material-ui/core";
import { CalculatorApp } from "./apps/calculator/components/CalculatorApp";
@@ -18,8 +18,10 @@ import { NotificationBar } from "./os/notifications/components/NotificationBar";
import { Navigation } from "./os/navigation-bar/components/Navigation";
import { useNuiService } from "./os/nui-events/hooks/useNuiService";
import { useSimcardService } from "./os/simcard/hooks/useSimcardService";
import { usePhoneService } from "./os/phone/hooks/usePhoneService";
// @TODO: Remove this testing shit
// Used for testing NUI events while we work on clientside
setTimeout(() => {
window.dispatchEvent(
new MessageEvent("message", {
@@ -32,12 +34,49 @@ setTimeout(() => {
);
}, 3000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent("message", {
data: {
app: "PHONE",
method: "setPowerOff",
data: false,
},
})
);
}, 4000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent("message", {
data: {
app: "PHONE",
method: "setVisibility",
data: true,
},
})
);
}, 3000);
function Phone() {
useNuiService();
const { visibility, powerOff } = usePhoneService();
useSimcardService();
useInitKeyboard();
const { settings, currentTheme } = useSettings();
if (visibility === false) {
return null;
}
const screenStyle = powerOff
? {
backgroundColor: "black",
}
: {
backgroundImage: `url(${process.env.PUBLIC_URL}/media/backgrounds/${settings.wallpaper})`,
};
return (
<ThemeProvider theme={currentTheme()}>
<div className="PhoneWrapper">
@@ -49,30 +88,28 @@ function Phone() {
backgroundImage: `url(${process.env.PUBLIC_URL}/media/frames/${settings.frame})`,
}}
></div>
<div
id="phone"
className="PhoneScreen"
style={{
backgroundImage: `url(${process.env.PUBLIC_URL}/media/backgrounds/${settings.wallpaper})`,
}}
>
<NotificationBar
notifications={[
{
key: "newMessage",
icon: <NotificationIcon Icon={MessageIcon} />,
},
]}
/>
<div className="PhoneAppContainer">
<Route exact path="/" component={HomeApp} />
<Route exact path="/contacts" component={ContactsApp} />
<Route exact path="/settings" component={SettingsApp} />
<Route exact path="/phone" component={PhoneApp} />
<Route exact path="/bank" component={BankApp} />
<Route exact path="/calculator" component={CalculatorApp} />
</div>
<Navigation />
<div id="phone" className="PhoneScreen" style={screenStyle}>
{!powerOff && (
<>
<NotificationBar
notifications={[
{
key: "newMessage",
icon: <NotificationIcon Icon={MessageIcon} />,
},
]}
/>
<div className="PhoneAppContainer">
<Route exact path="/" component={HomeApp} />
<Route exact path="/contacts" component={ContactsApp} />
<Route exact path="/settings" component={SettingsApp} />
<Route exact path="/phone" component={DialerApp} />
<Route exact path="/bank" component={BankApp} />
<Route exact path="/calculator" component={CalculatorApp} />
</div>
<Navigation />
</>
)}
</div>
</div>
</div>
-73
View File
@@ -1,73 +0,0 @@
import React, { useEffect } from "react";
import { useConfig } from "../../../config/hooks/useConfig";
import { blue, grey, green, orange } from "@material-ui/core/colors";
import { useTranslation } from "react-i18next";
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 { useSettings } from "../../settings/hooks/useSettings";
import { CalculatorIcon } from "../../calculator/components/CalculatorIcon";
const appsState = atom({
key: "apps",
default: { preinstalled: [] },
});
export const useApps = () => {
const [apps, setApps] = useConfig(appsState);
const { currentTheme } = useSettings();
const { t } = useTranslation();
useEffect(() => {
setApps("preinstalled", [
{
id: "phone",
name: t("APPS_PHONE"),
icon: <PhoneIcon />,
backgroundColor: green[400],
color: green[50],
path: "/phone",
},
{
id: "contacts",
name: t("APPS_CONTACTS"),
icon: <ContactsIcon />,
backgroundColor: blue[500],
color: blue[50],
path: "/contacts",
},
{
id: "calculator",
name: t("APPS_CALCULATOR"),
icon: <CalculatorIcon />,
backgroundColor: currentTheme().palette.primary.light,
color: currentTheme().palette.primary.contrastText,
path: "/calculator",
},
{
id: "settings",
name: t("APPS_SETTINGS"),
icon: <SettingsIcon />,
backgroundColor: grey[700],
color: grey[50],
path: '/settings'
},
{
id: 'bank',
name: t('APPS_BANK'),
icon: <AccountBalanceIcon />,
backgroundColor: orange[600],
color: orange[50],
path: '/bank'
},
]);
// eslint-disable-next-line
}, []);
const allApps = [...apps.preinstalled];
const getApp = (id) => allApps.find((a) => a.id === id) || {};
return { apps, allApps, setApps, getApp };
};
+6 -8
View File
@@ -5,9 +5,10 @@ import { AppWrapper } from "../../../ui/components";
import { AppContent } from "../../../ui/components/AppContent";
import { useTranslation } from "react-i18next";
import { Button } from "@material-ui/core";
import { useBank } from '../hooks/useBank';
import { TransactionList } from './transactionList';
import { useBank } from "../hooks/useBank";
import { TransactionList } from "./TransactionList";
import "./BankApp.css";
import { useApp } from "../../../os/apps/hooks/useApps";
const useStyles = makeStyles((theme) => ({
root: {
@@ -33,11 +34,10 @@ export const BankApp = () => {
const { transactionList } = useBank();
const { t } = useTranslation();
const classes = useStyles();
const bank = useApp("BANK");
return (
<AppWrapper>
<AppTitle className={classes.root}>
<h1 className={classes.header}>WhoDis Banking</h1>
</AppTitle>
<AppTitle {...bank} className={classes.root} />
<AppContent>
<div className={classes.bankOptions}>
<Button className={classes.bankOptionsButton}>
@@ -50,9 +50,7 @@ export const BankApp = () => {
{t("APPS_BANK_TRANSFER")}
</Button>
</div>
<TransactionList
transactions={transactionList}
/>
<TransactionList transactions={transactionList} />
</AppContent>
</AppWrapper>
);
@@ -1,19 +1,19 @@
import React from 'react';
import { List } from '../../../ui/components/List';
import { ListItem } from '../../../ui/components/ListItem';
import React from "react";
import { List } from "../../../ui/components/List";
import { ListItem } from "../../../ui/components/ListItem";
import ListItemText from "@material-ui/core/ListItemText";
export const TransactionList = ({ transactions }) => {
return (
<List>
{transactions.map((transaction) => (
<ListItem key={transaction.id} divider>
<ListItemText
primary={transaction.amount}
secondary={transaction.type}
/>
</ListItem>
))}
</List>
)
}
return (
<List>
{transactions.map((transaction) => (
<ListItem key={transaction.id} divider>
<ListItemText
primary={transaction.amount}
secondary={transaction.type}
/>
</ListItem>
))}
</List>
);
};
@@ -2,18 +2,14 @@ import React from "react";
import { AppWrapper } from "../../../ui/components";
import { AppTitle } from "../../../ui/components/AppTitle";
import { AppContent } from "../../../ui/components/AppContent";
import { useTranslation } from "react-i18next";
import { useApps } from "../../appmarket/hooks/useApps";
import { Calculator } from "./Calculator";
import { useApp } from "../../../os/apps/hooks/useApps";
export const CalculatorApp = () => {
const { t } = useTranslation();
const { getApp } = useApps();
const calculator = useApp("CALCULATOR");
return (
<AppWrapper>
<AppTitle color={getApp("calculator").backgroundColor}>
{t("APPS_CALCULATOR")}
</AppTitle>
<AppTitle {...calculator} />
<AppContent>
<Calculator />
</AppContent>
@@ -2,24 +2,20 @@ import React from "react";
import { AppWrapper } from "../../../ui/components";
import { AppTitle } from "../../../ui/components/AppTitle";
import { AppContent } from "../../../ui/components/AppContent";
import { useTranslation } from "react-i18next";
import { useContacts } from "../hooks/useContacts";
import { ContactList } from "./ContactList";
import { useApps } from "../../appmarket/hooks/useApps";
import { useApp } from "../../../os/apps/hooks/useApps";
export const ContactsApp = () => {
const { contactList } = useContacts();
const { getApp } = useApps();
const { t } = useTranslation();
const contacts = useApp("CONTACTS");
return (
<AppWrapper>
<AppTitle color={getApp("contacts").backgroundColor}>
{t("APPS_CONTACTS")}
</AppTitle>
<AppTitle {...contacts} />
<AppContent>
<ContactList
contacts={contactList}
onCall={(contact => console.log(contact))}
onCall={(contact) => console.log(contact)}
onMessage={() => console.log("Opening messages")}
/>
</AppContent>
@@ -0,0 +1,20 @@
import React from "react";
import { AppWrapper } from "../../../ui/components";
import { AppTitle } from "../../../ui/components/AppTitle";
import { AppContent } from "../../../ui/components/AppContent";
import { DialerHistory } from "./DialerHistory";
import { useDialerHistory } from "../hooks/useDialerHistory";
import { useApp } from "../../../os/apps/hooks/useApps";
export const DialerApp = () => {
const { history } = useDialerHistory();
const dialer = useApp("DIALER");
return (
<AppWrapper>
<AppTitle {...dialer} />
<AppContent>
<DialerHistory calls={history} />
</AppContent>
</AppWrapper>
);
};
@@ -10,7 +10,7 @@ const CallTypeIcon = {
outgoing: <PhoneForwardedIcon />,
};
export const PhoneList = ({ calls }) => {
export const DialerHistory = ({ calls }) => {
return (
<List>
{calls.map((call) => (
@@ -0,0 +1,24 @@
import { useRecoilState, atom } from "recoil";
const dialerHistoryState = atom({
key: "dialerHistory",
default: [
{
id: 0,
caller: "Kidz",
phoneNumber: "000-1111",
type: "incoming",
},
{
id: 1,
caller: "ROCKY",
phoneNumber: "000-1112",
type: "outgoing",
},
],
});
export const useDialerHistory = () => {
const [history, setHistory] = useRecoilState(dialerHistoryState);
return { history, setHistory };
};
+4 -2
View File
@@ -1,14 +1,16 @@
import React from "react";
import { AppWrapper } from "../../../ui/components";
import { Box } from "@material-ui/core";
import { useApps } from "../../appmarket/hooks/useApps";
import { GridMenu } from "../../../ui/components/GridMenu";
import { useApps } from "../../../os/apps/hooks/useApps";
export const HomeApp = () => {
const { apps } = useApps();
return (
<AppWrapper>
<Box width="100%" mt={6} px={1}>{apps && <GridMenu items={apps.preinstalled} />}</Box>
<Box width="100%" mt={6} px={1}>
{apps && <GridMenu items={apps.preinstalled} />}
</Box>
</AppWrapper>
);
};
@@ -1,26 +0,0 @@
import React from 'react'
import { AppWrapper } from "../../../ui/components";
import { AppTitle } from "../../../ui/components/AppTitle";
import { AppContent } from "../../../ui/components/AppContent";
import { useTranslation } from "react-i18next";
import { useApps } from "../../appmarket/hooks/useApps";
import { PhoneList } from './PhoneList';
import { useCalls } from '../hooks/useCalls';
export const PhoneApp = () => {
const { callList } = useCalls();
const { getApp } = useApps();
const { t } = useTranslation();
return (
<AppWrapper>
<AppTitle color={getApp("phone").backgroundColor}>
{t("APPS_PHONE")}
</AppTitle>
<AppContent>
<PhoneList
calls={callList}
/>
</AppContent>
</AppWrapper>
)
}
-25
View File
@@ -1,25 +0,0 @@
import { useRecoilState, atom } from 'recoil';
const callListState = atom({
key: 'callList',
default: [
{
id: 0,
caller: 'Kidz',
phoneNumber: "000-1111",
type: 'incoming'
},
{
id: 1,
caller: 'ROCKY',
phoneNumber: '000-1112',
type: 'outgoing'
},
],
});
export const useCalls = () => {
const [callList, setCallList] = useRecoilState
(callListState);
return { callList, setCallList };
}
@@ -0,0 +1,13 @@
import React from "react";
import { ListItem, ListItemText, Divider } from "@material-ui/core";
export const SettingItem = ({ options, label, value, onClick }) => {
return (
<>
<ListItem onClick={() => onClick(options)} button>
<ListItemText primary={label} secondary={value} />
</ListItem>
<Divider />
</>
);
};
@@ -1,37 +1,23 @@
import React from "react";
import { AppWrapper } from "../../../ui/components";
import { ListItemText, Divider } from "@material-ui/core";
import { AppTitle } from "../../../ui/components/AppTitle";
import { AppContent } from "../../../ui/components/AppContent";
import { useTranslation } from "react-i18next";
import {
useContextMenu,
MapStringOptions,
} from "../../../ui/hooks/useContextMenu";
import { useConfig } from "../../../config/hooks/useConfig";
import { useSettings } from "../hooks/useSettings";
import { useApps } from "../../appmarket/hooks/useApps";
import { List } from "../../../ui/components/List";
import { ListItem } from "../../../ui/components/ListItem";
import { useSimcard } from "../../../os/simcard/hooks/useSimcard";
export const SettingItem = ({ options, label, value, onClick }) => {
return (
<>
<ListItem onClick={() => onClick(options)} button>
<ListItemText primary={label} secondary={value} />
</ListItem>
<Divider />
</>
);
};
import { useApp } from "../../../os/apps/hooks/useApps";
import { SettingItem } from "./SettingItem";
export const SettingsApp = () => {
const { t } = useTranslation();
const settingsApp = useApp("SETTINGS");
const [config] = useConfig();
const { getApp } = useApps();
const { setSettings, settings } = useSettings();
const simcard = useSimcard();
const simcard = useSimcard();
const wallpapers = config.wallpapers.map(
MapStringOptions(settings.wallpaper, (val) => setSettings("wallpaper", val))
@@ -46,9 +32,7 @@ export const SettingsApp = () => {
const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu();
return (
<AppWrapper>
<AppTitle color={getApp("settings").backgroundColor}>
{t("APPS_SETTINGS")}
</AppTitle>
<AppTitle {...settingsApp} />
<AppContent backdrop={isMenuOpen} onClickBackdrop={closeMenu}>
<List>
<SettingItem
@@ -69,10 +53,7 @@ export const SettingsApp = () => {
options={frames}
onClick={openMenu}
/>
<SettingItem
label="Phone Number"
value={simcard.number}
/>
<SettingItem label="Phone Number" value={simcard.number} />
</List>
</AppContent>
<ContextMenu />
+15 -15
View File
@@ -1,16 +1,16 @@
{
"translation": {
"COMING_SOON": "Coming soon...",
"APPS_PHONE": "Phone",
"APPS_CONTACTS": "Contacts",
"APPS_MESSAGES": "Messages",
"APPS_CALCULATOR": "Calculator",
"APPS_SETTINGS": "Settings",
"APPS_BANK": "WhoDis Banking",
"APPS_BANK_DEPOSIT": "Deposit",
"APPS_BANK_WITHDRAW": "Withdraw",
"APPS_BANK_TRANSFER": "Transfer",
"APPS_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper",
"APPS_SETTINGS_OPTIONS_FRAME": "Frame"
}
}
"translation": {
"COMING_SOON": "Coming soon...",
"APPS_DIALER": "Phone",
"APPS_CONTACTS": "Contacts",
"APPS_MESSAGES": "Messages",
"APPS_CALCULATOR": "Calculator",
"APPS_SETTINGS": "Settings",
"APPS_BANK": "WhoDis Banking",
"APPS_BANK_DEPOSIT": "Deposit",
"APPS_BANK_WITHDRAW": "Withdraw",
"APPS_BANK_TRANSFER": "Transfer",
"APPS_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper",
"APPS_SETTINGS_OPTIONS_FRAME": "Frame"
}
}
+71
View File
@@ -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);
};
+7 -7
View File
@@ -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,
+12
View File
@@ -0,0 +1,12 @@
import { atom } from "recoil";
export const phoneState = {
visibility: atom({
key: "phoneVisibility",
default: false,
}),
powerOff: atom({
key: "phonePowerOff",
default: true,
}),
};
+8
View File
@@ -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();
};
+21 -11
View File
@@ -1,22 +1,32 @@
import React from "react";
import { Typography, Box, makeStyles } from "@material-ui/core";
import { useTranslation } from "react-i18next";
const useStyle = makeStyles(theme => ({
root: ({ color }) => ({
width: '100%',
textAlign: 'center',
backgroundColor: color || theme.palette.background.default
const useStyle = makeStyles((theme) => ({
root: ({ backgroundColor }) => ({
width: "100%",
textAlign: "center",
backgroundColor: backgroundColor || theme.palette.background.default,
}),
text: ({ color }) => ({
color: color || theme.palette.text.primary,
}),
text: {
color: theme.palette.text.primary
}
}));
export const AppTitle = ({ children, color, ...props }) => {
const classes = useStyle({ color });
export const AppTitle = ({
backgroundColor,
color,
nameLocale,
variant = "h4",
...props
}) => {
const classes = useStyle({ color, backgroundColor });
const { t } = useTranslation();
return (
<Box px={2} pt={4} className={classes.root} {...props}>
<Typography className={classes.text} paragraph variant="h4">{children}</Typography>
<Typography className={classes.text} paragraph variant={variant}>
{t(nameLocale)}
</Typography>
</Box>
);
};
+1 -1
View File
@@ -32,9 +32,9 @@ export const GridMenu = ({ items, Component = AppIcon }) => {
items.length &&
items.map((item) => (
<Grid
key={item.id}
item
className={classes.item}
key={item.name}
tabIndex="-1"
component={Link}
to={item.path}