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:
committed by
GitHub
parent
17ff1f11a7
commit
09ce85b30d
27
app/javascript/shared/helpers/localStorage.js
Normal file
27
app/javascript/shared/helpers/localStorage.js
Normal 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');
|
||||
},
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import wootConstants from 'dashboard/constants';
|
||||
import wootConstants from 'dashboard/constants/globals';
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
|
||||
Reference in New Issue
Block a user