summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob/utils.js
blob: b2400a4b22473626d1fb51a0b9d5434f0efb20eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { getBaseURL } from '~/lib/utils/url_utility';

const blameLinesPerPage = document.querySelector('.js-per-page')?.dataset?.blamePerPage;

export const getPageParamValue = (lineNum, blamePerPage = blameLinesPerPage) => {
  if (!blamePerPage) return '';
  const page = Math.ceil(parseInt(lineNum, 10) / parseInt(blamePerPage, 10));
  return page <= 1 ? '' : page;
};

export const getPageSearchString = (path, page) => {
  if (!page) return '';
  const url = new URL(path, getBaseURL());
  url.searchParams.set('page', page);
  return url.search;
};

export default () => ({});