introduced designer id, bring to front

This commit is contained in:
Jan Prochazka
2020-12-26 10:28:49 +01:00
parent 54bdaac64f
commit 95e0905f01
3 changed files with 41 additions and 19 deletions

View File

@@ -4,6 +4,19 @@ import localforage from 'localforage';
import { changeTab } from './common';
import { useSetOpenedTabs } from './globalState';
function getParsedLocalStorage(key) {
const value = localStorage.getItem(key);
if (value != null) {
try {
const res = JSON.parse(value);
return res;
} catch (e) {
localStorage.removeItem(key);
}
}
return null;
}
export default function useEditorData({ tabid, reloadToken = 0, loadFromArgs = null }) {
const localStorageKey = `tabdata_editor_${tabid}`;
const setOpenedTabs = useSetOpenedTabs();
@@ -34,7 +47,7 @@ export default function useEditorData({ tabid, reloadToken = 0, loadFromArgs = n
console.error(err.response);
}
} else {
const initFallback = localStorage.getItem(localStorageKey);
const initFallback = getParsedLocalStorage(localStorageKey);
if (initFallback != null) {
const init = JSON.parse(initFallback);
setValue(init);