diff --git a/package.json b/package.json index 483e435..d1850d9 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.5.0", "@testing-library/user-event": "^7.2.1", + "lodash": "^4.17.20", "react": "^16.13.1", "react-dom": "^16.13.1", "react-router-dom": "^5.2.0", diff --git a/public/media/backgrounds/legacy.jpg b/public/media/backgrounds/legacy.jpg new file mode 100644 index 0000000..40a7467 Binary files /dev/null and b/public/media/backgrounds/legacy.jpg differ diff --git a/src/Phone.js b/src/Phone.js index ec582c6..2978f40 100644 --- a/src/Phone.js +++ b/src/Phone.js @@ -1,7 +1,7 @@ import React from "react"; import "./Phone.css"; -import { HomeApp } from "./apps/home"; import { Route } from "react-router-dom"; +import { HomeApp } from "./apps/home/components/Home"; function Phone() { return ( diff --git a/src/apps/contacts/index.js b/src/apps/contacts/index.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/apps/home/components/AppIcon.js b/src/apps/home/components/AppIcon.js new file mode 100644 index 0000000..76bebf0 --- /dev/null +++ b/src/apps/home/components/AppIcon.js @@ -0,0 +1,7 @@ +import React from "react"; +import { useSettings } from "../../settings/hooks/useSettings"; + +export const AppIcon = ({ label, icon }) => { + const [settings] = useSettings(); + return {label}; +}; diff --git a/src/apps/home/components/GridMenu.js b/src/apps/home/components/GridMenu.js new file mode 100644 index 0000000..3388085 --- /dev/null +++ b/src/apps/home/components/GridMenu.js @@ -0,0 +1,14 @@ +import React from "react"; +import { AppIcon } from "./AppIcon"; + +export const GridMenu = ({ apps }) => { + return ( +
+ {apps.map((app) => ( +
+ +
+ ))} +
+ ); +}; diff --git a/src/apps/home/components/Home.js b/src/apps/home/components/Home.js index 12c9499..9691a71 100644 --- a/src/apps/home/components/Home.js +++ b/src/apps/home/components/Home.js @@ -1,6 +1,17 @@ -import React from 'react'; -import { AppWrapper } from '../../../ui/components'; +import React from "react"; +import { AppWrapper } from "../../../ui/components"; +import { useSettings } from "../../settings/hooks/useSettings"; +import { GridMenu } from "./GridMenu"; -export const HomeApp = ({}) => { - return Home! +export const HomeApp = () => { + const [settings] = useSettings(); + return ( + + + + ); }; diff --git a/src/apps/home/index.js b/src/apps/home/index.js deleted file mode 100644 index eceab89..0000000 --- a/src/apps/home/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from './components/Home'; diff --git a/src/apps/settings/default.json b/src/apps/settings/default.json new file mode 100644 index 0000000..fa0a4c7 --- /dev/null +++ b/src/apps/settings/default.json @@ -0,0 +1,9 @@ +{ + "wallpaper": "default.png", + "apps": [ + { + "name": "Contacts", + "icon": "contacts.png" + } + ] +} \ No newline at end of file diff --git a/src/apps/settings/hooks/useSettings.js b/src/apps/settings/hooks/useSettings.js new file mode 100644 index 0000000..0f18652 --- /dev/null +++ b/src/apps/settings/hooks/useSettings.js @@ -0,0 +1,9 @@ +import { createContext } from 'react'; +import Default from '../default.json'; +import { useConfig } from '../../../config/hooks/useConfig'; + +export const SettingsContext = createContext(Default); + +export const useSettings = () => { + return useConfig(SettingsContext); +}; diff --git a/src/config/default.json b/src/config/default.json new file mode 100644 index 0000000..91875d2 --- /dev/null +++ b/src/config/default.json @@ -0,0 +1,4 @@ +{ + "4gNetowrk": "AT&T", + "language": "en_US" +} \ No newline at end of file diff --git a/src/config/hooks/useConfig.js b/src/config/hooks/useConfig.js new file mode 100644 index 0000000..b6497eb --- /dev/null +++ b/src/config/hooks/useConfig.js @@ -0,0 +1,20 @@ +import { createContext, useContext, useEffect, useState } from "react"; +import _set from "lodash/set"; +import Default from "../default.json"; + +export const ConfigContext = createContext(Default); + +export const useConfig = (Context = ConfigContext) => { + const configCtx = useContext(Context); + const [config, _setConfig] = useState({ ...configCtx }); + + useEffect(() => { + _setConfig({ ...configCtx }); + }, [configCtx]); + + const setConfig = (key, value) => { + const state = { ...config }; + _setConfig(_set(state, key, value)); + }; + return [config, setConfig]; +}; diff --git a/src/ui/components/AppWrapper.js b/src/ui/components/AppWrapper.js index 3bf1981..5357899 100644 --- a/src/ui/components/AppWrapper.js +++ b/src/ui/components/AppWrapper.js @@ -1,5 +1,12 @@ -import React from 'react'; +import React from "react"; export const AppWrapper = ({ children, style, ...props }) => { - return
{children}
+ return ( +
+
{children}
+
+ ); }; diff --git a/yarn.lock b/yarn.lock index c376dba..8d30175 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6629,7 +6629,7 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -"lodash@>=3.5 <5", lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.5: +"lodash@>=3.5 <5", lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.5: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==