Repository: go-gitea/gitea
File: web_src/js/features/repo-graph.ts (TypeScript)

Code before:
import {toggleClass} from '../utils/dom.ts';
import {GET} from '../modules/fetch.ts';
import {fomanticQuery} from '../modules/fomantic/base.ts';

export function initRepoGraphGit() {
  const graphContainer = document.querySelector<HTMLElement>('#git-graph-container');
  if (!graphContainer) return;

  const elColorMonochrome = document.querySelector<HTMLElement>('#flow-color-monochrome');
  const elColorColored = document.querySelector<HTMLElement>('#flow-color-colored');
  const toggleColorMode = (mode: 'monochrome' | 'colored') => {
    toggleClass(graphContainer, 'monochrome', mode === 'monochrome');
    toggleClass(graphContainer, 'colored', mode === 'colored');

    toggleClass(elColorMonochrome, 'active', mode === 'monochrome');
    toggleClass(elColorColored, 'active', mode === 'colored');

    const params = new URLSearchParams(window.location.search);
    params.set('mode', mode);
    window.history.replaceState({}, '', `?${params.toString()}`);
    for (const link of document.querySelectorAll('#pagination .pagination a')) {
      const href = link.getAttribute('href');
      if (!href) continue;
      const url = new URL(href, window.location.href);
      const params = url.searchParams;
      params.set('mode', mode);
      url.search = `?${params.toString()}`;
      link.setAttribute('href', url.href);
    }
  };
  elColorMonochrome.addEventListener('click', () => toggleColorMode('monochrome'));
  elColorColored.addEventListener('click', () => toggleColorMode('colored'));

  const elGraphBody = document.querySelector<HTMLElement>('#git-graph-body');
  const url = new URL(window.location.href);
  const params = url.searchParams;
  const loadGitGraph = async () => {
    const queryString = params.toString();
    const ajaxUrl = new URL(url);
    ajaxUrl.searchParams.set('div-only', 'true');
    window.history.replaceState({}, '', queryString ? `?${queryString}` : window.location.pathname);

    elGraphBody.classList.add('is-loading');
    try {
      const resp = await GET(ajaxUrl.toString());

Review comment (suggestion):
```suggestion
    window.history.replaceState(null, '', `?${params.toString()}`);
```

Don't need a state object.

Code after:
import {toggleClass} from '../utils/dom.ts';
import {GET} from '../modules/fetch.ts';
import {fomanticQuery} from '../modules/fomantic/base.ts';

export function initRepoGraphGit() {
  const graphContainer = document.querySelector<HTMLElement>('#git-graph-container');
  if (!graphContainer) return;

  const elColorMonochrome = document.querySelector<HTMLElement>('#flow-color-monochrome');
  const elColorColored = document.querySelector<HTMLElement>('#flow-color-colored');
  const toggleColorMode = (mode: 'monochrome' | 'colored') => {
    toggleClass(graphContainer, 'monochrome', mode === 'monochrome');
    toggleClass(graphContainer, 'colored', mode === 'colored');

    toggleClass(elColorMonochrome, 'active', mode === 'monochrome');
    toggleClass(elColorColored, 'active', mode === 'colored');

    const params = new URLSearchParams(window.location.search);
    params.set('mode', mode);
    window.history.replaceState(null, '', `?${params.toString()}`);
    for (const link of document.querySelectorAll('#pagination .pagination a')) {
      const href = link.getAttribute('href');
      if (!href) continue;
      const url = new URL(href, window.location.href);
      const params = url.searchParams;
      params.set('mode', mode);
      url.search = `?${params.toString()}`;
      link.setAttribute('href', url.href);
    }
  };
  elColorMonochrome.addEventListener('click', () => toggleColorMode('monochrome'));
  elColorColored.addEventListener('click', () => toggleColorMode('colored'));

  const elGraphBody = document.querySelector<HTMLElement>('#git-graph-body');
  const url = new URL(window.location.href);
  const params = url.searchParams;
  const loadGitGraph = async () => {
    const queryString = params.toString();
    const ajaxUrl = new URL(url);
    ajaxUrl.searchParams.set('div-only', 'true');
    window.history.replaceState(null, '', queryString ? `?${queryString}` : window.location.pathname);

    elGraphBody.classList.add('is-loading');
    try {
      const resp = await GET(ajaxUrl.toString());