debian-mirror-gitlab/app/assets/javascripts/lib/utils/autosave.js
2019-07-07 11:18:12 +05:30

32 lines
864 B
JavaScript

import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
export const clearDraft = autosaveKey => {
try {
window.localStorage.removeItem(`autosave/${autosaveKey}`);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
};
export const getDraft = autosaveKey => {
try {
return window.localStorage.getItem(`autosave/${autosaveKey}`);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
return null;
}
};
export const updateDraft = (autosaveKey, text) => {
try {
window.localStorage.setItem(`autosave/${autosaveKey}`, text);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
};
export const getDiscussionReplyKey = (noteableType, discussionId) =>
['Note', capitalizeFirstCharacter(noteableType), discussionId, 'Reply'].join('/');