summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/visual_review_toolbar/components/comment_storage.js
blob: 49c9400437e7a09c1b4ca5fed9f30ada6a328190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { selectCommentBox } from './utils';
import { sessionStorage, STORAGE_COMMENT } from '../shared';

const getSavedComment = () => sessionStorage.getItem(STORAGE_COMMENT) || '';

const saveComment = () => {
  const currentComment = selectCommentBox();

  // This may be added to any view via top-level beforeunload listener
  // so let's skip if it does not apply
  if (currentComment && currentComment.value) {
    sessionStorage.setItem(STORAGE_COMMENT, currentComment.value);
  }
};

const clearSavedComment = () => {
  sessionStorage.removeItem(STORAGE_COMMENT);
};

export { getSavedComment, saveComment, clearSavedComment };