Welcome to mirror list, hosted at ThFree Co, Russian Federation.

preferences.js « utils « diffs « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e440de3350ae0d37ccffb344e60d88b2d2ebb9cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import Cookies from 'js-cookie';
import { getParameterValues } from '~/lib/utils/url_utility';

import { DIFF_FILE_BY_FILE_COOKIE_NAME, DIFF_VIEW_FILE_BY_FILE } from '../constants';

export function fileByFile(pref = false) {
  const search = getParameterValues(DIFF_FILE_BY_FILE_COOKIE_NAME)?.[0];
  const cookie = Cookies.get(DIFF_FILE_BY_FILE_COOKIE_NAME);
  let viewFileByFile = pref;

  // use the cookie first, if it exists
  if (cookie) {
    viewFileByFile = cookie === DIFF_VIEW_FILE_BY_FILE;
  }

  // the search parameter of the URL should override, if it exists
  if (search) {
    viewFileByFile = search === DIFF_VIEW_FILE_BY_FILE;
  }

  return viewFileByFile;
}