Improve hooks

This commit is contained in:
J Francisco Rader committed 2020-08-22 15:49:22 -03:00
1 parent d8f756b309
commit 34bfab2448
8 files changed
+50 -46

No files matched your search

+4 -3
View File
@@ -8,13 +8,12 @@ import { NotificationBar } from "./os/components/NotificationBar";
import { NotificationIcon } from "./os/components/NotificationIcon"; import { NotificationIcon } from "./os/components/NotificationIcon";
import { NavigationBar } from "./os/components/NavigationBar"; import { NavigationBar } from "./os/components/NavigationBar";
import { HomeApp } from "./apps/home/components/Home"; import { HomeApp } from "./apps/home/components/Home";
import { ContactsApp } from "./apps/contacts/components/Contacts"; import { ContactsApp } from "./apps/contacts/components/Contacts";
import { SettingsApp } from "./apps/settings/components/Settings"; import { SettingsApp } from "./apps/settings/components/Settings";
function Phone() { function Phone() {
const [settings] = useSettings(); const { settings } = useSettings();
return ( return (
<div className="PhoneWrapper"> <div className="PhoneWrapper">
<div style={{ zoom: "80%" }}> <div style={{ zoom: "80%" }}>
@@ -32,7 +31,9 @@ function Phone() {
backgroundImage: `${process.env.PUBLIC_URL}url(/media/backgrounds/${settings.wallpaper})`, backgroundImage: `${process.env.PUBLIC_URL}url(/media/backgrounds/${settings.wallpaper})`,
}} }}
> >
<NotificationBar notifications={[<NotificationIcon Icon={MessageIcon} />]} /> <NotificationBar
notifications={[<NotificationIcon Icon={MessageIcon} />]}
/>
<div className="PhoneAppContainer"> <div className="PhoneAppContainer">
<Route exact path="/" component={HomeApp} /> <Route exact path="/" component={HomeApp} />
<Route exact path="/contacts" component={ContactsApp} /> <Route exact path="/contacts" component={ContactsApp} />
+1 -1
View File
@@ -34,5 +34,5 @@ export const useApps = () => {
// eslint-disable-next-line // eslint-disable-next-line
}, []); }, []);
return [apps, setApps]; return { apps, setApps };
}; };
+27 -25
View File
@@ -1,40 +1,42 @@
import React from 'react' import React from "react";
import { makeStyles } from '@material-ui/core/styles'; import { makeStyles } from "@material-ui/core/styles";
import List from '@material-ui/core/List'; import List from "@material-ui/core/List";
import ListItem from '@material-ui/core/ListItem'; import ListItem from "@material-ui/core/ListItem";
import ListItemText from '@material-ui/core/ListItemText'; import ListItemText from "@material-ui/core/ListItemText";
import { useContacts } from "../hooks/useContacts"; import { Button } from "@material-ui/core";
import { Button } from '@material-ui/core';
import PhoneIcon from '@material-ui/icons/Phone';
import ChatIcon from '@material-ui/icons/Chat';
import PhoneIcon from "@material-ui/icons/Phone";
import ChatIcon from "@material-ui/icons/Chat";
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
root: { root: {
width: '100%', width: "100%",
maxWidth: 360, maxWidth: 360,
color: '#fff' color: "#fff",
}, },
listItem: { listItem: {
color: '#fff' color: "#fff",
} },
})); }));
export const ContactList = ({ children, onCall, onMessage }) => { export const ContactList = ({ contacts, onCall, onMessage }) => {
const classes = useStyles(); const classes = useStyles();
const [contacts] = useContacts();
return ( return (
<> <List component="nav" className={classes.root}>
<List component='nav' className={classes.root} >
{contacts.map((contact) => ( {contacts.map((contact) => (
<ListItem divider className={classes.listItem}> <ListItem divider className={classes.listItem}>
<ListItemText primary={contact.display} secondary={contact.phoneNumber}/> <ListItemText
<Button className={classes.listItem} onClick={onCall}><PhoneIcon/></Button> primary={contact.display}
<Button className={classes.listItem} onClick={onMessage}><ChatIcon/></Button> secondary={contact.phoneNumber}
/>
<Button className={classes.listItem} onClick={onCall}>
<PhoneIcon />
</Button>
<Button className={classes.listItem} onClick={onMessage}>
<ChatIcon />
</Button>
</ListItem> </ListItem>
))} ))}
</List> </List>
</> );
) };
}
+2 -2
View File
@@ -21,13 +21,13 @@ const useStyles = makeStyles(() => ({
export const ContactsApp = () => { export const ContactsApp = () => {
const classes = useStyles(); const classes = useStyles();
const [contacts] = useContacts(); const { contactList } = useContacts();
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
<AppWrapper className={classes.root}> <AppWrapper className={classes.root}>
<AppTitle className={classes.title}>{t("APPS_CONTACTS")}</AppTitle> <AppTitle className={classes.title}>{t("APPS_CONTACTS")}</AppTitle>
<AppContent> <AppContent>
<ContactList onCall={() => console.log("Calling")} onMessage={() => console.log("Opening messages")}/> <ContactList contacts={contactList} onCall={() => console.log("Calling")} onMessage={() => console.log("Opening messages")}/>
</AppContent> </AppContent>
</AppWrapper> </AppWrapper>
); );
+6 -6
View File
@@ -1,8 +1,8 @@
import { createContext } from "react"; import { useRecoilState, atom } from "recoil";
import { useConfig } from "../../../config/hooks/useConfig";
export const ContactsContext = createContext({ const contactListState = atom({
all: [ key: "contactList",
default: [
{ {
display: "Test Contact", display: "Test Contact",
phoneNumber: "000-1111", phoneNumber: "000-1111",
@@ -15,6 +15,6 @@ export const ContactsContext = createContext({
}); });
export const useContacts = () => { export const useContacts = () => {
const [contacts, setContacts] = useConfig(ContactsContext); const [contactList, setContactList] = useRecoilState(contactListState);
return [contacts.all, contacts => setContacts('all', contacts)] return { contactList, setContactList };
}; };
+1 -1
View File
@@ -5,7 +5,7 @@ import { Box } from "@material-ui/core";
import { useApps } from "../../appmarket/hooks/useApps"; import { useApps } from "../../appmarket/hooks/useApps";
export const HomeApp = () => { export const HomeApp = () => {
const [apps] = useApps(); const { apps } = useApps();
return ( return (
<AppWrapper> <AppWrapper>
<Box width="100%" mt={6} px={1}>{apps && <GridMenu apps={apps.preinstalled} />}</Box> <Box width="100%" mt={6} px={1}>{apps && <GridMenu apps={apps.preinstalled} />}</Box>
+1 -1
View File
@@ -22,7 +22,7 @@ export const SettingsApp = () => {
const classes = useStyles(); const classes = useStyles();
const { t } = useTranslation(); const { t } = useTranslation();
const [config] = useConfig(); const [config] = useConfig();
const [_settings, setSettings] = useSettings(); const { setSettings } = useSettings();
const wallpaperOptions = config.wallpapers.map((w) => ({ const wallpaperOptions = config.wallpapers.map((w) => ({
label: w, label: w,
+8 -7
View File
@@ -1,12 +1,13 @@
import Default from '../default.json'; import Default from "../default.json";
import { useConfig } from '../../../config/hooks/useConfig'; import { useConfig } from "../../../config/hooks/useConfig";
import { atom } from 'recoil'; import { atom } from "recoil";
const settingsState = atom({ const settingsState = atom({
key: 'settings', key: "settings",
default: Default default: Default,
}) });
export const useSettings = () => { export const useSettings = () => {
return useConfig(settingsState); const [settings, setSettings] = useConfig(settingsState);
return { settings, setSettings };
}; };