* Add draft support * Fixes issue with draft loading * Adds draft for private notes * Use localstorage helper * .remove instead of .clear * Remove timestamp * clearLocalStorageOnLogout * Fix draft save on refresh * Remove usage of delete operator * Adds autosave for draft messages * Remove setinterval and add debounce * Removes draft redundancy check * Adds test cases for debouncer * Update app/javascript/shared/helpers/specs/TimeHelpers.spec.js Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> * Update app/javascript/shared/helpers/specs/TimeHelpers.spec.js Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> * Review fixes * Fixes issue with debouncer * FIxes debouncer issue * Fixes issue with draft empty message * Removes empty keys from local storage drafts * Fixes error with empty draft Co-authored-by: Pranav Raj S <pranav@chatwoot.com> Co-authored-by: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com>
33 lines
760 B
JavaScript
33 lines
760 B
JavaScript
export const LOCAL_STORAGE_KEYS = {
|
|
DISMISSED_UPDATES: 'dismissedUpdates',
|
|
DRAFT_MESSAGES: 'draftMessages',
|
|
};
|
|
|
|
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');
|
|
},
|
|
};
|