improve settings hook

This commit is contained in:
J Francisco Rader committed 2020-08-22 18:46:57 -03:00
1 parent 362ab8be4d
commit 26cf051696
2 files changed
+10 -9

No files matched your search

+6 -8
View File
@@ -11,13 +11,12 @@ import MessageIcon from "@material-ui/icons/Email";
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";
import { ThemeProvider, createMuiTheme } from "@material-ui/core"; import { ThemeProvider } from "@material-ui/core";
import { useConfig } from "./config/hooks/useConfig";
function Phone() { function Phone() {
const { settings } = useSettings(); const { settings, currentTheme } = useSettings();
const [config] = useConfig();
return ( return (
<ThemeProvider theme={currentTheme()}>
<div className="PhoneWrapper"> <div className="PhoneWrapper">
<div style={{ zoom: "80%" }}> <div style={{ zoom: "80%" }}>
<div className="Phone"> <div className="Phone">
@@ -27,7 +26,6 @@ function Phone() {
backgroundImage: `${process.env.PUBLIC_URL}url(/media/frames/${settings.frame})`, backgroundImage: `${process.env.PUBLIC_URL}url(/media/frames/${settings.frame})`,
}} }}
></div> ></div>
<ThemeProvider theme={createMuiTheme(config.themes[settings.theme])}>
<div <div
id="phone" id="phone"
className="PhoneScreen" className="PhoneScreen"
@@ -45,10 +43,10 @@ function Phone() {
</div> </div>
<NavigationBar /> <NavigationBar />
</div> </div>
</div>
</div>
</div>
</ThemeProvider> </ThemeProvider>
</div>
</div>
</div>
); );
} }
+4 -1
View File
@@ -1,6 +1,7 @@
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";
import { createMuiTheme } from "@material-ui/core";
const settingsState = atom({ const settingsState = atom({
key: "settings", key: "settings",
@@ -9,5 +10,7 @@ const settingsState = atom({
export const useSettings = () => { export const useSettings = () => {
const [settings, setSettings] = useConfig(settingsState); const [settings, setSettings] = useConfig(settingsState);
return { settings, setSettings }; const [config] = useConfig();
const currentTheme = () => createMuiTheme(config.themes[settings.theme]);
return { settings, setSettings, currentTheme };
}; };