diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 9da3827..9627e86 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -25,7 +25,7 @@ import { useNotesService } from './apps/notes/hooks/useNotesService'; import { usePhotoService } from './apps/camera/hooks/usePhotoService'; import Nui from './os/nui-events/utils/Nui'; import { usePhone } from './os/phone/hooks/usePhone'; -import { getStorageItem } from './os/phone/hooks/getLocalStorage'; +import { getStorage } from './os/phone/hooks/useLocalStorage'; // Inject mock data when in development env. if (process.env.NODE_ENV === 'development') { @@ -273,21 +273,19 @@ function Phone() { return (
-
+
( @@ -35,33 +38,32 @@ const SubHeaderComp = (props: { text: string }) => ( export const SettingsApp = () => { const settingsApp = useApp('SETTINGS'); const [config] = useConfig(); - const [localVal, setVal, getStorageItem] = useLocalStorage(); const simcard = useSimcard(); const wallpapers = config.wallpapers.map( - MapStringOptions(getStorageItem('wallpaper'), (val: string) => - setVal('wallpaper', val) + MapStringOptions(getStorage('wallpaper'), (val: string) => + writeStorage('wallpaper', val) ) ); const frames = config.frames.map( - MapStringOptions(getStorageItem('frame'), (val: string) => - setVal('frame', val) + MapStringOptions(getStorage('frame'), (val: string) => + writeStorage('frame', val) ) ); const themes = Object.keys(config.themes).map( - MapStringOptions(getStorageItem('theme'), (val: string) => - setVal('theme', val) + MapStringOptions(getStorage('theme'), (val: string) => + writeStorage('theme', val) ) ); const zoomOptions = config.zoomOptions.map( - MapStringOptions(getStorageItem('zoom'), (val: string) => - setVal('zoom', val) + MapStringOptions(getStorage('zoom'), (val: string) => + writeStorage('zoom', val) ) ); // Doesn't actually do anything for the time being const ringtones = config.ringtones.map( - MapStringOptions(getStorageItem('ringtone'), (val: string) => - setVal('ringtone', val) + MapStringOptions(getStorage('ringtone'), (val: string) => + writeStorage('ringtone', val) ) ); // * Probably gonna make this a slider component in the future @@ -71,9 +73,7 @@ export const SettingsApp = () => { // TODO: These new settings all work - useEffect(() => { - // this will be used to trigger a alert that gives feedback when the a setting is changed - }, [setVal]); + useEffect(() => {}, [getStorage]); const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu(); return ( @@ -88,7 +88,7 @@ export const SettingsApp = () => { /> } @@ -108,28 +108,28 @@ export const SettingsApp = () => { }> } /> } /> } /> } diff --git a/phone/src/apps/settings/hooks/useSettings.ts b/phone/src/apps/settings/hooks/useSettings.ts index c472605..dceedfe 100644 --- a/phone/src/apps/settings/hooks/useSettings.ts +++ b/phone/src/apps/settings/hooks/useSettings.ts @@ -2,8 +2,9 @@ import Default from '../default.json'; import { useConfig } from '../../../config/hooks/useConfig'; import { atom } from 'recoil'; import { createMuiTheme } from '@material-ui/core'; -import useLocalStorage from '../../../os/phone/hooks/useLocalStorage'; -import { getStorageItem } from '../../../os/phone/hooks/getLocalStorage'; +import useLocalStorage, { + getStorage, +} from '../../../os/phone/hooks/useLocalStorage'; const settingsState = atom({ key: 'settings', @@ -11,9 +12,8 @@ const settingsState = atom({ }); export const useSettings = (): any => { - const theme = getStorageItem('theme'); - const [settings, setSettings] = useLocalStorage(); + const theme = getStorage('theme'); const [config] = useConfig(); const currentTheme = () => createMuiTheme(config.themes[theme]); - return { settings, setSettings, currentTheme }; + return { currentTheme }; }; diff --git a/phone/src/config/hooks/useConfig.ts b/phone/src/config/hooks/useConfig.ts index 02f15e7..59785dd 100644 --- a/phone/src/config/hooks/useConfig.ts +++ b/phone/src/config/hooks/useConfig.ts @@ -8,7 +8,6 @@ const configState = atom({ }); export const useConfig = (state: any = configState): any => { - const [, setVal] = useLocalStorage(''); const [config, _setConfig] = useRecoilState(state); const setConfig = (key, value) => { diff --git a/phone/src/os/phone/hooks/forceUpdate.ts b/phone/src/os/phone/hooks/forceUpdate.ts deleted file mode 100644 index ebf5e3c..0000000 --- a/phone/src/os/phone/hooks/forceUpdate.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { useRecoilState } from 'recoil'; -import { phoneState } from './state'; - -export const useForceUpdate = () => { - const [update, setUpdate] = useRecoilState(phoneState.forceUpdateState); - return { update, setUpdate }; -}; diff --git a/phone/src/os/phone/hooks/getLocalStorage.ts b/phone/src/os/phone/hooks/getLocalStorage.ts deleted file mode 100644 index 84e2838..0000000 --- a/phone/src/os/phone/hooks/getLocalStorage.ts +++ /dev/null @@ -1,12 +0,0 @@ -export const getStorageItem = (key: string) => { - const UNIQ_PREFIX = 'npwd_phone_'; - try { - const data = window.localStorage.getItem(UNIQ_PREFIX + key); - // return stored or initValue if none stored - return JSON.parse(data); - } catch (e) { - // TODO: Integrate debug error state here - console.log(e); - // We still return initVal if error is thrown - } -}; diff --git a/phone/src/os/phone/hooks/useLocalStorage.ts b/phone/src/os/phone/hooks/useLocalStorage.ts index 042acf3..2467a98 100644 --- a/phone/src/os/phone/hooks/useLocalStorage.ts +++ b/phone/src/os/phone/hooks/useLocalStorage.ts @@ -9,7 +9,7 @@ import { useState } from 'react'; * if there is no savedState */ -function useLocalStorage(key?: string, initialValue?: T) { +function useLocalStorage(key: string, initialValue: T) { // Serves as a nice identifying prefix for the key const UNIQ_PREFIX = 'npwd_phone_'; const [localVal, setLocalVal] = useState(() => { @@ -43,7 +43,27 @@ function useLocalStorage(key?: string, initialValue?: T) { } }; - return [localVal, setVal] as const; + return [localVal, setVal]; } +export const writeStorage = (key: string, value: T) => { + const UNIQ_PREFIX = 'npwd_phone_'; + + try { + window.localStorage.setItem(UNIQ_PREFIX + key, JSON.stringify(value)); + } catch (error) { + console.log(error); + } +}; + +export const getStorage = (key: string) => { + const UNIQ_PREFIX = 'npwd_phone_'; + try { + const data = window.localStorage.getItem(UNIQ_PREFIX + key); + return JSON.parse(data); + } catch (error) { + console.log(error); + } +}; + export default useLocalStorage;