debian-mirror-gitlab/app/assets/javascripts/lib/utils/autosave.js

34 lines
930 B
JavaScript
Raw Normal View History

2019-07-07 11:18:12 +05:30
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
2021-03-08 18:12:59 +05:30
export const clearDraft = (autosaveKey) => {
2019-07-07 11:18:12 +05:30
try {
window.localStorage.removeItem(`autosave/${autosaveKey}`);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
};
2021-03-08 18:12:59 +05:30
export const getDraft = (autosaveKey) => {
2019-07-07 11:18:12 +05:30
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) =>
2020-04-22 19:07:51 +05:30
/* eslint-disable-next-line @gitlab/require-i18n-strings */
2019-07-07 11:18:12 +05:30
['Note', capitalizeFirstCharacter(noteableType), discussionId, 'Reply'].join('/');