Use redux directly when setting numeric configs
This commit is contained in:
parent
8fa3ac611a
commit
394b44eb15
|
@ -1,6 +1,6 @@
|
|||
import { store } from "../redux/store";
|
||||
import { getWebAppConfig } from "../resources/selectors";
|
||||
import { BooleanConfigKey } from "../config_storage/web_app_configs";
|
||||
import { BooleanConfigKey, NumberConfigKey } from "../config_storage/web_app_configs";
|
||||
import { edit, save } from "../api/crud";
|
||||
|
||||
/**
|
||||
|
@ -29,9 +29,22 @@ export function setBoolViaRedux(key: BooleanConfigKey, val: boolean) {
|
|||
if (conf) {
|
||||
store.dispatch(edit(conf, { [key]: val }));
|
||||
store.dispatch(save(conf.uuid));
|
||||
} else {
|
||||
console.log("Be concerned.");
|
||||
debugger;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/** Avoid using this function in new places. Pass props instead. */
|
||||
export function getNumViaRedux(key: NumberConfigKey): number | undefined {
|
||||
const conf = getWebAppConfig(store.getState().resources.index);
|
||||
return conf && conf.body[key];
|
||||
}
|
||||
|
||||
/** Avoid using this function in new places. Pass props instead. */
|
||||
export function setNumViaRedux(key: NumberConfigKey, val: number): number {
|
||||
const conf = getWebAppConfig(store.getState().resources.index);
|
||||
if (conf) {
|
||||
store.dispatch(edit(conf, { [key]: val }));
|
||||
store.dispatch(save(conf.uuid));
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -180,7 +180,6 @@ export let botReducer = generateReducer<BotState>(initialState(), afterEach)
|
|||
return s;
|
||||
})
|
||||
.add<void>(Actions.STASH_STATUS, (s, a) => {
|
||||
console.log("Stash status (singular)");
|
||||
stashStatus(s);
|
||||
return s;
|
||||
})
|
||||
|
@ -190,11 +189,9 @@ export let botReducer = generateReducer<BotState>(initialState(), afterEach)
|
|||
const isDown = status.state === "down";
|
||||
if (isBotMqtt) { /** This is way too hard to maintain */
|
||||
if (isDown) {
|
||||
console.log("Edge change stash");
|
||||
stashStatus(s);
|
||||
s.hardware.informational_settings.sync_status = undefined;
|
||||
} else {
|
||||
console.log("Edge change unstash");
|
||||
const botMqtt = s.connectivity["bot.mqtt"];
|
||||
if (botMqtt && botMqtt.state === "down") { // Going from "down" to "up"
|
||||
s.hardware.informational_settings.sync_status = s.statusStash;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { AuthState } from "./auth/interfaces";
|
||||
import { box } from "boxed_value";
|
||||
import { get, isNumber } from "lodash";
|
||||
import { BooleanConfigKey, NumberConfigKey } from "./config_storage/web_app_configs";
|
||||
import { BooleanSetting, NumericSetting } from "./session_keys";
|
||||
import { getBoolViaRedux, setBoolViaRedux } from "./config/legacy_shims";
|
||||
import { getBoolViaRedux, setBoolViaRedux, getNumViaRedux, setNumViaRedux } from "./config/legacy_shims";
|
||||
|
||||
/** The `Session` namespace is a wrapper for `localStorage`.
|
||||
* Use this to avoid direct access of `localStorage` where possible.
|
||||
|
@ -63,13 +62,12 @@ export namespace Session {
|
|||
/** Extract numeric settings from `localStorage`. Returns `undefined` when
|
||||
* none are found. */
|
||||
export function getNum(key: NumberConfigKey): number | undefined {
|
||||
const output = JSON.parse(get(localStorage, key, "null"));
|
||||
return (isNumber(output)) ? output : undefined;
|
||||
return getNumViaRedux(key);
|
||||
}
|
||||
|
||||
/** Set a numeric value in `localStorage`. */
|
||||
export function setNum(key: NumberConfigKey, val: number): void {
|
||||
localStorage.setItem(key, JSON.stringify(val));
|
||||
setNumViaRedux(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue