Chore: moves localstorage helper as a shared utility (#6838)

* Chore: moves localstorage helper as a shared utility and refactors constants

* Refactors constants file

* Fixes merge conflicts

* Delete constants.js

---------

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
Nithin David Thomas
2023-04-11 15:50:46 +05:30
committed by GitHub
parent 17ff1f11a7
commit 09ce85b30d
29 changed files with 36 additions and 36 deletions

View File

@@ -0,0 +1,27 @@
export const LocalStorage = {
clearAll() {
window.localStorage.clear();
},
get(key) {
const value = window.localStorage.getItem(key);
try {
return typeof value === 'string' ? JSON.parse(value) : value;
} catch (error) {
return value;
}
},
set(key, value) {
if (typeof value === 'object') {
window.localStorage.setItem(key, JSON.stringify(value));
} else {
window.localStorage.setItem(key, value);
}
window.localStorage.setItem(key + ':ts', Date.now());
},
remove(key) {
window.localStorage.removeItem(key);
window.localStorage.removeItem(key + ':ts');
},
};

View File

@@ -1,4 +1,4 @@
import wootConstants from 'dashboard/constants';
import wootConstants from 'dashboard/constants/globals';
export default {
methods: {