mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
Improve hooks
This commit is contained in:
1 parent
d8f756b309
commit
34bfab2448
8 files changed
+61
-57
No files matched your search
+4
-3
@@ -8,13 +8,12 @@ import { NotificationBar } from "./os/components/NotificationBar";
|
||||
import { NotificationIcon } from "./os/components/NotificationIcon";
|
||||
import { NavigationBar } from "./os/components/NavigationBar";
|
||||
|
||||
|
||||
import { HomeApp } from "./apps/home/components/Home";
|
||||
import { ContactsApp } from "./apps/contacts/components/Contacts";
|
||||
import { SettingsApp } from "./apps/settings/components/Settings";
|
||||
|
||||
function Phone() {
|
||||
const [settings] = useSettings();
|
||||
const { settings } = useSettings();
|
||||
return (
|
||||
<div className="PhoneWrapper">
|
||||
<div style={{ zoom: "80%" }}>
|
||||
@@ -32,7 +31,9 @@ function Phone() {
|
||||
backgroundImage: `${process.env.PUBLIC_URL}url(/media/backgrounds/${settings.wallpaper})`,
|
||||
}}
|
||||
>
|
||||
<NotificationBar notifications={[<NotificationIcon Icon={MessageIcon} />]} />
|
||||
<NotificationBar
|
||||
notifications={[<NotificationIcon Icon={MessageIcon} />]}
|
||||
/>
|
||||
<div className="PhoneAppContainer">
|
||||
<Route exact path="/" component={HomeApp} />
|
||||
<Route exact path="/contacts" component={ContactsApp} />
|
||||
|
||||
@@ -34,5 +34,5 @@ export const useApps = () => {
|
||||
// eslint-disable-next-line
|
||||
}, []);
|
||||
|
||||
return [apps, setApps];
|
||||
return { apps, setApps };
|
||||
};
|
||||
@@ -1,40 +1,42 @@
|
||||
import React from 'react'
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import List from '@material-ui/core/List';
|
||||
import ListItem from '@material-ui/core/ListItem';
|
||||
import ListItemText from '@material-ui/core/ListItemText';
|
||||
import { useContacts } from "../hooks/useContacts";
|
||||
import { Button } from '@material-ui/core';
|
||||
|
||||
import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import ChatIcon from '@material-ui/icons/Chat';
|
||||
import React from "react";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import List from "@material-ui/core/List";
|
||||
import ListItem from "@material-ui/core/ListItem";
|
||||
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";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
width: '100%',
|
||||
maxWidth: 360,
|
||||
color: '#fff'
|
||||
},
|
||||
listItem: {
|
||||
color: '#fff'
|
||||
}
|
||||
}));
|
||||
root: {
|
||||
width: "100%",
|
||||
maxWidth: 360,
|
||||
color: "#fff",
|
||||
},
|
||||
listItem: {
|
||||
color: "#fff",
|
||||
},
|
||||
}));
|
||||
|
||||
export const ContactList = ({ children, onCall, onMessage }) => {
|
||||
const classes = useStyles();
|
||||
const [contacts] = useContacts();
|
||||
return (
|
||||
<>
|
||||
<List component='nav' className={classes.root} >
|
||||
{contacts.map((contact) => (
|
||||
<ListItem divider className={classes.listItem}>
|
||||
<ListItemText primary={contact.display} secondary={contact.phoneNumber}/>
|
||||
<Button className={classes.listItem} onClick={onCall}><PhoneIcon/></Button>
|
||||
<Button className={classes.listItem} onClick={onMessage}><ChatIcon/></Button>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
</>
|
||||
)
|
||||
}
|
||||
export const ContactList = ({ contacts, onCall, onMessage }) => {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<List component="nav" className={classes.root}>
|
||||
{contacts.map((contact) => (
|
||||
<ListItem divider className={classes.listItem}>
|
||||
<ListItemText
|
||||
primary={contact.display}
|
||||
secondary={contact.phoneNumber}
|
||||
/>
|
||||
<Button className={classes.listItem} onClick={onCall}>
|
||||
<PhoneIcon />
|
||||
</Button>
|
||||
<Button className={classes.listItem} onClick={onMessage}>
|
||||
<ChatIcon />
|
||||
</Button>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
);
|
||||
};
|
||||
@@ -21,13 +21,13 @@ const useStyles = makeStyles(() => ({
|
||||
|
||||
export const ContactsApp = () => {
|
||||
const classes = useStyles();
|
||||
const [contacts] = useContacts();
|
||||
const { contactList } = useContacts();
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<AppWrapper className={classes.root}>
|
||||
<AppTitle className={classes.title}>{t("APPS_CONTACTS")}</AppTitle>
|
||||
<AppContent>
|
||||
<ContactList onCall={() => console.log("Calling")} onMessage={() => console.log("Opening messages")}/>
|
||||
<ContactList contacts={contactList} onCall={() => console.log("Calling")} onMessage={() => console.log("Opening messages")}/>
|
||||
</AppContent>
|
||||
</AppWrapper>
|
||||
);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { createContext } from "react";
|
||||
import { useConfig } from "../../../config/hooks/useConfig";
|
||||
import { useRecoilState, atom } from "recoil";
|
||||
|
||||
export const ContactsContext = createContext({
|
||||
all: [
|
||||
const contactListState = atom({
|
||||
key: "contactList",
|
||||
default: [
|
||||
{
|
||||
display: "Test Contact",
|
||||
phoneNumber: "000-1111",
|
||||
@@ -15,6 +15,6 @@ export const ContactsContext = createContext({
|
||||
});
|
||||
|
||||
export const useContacts = () => {
|
||||
const [contacts, setContacts] = useConfig(ContactsContext);
|
||||
return [contacts.all, contacts => setContacts('all', contacts)]
|
||||
const [contactList, setContactList] = useRecoilState(contactListState);
|
||||
return { contactList, setContactList };
|
||||
};
|
||||
@@ -5,7 +5,7 @@ import { Box } from "@material-ui/core";
|
||||
import { useApps } from "../../appmarket/hooks/useApps";
|
||||
|
||||
export const HomeApp = () => {
|
||||
const [apps] = useApps();
|
||||
const { apps } = useApps();
|
||||
return (
|
||||
<AppWrapper>
|
||||
<Box width="100%" mt={6} px={1}>{apps && <GridMenu apps={apps.preinstalled} />}</Box>
|
||||
|
||||
@@ -22,7 +22,7 @@ export const SettingsApp = () => {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const [config] = useConfig();
|
||||
const [_settings, setSettings] = useSettings();
|
||||
const { setSettings } = useSettings();
|
||||
|
||||
const wallpaperOptions = config.wallpapers.map((w) => ({
|
||||
label: w,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import Default from '../default.json';
|
||||
import { useConfig } from '../../../config/hooks/useConfig';
|
||||
import { atom } from 'recoil';
|
||||
import Default from "../default.json";
|
||||
import { useConfig } from "../../../config/hooks/useConfig";
|
||||
import { atom } from "recoil";
|
||||
|
||||
const settingsState = atom({
|
||||
key: 'settings',
|
||||
default: Default
|
||||
})
|
||||
key: "settings",
|
||||
default: Default,
|
||||
});
|
||||
|
||||
export const useSettings = () => {
|
||||
return useConfig(settingsState);
|
||||
const [settings, setSettings] = useConfig(settingsState);
|
||||
return { settings, setSettings };
|
||||
};
|
||||
Reference in new issue
Block a user