mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
feat(localstorage): resolved issue with phone not re-rendering
This commit is contained in:
1 parent
14223c9800
commit
dddddc01f8
5 files changed
+19
-6
No files matched your search
@@ -6,6 +6,7 @@ import {
|
||||
ListItemIcon,
|
||||
} from '@material-ui/core';
|
||||
import { SvgIconProps } from '@material-ui/core';
|
||||
|
||||
interface IProps {
|
||||
options?: any;
|
||||
label: string;
|
||||
|
||||
@@ -35,15 +35,9 @@ const SubHeaderComp = (props: { text: string }) => (
|
||||
export const SettingsApp = () => {
|
||||
const settingsApp = useApp('SETTINGS');
|
||||
const [config] = useConfig();
|
||||
const { setSettings, settings } = useSettings();
|
||||
const [localVal, setVal, getStorageItem] = useLocalStorage();
|
||||
const simcard = useSimcard();
|
||||
|
||||
useEffect(() => {
|
||||
console.log('new localstorage');
|
||||
// this will be used to trigger a alert that gives feedback when the a setting is changed
|
||||
}, [localVal]);
|
||||
|
||||
const wallpapers = config.wallpapers.map(
|
||||
MapStringOptions(getStorageItem('wallpaper'), (val: string) =>
|
||||
setVal('wallpaper', val)
|
||||
@@ -77,6 +71,10 @@ 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]);
|
||||
|
||||
const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu();
|
||||
return (
|
||||
<AppWrapper>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { phoneState } from './state';
|
||||
|
||||
export const useForceUpdate = () => {
|
||||
const [update, setUpdate] = useRecoilState(phoneState.forceUpdateState);
|
||||
return { update, setUpdate };
|
||||
};
|
||||
@@ -9,4 +9,8 @@ export const phoneState = {
|
||||
key: 'phoneConfig',
|
||||
default: undefined,
|
||||
}),
|
||||
forceUpdateState: atom({
|
||||
key: 'fuckingupdate',
|
||||
default: 0,
|
||||
}),
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
import { useForceUpdate } from '../../../os/phone/hooks/forceUpdate';
|
||||
|
||||
// TODO: Integrate debug log to fetch when that branch is merged
|
||||
|
||||
@@ -10,6 +11,7 @@ import { useState } from 'react';
|
||||
*/
|
||||
|
||||
function useLocalStorage<T>(key?: string, initialValue?: T) {
|
||||
const { update, setUpdate } = useForceUpdate();
|
||||
// Serves as a nice identifying prefix for the key
|
||||
const UNIQ_PREFIX = 'npwd_phone_';
|
||||
const [localVal, setLocalVal] = useState<T>(() => {
|
||||
@@ -42,6 +44,7 @@ function useLocalStorage<T>(key?: string, initialValue?: T) {
|
||||
const setVal = (localKey, value: T | ((val: T) => T)) => {
|
||||
console.log(localKey, value);
|
||||
try {
|
||||
setUpdate(update + 1);
|
||||
// Same API as useState meaning we can accept a function for value
|
||||
const valForStore = value instanceof Function ? value(localVal) : value;
|
||||
// Save that state so we repli useState
|
||||
|
||||
Reference in new issue
Block a user