From d32eaf63cf59fb598c5ec4650070c361394e826d Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Tue, 8 Mar 2022 10:19:02 -0800 Subject: [PATCH] Disable local storage on embedded view --- .../src/components/LocalStorageManager.ts | 19 +++++++++++++++---- packages/webapp/src/redux/clientSlice.ts | 6 +++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/mindplot/src/components/LocalStorageManager.ts b/packages/mindplot/src/components/LocalStorageManager.ts index 6c266e56..ae35abe3 100644 --- a/packages/mindplot/src/components/LocalStorageManager.ts +++ b/packages/mindplot/src/components/LocalStorageManager.ts @@ -23,23 +23,34 @@ class LocalStorageManager extends PersistenceManager { private forceLoad: boolean; - constructor(documentUrl: string, forceLoad: boolean) { + private readOnly: boolean; + + constructor(documentUrl: string, forceLoad: boolean, readOnly = true) { super(); this.documentUrl = documentUrl; this.forceLoad = forceLoad; + this.readOnly = readOnly; } saveMapXml(mapId: string, mapDoc: Document): void { const mapXml = new XMLSerializer().serializeToString(mapDoc); - localStorage.setItem(`${mapId}-xml`, mapXml); + if (!this.readOnly) { + localStorage.setItem(`${mapId}-xml`, mapXml); + } + console.log(`Map XML to save => ${this.saveMapXml}`); } discardChanges(mapId: string) { - localStorage.removeItem(`${mapId}-xml`); + if (!this.readOnly) { + localStorage.removeItem(`${mapId}-xml`); + } } loadMapDom(mapId: string) { - let xml = localStorage.getItem(`${mapId}-xml`); + let xml; + if (!this.readOnly) { + xml = localStorage.getItem(`${mapId}-xml`); + } if (xml == null || this.forceLoad) { $.ajax({ url: this.documentUrl.replace('{id}', mapId), diff --git a/packages/webapp/src/redux/clientSlice.ts b/packages/webapp/src/redux/clientSlice.ts index 6cc61b22..1fe4f199 100644 --- a/packages/webapp/src/redux/clientSlice.ts +++ b/packages/webapp/src/redux/clientSlice.ts @@ -47,12 +47,12 @@ export const fetchMapById = (id: number): MapLoadResult => { return client.fetchAllMaps(); }); + // Sanitize error structure ... let errorMsg: ErrorInfo = Object.keys(error).length !== 0 ? error : null; + + // If the map can not be loaded, create an error object. let map: MapInfo; if (!isLoading) { - // Sanitize error structure ... - - // If the map can not be loaded, create an error object. map = data?.find((m) => m.id == id); if (map === null && !errorMsg) { errorMsg = { msg: `Map with id ${id} could not be found. Please, reflesh the page` }