You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
550 B
TypeScript
21 lines
550 B
TypeScript
import { Const } from "../../common/utils.ts";
|
|
import { State } from "../components/App/state.ts";
|
|
|
|
export const defaultAppState: State = {
|
|
view: { kind: "Home", state: null },
|
|
};
|
|
|
|
export const LOCAL_STORAGE_KEY = "zchemaAppState";
|
|
export const saveStateToLocalStorage = (state: Const<State>) => {
|
|
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(state));
|
|
};
|
|
|
|
export const loadStateFromLocalStorage = (): State => {
|
|
const r = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
if (r == null) {
|
|
return defaultAppState;
|
|
}
|
|
|
|
return JSON.parse(r);
|
|
};
|