diff --git a/package.json b/package.json index 259e5cc..019f87b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "react-dom": "^16.13.1", "react-i18next": "^11.7.1", "react-router-dom": "^5.2.0", - "react-scripts": "3.4.3" + "react-scripts": "3.4.3", + "recoil": "^0.0.10" }, "scripts": { "start": "react-scripts start", diff --git a/src/apps/appmarket/hooks/useApps.js b/src/apps/appmarket/hooks/useApps.js index 2853b2a..5b53f00 100644 --- a/src/apps/appmarket/hooks/useApps.js +++ b/src/apps/appmarket/hooks/useApps.js @@ -1,14 +1,18 @@ -import React, { createContext, useEffect } from "react"; +import React, { useEffect } from "react"; import { useConfig } from "../../../config/hooks/useConfig"; import { blue, grey } 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 { atom } from "recoil"; -const AppsContext = createContext(null); +const appsState = atom({ + key: 'apps', + default: null +}); export const useApps = () => { - const [apps, setApps] = useConfig(AppsContext); + const [apps, setApps] = useConfig(appsState); const { t } = useTranslation(); useEffect(() => { setApps("preinstalled", [ diff --git a/src/apps/settings/components/Settings.js b/src/apps/settings/components/Settings.js index 019edd3..0f4251d 100644 --- a/src/apps/settings/components/Settings.js +++ b/src/apps/settings/components/Settings.js @@ -22,14 +22,16 @@ export const SettingsApp = () => { const classes = useStyles(); const { t } = useTranslation(); const [config] = useConfig(); - const [settings, setSettings] = useSettings(); + const [_settings, setSettings] = useSettings(); const wallpaperOptions = config.wallpapers.map((w) => ({ label: w, onClick: () => setSettings("wallpaper", w), })); - const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu(wallpaperOptions); + const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu( + wallpaperOptions + ); return ( {t("APPS_SETTINGS")} @@ -40,7 +42,7 @@ export const SettingsApp = () => { - + ); }; diff --git a/src/apps/settings/hooks/useSettings.js b/src/apps/settings/hooks/useSettings.js index 0f18652..04313e2 100644 --- a/src/apps/settings/hooks/useSettings.js +++ b/src/apps/settings/hooks/useSettings.js @@ -1,9 +1,12 @@ -import { createContext } from 'react'; import Default from '../default.json'; import { useConfig } from '../../../config/hooks/useConfig'; +import { atom } from 'recoil'; -export const SettingsContext = createContext(Default); +const settingsState = atom({ + key: 'settings', + default: Default + }) export const useSettings = () => { - return useConfig(SettingsContext); + return useConfig(settingsState); }; diff --git a/src/config/hooks/useConfig.js b/src/config/hooks/useConfig.js index b6497eb..68f41c4 100644 --- a/src/config/hooks/useConfig.js +++ b/src/config/hooks/useConfig.js @@ -1,20 +1,22 @@ -import { createContext, useContext, useEffect, useState } from "react"; -import _set from "lodash/set"; import Default from "../default.json"; +import { atom, useRecoilState } from "recoil"; -export const ConfigContext = createContext(Default); +const configState = atom({ + key: 'config', + default: Default +}) -export const useConfig = (Context = ConfigContext) => { - const configCtx = useContext(Context); - const [config, _setConfig] = useState({ ...configCtx }); +console.log(Default) - useEffect(() => { - _setConfig({ ...configCtx }); - }, [configCtx]); +export const useConfig = (state = configState) => { + const [config, _setConfig] = useRecoilState(state) const setConfig = (key, value) => { - const state = { ...config }; - _setConfig(_set(state, key, value)); + _setConfig(oldConfig => ({ + ...oldConfig, + [key]: value + })); }; + return [config, setConfig]; }; diff --git a/src/index.js b/src/index.js index 03de0c9..f84a406 100644 --- a/src/index.js +++ b/src/index.js @@ -4,11 +4,14 @@ import "./main.css"; import Phone from "./Phone"; import * as serviceWorker from "./serviceWorker"; import { BrowserRouter } from "react-router-dom"; +import { RecoilRoot } from "recoil"; ReactDOM.render( - + + + , document.getElementById("root") diff --git a/src/os/components/NavigationBar.js b/src/os/components/NavigationBar.js index 8cc5ea1..f8eab4b 100644 --- a/src/os/components/NavigationBar.js +++ b/src/os/components/NavigationBar.js @@ -5,7 +5,6 @@ import { BottomNavigationAction, } from "@material-ui/core"; import { grey } from "@material-ui/core/colors"; -import { fade } from "@material-ui/core/styles/colorManipulator"; import KeyboardArrowLeftIcon from "@material-ui/icons/KeyboardArrowLeft"; import AppsIcon from "@material-ui/icons/Apps"; import { useHistory } from "react-router-dom"; diff --git a/src/ui/components/AppWrapper.js b/src/ui/components/AppWrapper.js index 70a2619..b1dc92d 100644 --- a/src/ui/components/AppWrapper.js +++ b/src/ui/components/AppWrapper.js @@ -1,5 +1,4 @@ import React from "react"; -import { ClickAwayListener } from "@material-ui/core"; export const AppWrapper = ({ children, style, handleClickAway, ...props }) => { return ( diff --git a/src/ui/components/ContextMenu.js b/src/ui/components/ContextMenu.js index cb02d64..40b1c23 100644 --- a/src/ui/components/ContextMenu.js +++ b/src/ui/components/ContextMenu.js @@ -1,13 +1,11 @@ import React from "react"; import { - Drawer, ListItem, List, ListItemIcon, ListItemText, Slide, makeStyles, - ClickAwayListener, } from "@material-ui/core"; const useStyles = makeStyles((theme) => ({ @@ -15,33 +13,31 @@ const useStyles = makeStyles((theme) => ({ width: "100%", backgroundColor: theme.palette.background.default, color: "black", - zIndex: 2 + zIndex: 2, }, })); -export const ContextMenu = ({ open, onClose, handleClickAway, options }) => { +export const ContextMenu = ({ open, onClose, options }) => { const classes = useStyles(); return ( - - - - - {options.map((option) => ( - { - option.onClick(e, option); - onClose(); - }} - > - {option.icon} - - - ))} - - - - + + + + {options.map((option) => ( + { + option.onClick(e, option); + onClose(); + }} + > + {option.icon} + + + ))} + + + ); }; diff --git a/yarn.lock b/yarn.lock index 71888e9..99e2693 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9087,6 +9087,11 @@ realpath-native@^1.1.0: dependencies: util.promisify "^1.0.0" +recoil@^0.0.10: + version "0.0.10" + resolved "https://registry.yarnpkg.com/recoil/-/recoil-0.0.10.tgz#679ab22306f559f8a63c46fd5ff5241539f9248f" + integrity sha512-+9gRqehw3yKETmoZbhSnWu4GO10HDb5xYf1CjLF1oXGK2uT6GX5Lu9mfTXwjxV/jXxEKx8MIRUUbgPxvbJ8SEw== + recursive-readdir@2.2.2: version "2.2.2" resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.2.tgz#9946fb3274e1628de6e36b2f6714953b4845094f"