aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-10-15 09:44:41 +0200
committerFlorian Dold <florian@dold.me>2021-10-15 09:44:48 +0200
commit684b1efaaaa6bcfc353263b8bcf93bee22c3a7fc (patch)
tree15935b0088fbb72e1def70e4c45d8b78449256c6
parentf2492cac6d0e97aa0c90b0659cae47af834af699 (diff)
anastasis-webui: prevent webpack warning
-rw-r--r--packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts17
-rw-r--r--packages/anastasis-webui/src/sw.js4
2 files changed, 15 insertions, 6 deletions
diff --git a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
index 110ec0166..27eab0884 100644
--- a/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
+++ b/packages/anastasis-webui/src/hooks/use-anastasis-reducer.ts
@@ -235,10 +235,23 @@ export interface AnastasisReducerApi {
runTransaction(f: (h: ReducerTransactionHandle) => Promise<void>): void;
}
+function storageGet(key: string): string | null {
+ if (typeof localStorage === "object") {
+ return localStorage.getItem(key);
+ }
+ return null;
+}
+
+function storageSet(key: string, value: any): void {
+ if (typeof localStorage === "object") {
+ return localStorage.setItem(key, value);
+ }
+}
+
function restoreState(): any {
let state: any;
try {
- let s = localStorage.getItem("anastasisReducerState");
+ let s = storageGet("anastasisReducerState");
if (s === "undefined") {
state = undefined;
} else if (s) {
@@ -261,7 +274,7 @@ export function useAnastasisReducer(): AnastasisReducerApi {
const setAnastasisState = (newState: AnastasisState) => {
try {
- localStorage.setItem(
+ storageSet(
"anastasisReducerState",
JSON.stringify(newState.reducerState),
);
diff --git a/packages/anastasis-webui/src/sw.js b/packages/anastasis-webui/src/sw.js
deleted file mode 100644
index 9071b03f5..000000000
--- a/packages/anastasis-webui/src/sw.js
+++ /dev/null
@@ -1,4 +0,0 @@
-// import { getFiles, setupPrecaching, setupRouting } from 'preact-cli/sw/';
-
-// setupRouting();
-// setupPrecaching(getFiles());