I really hope I didnt fuck anything up now

This commit is contained in:
chip committed 2020-08-23 20:08:08 +02:00
1 parent ad20755608
commit ec37fcde46
67 files changed

No files matched your search

+73
View File
@@ -0,0 +1,73 @@
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 };
};
@@ -0,0 +1 @@
@import url("https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap");
+59
View File
@@ -0,0 +1,59 @@
import React from "react";
import { makeStyles } from "@material-ui/core";
import { AppTitle } from "../../../ui/components/AppTitle";
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 "./BankApp.css";
const useStyles = makeStyles((theme) => ({
root: {
height: "90px",
display: "flex",
justifyContent: "center",
backgroundColor: "#fb8c00",
alignItems: "center",
},
header: {
fontFamily: "'Bebas Neue', cursive",
textAlign: "center",
fontSize: 50,
},
bankOptions: {},
bankOptionsButton: {
display: "block",
textAlign: "center",
},
}));
export const BankApp = () => {
const { transactionList } = useBank();
const { t } = useTranslation();
const classes = useStyles();
return (
<AppWrapper>
<AppTitle className={classes.root}>
<h1 className={classes.header}>WhoDis Banking</h1>
</AppTitle>
<AppContent>
<div className={classes.bankOptions}>
<Button className={classes.bankOptionsButton}>
{t("APPS_BANK_DEPOSIT")}
</Button>
<Button className={classes.bankOptionsButton}>
{t("APPS_BANK_WITHDRAW")}
</Button>
<Button className={classes.bankOptionsButton}>
{t("APPS_BANK_TRANSFER")}
</Button>
</div>
<TransactionList
transactions={transactionList}
/>
</AppContent>
</AppWrapper>
);
};
@@ -0,0 +1,19 @@
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>
)
}
+31
View File
@@ -0,0 +1,31 @@
import { useRecoilState, atom } from 'recoil';
const transactionListState = atom({
key: 'transactionList',
default: [
{
id: 0,
amount: 300,
type: 'withdraw',
date: '3'
},
{
id: 1,
amount: 1000,
type: 'withdraw',
date: '3'
},
{
id: 2,
amount: 50,
type: 'transfer',
date: '2'
},
],
});
export const useBank = () => {
const [transactionList, setTransactionList] = useRecoilState
(transactionListState);
return { transactionList, setTransactionList };
}
@@ -0,0 +1,68 @@
import React from "react";
import { useCalculator, CalcButton } from "../hooks/useCalculator";
import { Grid, makeStyles, Box, Paper } from "@material-ui/core";
const useStyles = makeStyles((theme) => ({
button: {
fontSize: theme.typography.h5.fontSize,
padding: theme.spacing(2),
},
result: {
fontSize: theme.typography.h2.fontSize,
textAlign: "right",
},
}));
export const Calculator = ({ ...props }) => {
const {
result,
equals,
clear,
clearAll,
divider,
multiplier,
substractor,
adder,
dot,
zero,
one,
two,
three,
four,
five,
six,
seven,
eight,
nine,
} = useCalculator();
const classes = useStyles();
return (
<Box display="flex" flexDirection="column">
<Box flexGrow={1} component={Paper} p={4} className={classes.result}>
{result()}
</Box>
<Box>
<Grid container justify="space-around">
<CalcButton button={clear} className={classes.button} />
<CalcButton button={clearAll} className={classes.button} />
<CalcButton button={divider} className={classes.button} />
<CalcButton button={multiplier} className={classes.button} />
<CalcButton button={seven} className={classes.button} />
<CalcButton button={eight} className={classes.button} />
<CalcButton button={nine} className={classes.button} />
<CalcButton button={substractor} className={classes.button} />
<CalcButton button={four} className={classes.button} />
<CalcButton button={five} className={classes.button} />
<CalcButton button={six} className={classes.button} />
<CalcButton button={adder} className={classes.button} />
<CalcButton button={one} className={classes.button} />
<CalcButton button={two} className={classes.button} />
<CalcButton button={three} className={classes.button} />
<CalcButton button={equals} className={classes.button} />
<CalcButton button={dot} className={classes.button} />
<CalcButton button={zero} className={classes.button} xs={9} />
</Grid>
</Box>
</Box>
);
};
@@ -0,0 +1,22 @@
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";
export const CalculatorApp = () => {
const { t } = useTranslation();
const { getApp } = useApps();
return (
<AppWrapper>
<AppTitle color={getApp("calculator").backgroundColor}>
{t("APPS_CALCULATOR")}
</AppTitle>
<AppContent>
<Calculator />
</AppContent>
</AppWrapper>
);
};
@@ -0,0 +1,43 @@
import React from "react";
import { SvgIcon } from "@material-ui/core";
export const CalculatorIcon = ({ ...props }) => {
return (
<SvgIcon {...props}>
<svg
xmlns="http://www.w3.org/2000/svg"
x="0"
y="0"
enableBackground="new 0 0 56 56"
version="1.1"
viewBox="0 0 56 56"
xmlSpace="preserve"
>
<path fill="#EBBA16" d="M0 0H28V28H0z"></path>
<path fill="#ED8A19" d="M28 0H56V28H28z"></path>
<path fill="#ED8A19" d="M0 28H28V56H0z"></path>
<path fill="#556080" d="M28 28H56V56H28z"></path>
<path
fill="#FFF"
d="M48 46H36a1 1 0 110-2h12a1 1 0 110 2zM48 40H36a1 1 0 110-2h12a1 1 0 110 2zM14 43a.999.999 0 01-.707-1.707l5-5a.999.999 0 111.414 1.414l-5 5A.997.997 0 0114 43z"
></path>
<path
fill="#FFF"
d="M9 48a.999.999 0 01-.707-1.707l5-5a.999.999 0 111.414 1.414l-5 5A.997.997 0 019 48z"
></path>
<path
fill="#FFF"
d="M19 48a.997.997 0 01-.707-.293l-5-5a.999.999 0 111.414-1.414l5 5A.999.999 0 0119 48z"
></path>
<path
fill="#FFF"
d="M14 43a.997.997 0 01-.707-.293l-5-5a.999.999 0 111.414-1.414l5 5A.999.999 0 0114 43zM20 15H8a1 1 0 110-2h12a1 1 0 110 2z"
></path>
<path
fill="#FFF"
d="M14 21a1 1 0 01-1-1V8a1 1 0 112 0v12a1 1 0 01-1 1zM48 15H36a1 1 0 110-2h12a1 1 0 110 2z"
></path>
</svg>
</SvgIcon>
);
};
@@ -0,0 +1,168 @@
import React, { useReducer } from "react";
import { Grid, Button } from "@material-ui/core";
const initialState = {
value: 0,
op: "",
num1: 0,
num2: "",
num3: "",
};
const Reducer = (state, action) => {
switch (action.type) {
case "2":
if (!state.num1) {
return { ...state, num1: state.num2, op: action.payload, num2: "" };
}
if (!state.num2) {
return { ...state, op: action.payload };
}
if (state.num1 && state.op) {
return {
...state,
value: state.op(state.value, state.num2),
op: action.payload,
};
}
return {
...state,
value: state.op(state.num1, state.num2),
num2: "",
op: action.payload,
num1: state.op(state.num1, state.num2),
};
case "1":
if (state.num2 === "" && action.payload === ".") {
return { ...state, num2: "0" + action.payload };
}
if (state.num2 === "") {
return { ...state, num2: action.payload };
}
if (action.payload === "." && state.num2.includes(".")) {
return state;
} else {
return { ...state, num2: state.num2 + action.payload };
}
case "3":
if (state.op && state.num2) {
return {
...state,
value: state.op(state.num1, state.num2),
num2: "",
num1: state.op(state.num1, state.num2),
num3: state.num2,
};
}
if (state.op && state.value) {
return { ...state, value: state.op(state.value, state.num3) };
}
return state;
case "c":
if (state.num2.length === 2 && state.num2.includes("0.")) {
return { ...state, num2: "" };
}
if (state.num2.length > 1) {
return { ...state, num2: state.num2.slice(0, -1) };
}
return { ...state, num2: "" };
case "ac":
return {
value: 0,
op: "",
num1: 0,
num2: "",
num3: "",
};
default:
return state;
}
};
export const CalcButton = ({ button, className, ...props }) => (
<Grid key={button.label} item xs={3} {...props}>
<Button fullWidth className={className} onClick={button.onClick}>
{button.label}
</Button>
</Grid>
);
export const useCalculator = () => {
const [state, dispatch] = useReducer(Reducer, initialState);
const getPayload = (label, type) => {
if (type !== "2") {
return `${label}`;
}
switch (label) {
case "/":
return (a, b) => Number(a) / Number(b);
case "*":
return (a, b) => Number(a) * Number(b);
case "+":
return (a, b) => Number(a) + Number(b);
case "-":
return (a, b) => Number(a) - Number(b);
default:
break;
}
};
const buttonProps = (label, type) => ({
label,
onClick: () =>
dispatch({
type,
payload: getPayload(label, type),
}),
});
const number = (n) => buttonProps(n, "1");
const operator = (sym) => buttonProps(sym, "2");
const clear = buttonProps("C", "c");
const clearAll = buttonProps("AC", "ac");
const equals = buttonProps("=", "3");
const zero = number(0);
const dot = number(".");
const divider = operator("/");
const multiplier = operator("*");
const adder = operator("+");
const substractor = operator("-");
const one = number(1);
const two = number(2);
const three = number(3);
const four = number(4);
const five = number(5);
const six = number(6);
const seven = number(7);
const eight = number(8);
const nine = number(9);
const result = () => (!state.num2 ? state.value : state.num2);
return {
result,
equals,
clear,
clearAll,
divider,
multiplier,
substractor,
adder,
dot,
zero,
one,
two,
three,
four,
five,
six,
seven,
eight,
nine,
};
};
@@ -0,0 +1,29 @@
import React from "react";
import ListItemText from "@material-ui/core/ListItemText";
import { Button } from "@material-ui/core";
import PhoneIcon from "@material-ui/icons/Phone";
import ChatIcon from "@material-ui/icons/Chat";
import { List } from "../../../ui/components/List";
import { ListItem } from "../../../ui/components/ListItem";
export const ContactList = ({ contacts, onCall, onMessage }) => {
return (
<List>
{contacts.map((contact) => (
<ListItem key={contact.id} divider>
<ListItemText
primary={contact.display}
secondary={contact.phoneNumber}
/>
<Button onClick={() => onCall(contact.display)}>
<PhoneIcon />
</Button>
<Button onClick={onMessage}>
<ChatIcon />
</Button>
</ListItem>
))}
</List>
);
};
@@ -0,0 +1,28 @@
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";
export const ContactsApp = () => {
const { contactList } = useContacts();
const { getApp } = useApps();
const { t } = useTranslation();
return (
<AppWrapper>
<AppTitle color={getApp("contacts").backgroundColor}>
{t("APPS_CONTACTS")}
</AppTitle>
<AppContent>
<ContactList
contacts={contactList}
onCall={(contact => console.log(contact))}
onMessage={() => console.log("Opening messages")}
/>
</AppContent>
</AppWrapper>
);
};
@@ -0,0 +1,22 @@
import { useRecoilState, atom } from "recoil";
const contactListState = atom({
key: "contactList",
default: [
{
id: 0,
display: "Test Contact",
phoneNumber: "000-1111",
},
{
id: 1,
display: "Test Contact 2",
phoneNumber: "000-1112",
},
],
});
export const useContacts = () => {
const [contactList, setContactList] = useRecoilState(contactListState);
return { contactList, setContactList };
};
+14
View File
@@ -0,0 +1,14 @@
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";
export const HomeApp = () => {
const { apps } = useApps();
return (
<AppWrapper>
<Box width="100%" mt={6} px={1}>{apps && <GridMenu items={apps.preinstalled} />}</Box>
</AppWrapper>
);
};
Whitespace-only changes.
Whitespace-only changes.
View File
Whitespace-only changes.
@@ -0,0 +1,26 @@
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>
)
}
@@ -0,0 +1,24 @@
import React from "react";
import ListItemText from "@material-ui/core/ListItemText";
import PhoneCallbackIcon from "@material-ui/icons/PhoneCallback";
import PhoneForwardedIcon from "@material-ui/icons/PhoneForwarded";
import { List } from "../../../ui/components/List";
import { ListItem } from "../../../ui/components/ListItem";
const CallTypeIcon = {
incoming: <PhoneCallbackIcon />,
outgoing: <PhoneForwardedIcon />,
};
export const PhoneList = ({ calls }) => {
return (
<List>
{calls.map((call) => (
<ListItem key={call.id} divider>
<ListItemText primary={call.caller} secondary={call.phoneNumber} />
{CallTypeIcon[call.type]}
</ListItem>
))}
</List>
);
};
+25
View File
@@ -0,0 +1,25 @@
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,75 @@
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";
export const SettingItem = ({ options, label, value, onClick }) => {
return (
<>
<ListItem onClick={() => onClick(options)} button>
<ListItemText primary={label} secondary={value} />
</ListItem>
<Divider />
</>
);
};
export const SettingsApp = () => {
const { t } = useTranslation();
const [config] = useConfig();
const { getApp } = useApps();
const { setSettings, settings } = useSettings();
const wallpapers = config.wallpapers.map(
MapStringOptions(settings.wallpaper, (val) => setSettings("wallpaper", val))
);
const frames = config.frames.map(
MapStringOptions(settings.frame, (val) => setSettings("frame", val))
);
const themes = Object.keys(config.themes).map(
MapStringOptions(settings.theme, (val) => setSettings("theme", val))
);
const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu();
return (
<AppWrapper>
<AppTitle color={getApp("settings").backgroundColor}>
{t("APPS_SETTINGS")}
</AppTitle>
<AppContent backdrop={isMenuOpen} onClickBackdrop={closeMenu}>
<List>
<SettingItem
label="Theme"
value={settings.theme}
options={themes}
onClick={openMenu}
/>
<SettingItem
label="Wallpaper"
value={settings.wallpaper}
options={wallpapers}
onClick={openMenu}
/>
<SettingItem
label="Frame"
value={settings.frame}
options={frames}
onClick={openMenu}
/>
</List>
</AppContent>
<ContextMenu />
</AppWrapper>
);
};
+5
View File
@@ -0,0 +1,5 @@
{
"wallpaper": "default.png",
"frame": "default.png",
"theme": "default-dark"
}
@@ -0,0 +1,16 @@
import Default from "../default.json";
import { useConfig } from "../../../config/hooks/useConfig";
import { atom } from "recoil";
import { createMuiTheme } from "@material-ui/core";
const settingsState = atom({
key: "settings",
default: Default,
});
export const useSettings = () => {
const [settings, setSettings] = useConfig(settingsState);
const [config] = useConfig();
const currentTheme = () => createMuiTheme(config.themes[settings.theme]);
return { settings, setSettings, currentTheme };
};