chore: Cleanup update banner with localstorage updates (#5209)

Co-authored-by: Aswin Dev P.S <aswindevps@gmail.com>
This commit is contained in:
Pranav Raj S
2022-08-05 13:46:12 +05:30
committed by GitHub
parent fc9699d993
commit 124390a019
5 changed files with 104 additions and 63 deletions

View File

@@ -1,17 +1,32 @@
class LocalStorage {
constructor(key) {
this.key = key;
}
export const LOCAL_STORAGE_KEYS = {
DISMISSED_UPDATES: 'dismissedUpdates',
WIDGET_BUILDER: 'widgetBubble_',
};
store(allItems) {
localStorage.setItem(this.key, JSON.stringify(allItems));
localStorage.setItem(this.key + ':ts', Date.now());
}
export const LocalStorage = {
clearAll() {
window.localStorage.clear();
},
get() {
let stored = localStorage.getItem(this.key);
return JSON.parse(stored) || [];
}
}
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());
},
export default LocalStorage;
remove(key) {
window.localStorage.removeItem(key);
window.localStorage.removeItem(key + ':ts');
},
};