Don't throw error when localStorage is null (#2505)
This commit is contained in:
parent
a4e1f2c5c1
commit
7c7fb4903b
@ -99,19 +99,31 @@ export const importFromLocalStorage = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getElementsStorageSize = () => {
|
export const getElementsStorageSize = () => {
|
||||||
|
try {
|
||||||
const elements = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS);
|
const elements = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS);
|
||||||
const elementsSize = elements ? JSON.stringify(elements).length : 0;
|
const elementsSize = elements ? JSON.stringify(elements).length : 0;
|
||||||
return elementsSize;
|
return elementsSize;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTotalStorageSize = () => {
|
export const getTotalStorageSize = () => {
|
||||||
|
try {
|
||||||
const appState = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_APP_STATE);
|
const appState = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_APP_STATE);
|
||||||
const collab = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_COLLAB);
|
const collab = localStorage.getItem(STORAGE_KEYS.LOCAL_STORAGE_COLLAB);
|
||||||
const library = localStorage.getItem(APP_STORAGE_KEYS.LOCAL_STORAGE_LIBRARY);
|
const library = localStorage.getItem(
|
||||||
|
APP_STORAGE_KEYS.LOCAL_STORAGE_LIBRARY,
|
||||||
|
);
|
||||||
|
|
||||||
const appStateSize = appState ? JSON.stringify(appState).length : 0;
|
const appStateSize = appState ? JSON.stringify(appState).length : 0;
|
||||||
const collabSize = collab ? JSON.stringify(collab).length : 0;
|
const collabSize = collab ? JSON.stringify(collab).length : 0;
|
||||||
const librarySize = library ? JSON.stringify(library).length : 0;
|
const librarySize = library ? JSON.stringify(library).length : 0;
|
||||||
|
|
||||||
return appStateSize + collabSize + librarySize + getElementsStorageSize();
|
return appStateSize + collabSize + librarySize + getElementsStorageSize();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user