<commit_before>const sendEvent = require("../../browser-send-event.js");
const page = require("./page").page;
const { AbstractShot } = require("../../../shared/shot");

let model;

exports.launch = function (m) {
  m.shots = m.shots.map((shot) => new AbstractShot(m.backend, shot.id, shot.json));
  let match = /[\?&]q=([^&]+)/.exec(location.href);
  if (match) {
    m.defaultSearch = decodeURIComponent(match[1]);
  }
  model = m;
  render();
};

function render() {
  page.render(model);
}

exports.onChangeSearch = function (query) {
  model.defaultSearch = query;
  window.history.pushState(null, "", "/shots?q=" + encodeURIComponent(query));
  refreshModel();
};

window.addEventListener("popstate", () => {
  let match = /[?&]q=([^&]*)/.exec(location.search);
  if (! match) {
    model.defaultSearch = "";
  } else {
    model.defaultSearch = decodeURIComponent(match[1]);
  }
  // FIXME: this isn't the "right" way to research the search box, but given that
  // it's an uncontrolled field it doesn't seem to be reset in this case otherwise:
  let el = document.getElementById("search");
  if (el) {
    el.value = model.defaultSearch;
  }<commit_msg>When erasing the search, change to URL to /shots instead of /shots?q=<commit_after>const sendEvent = require("../../browser-send-event.js");
const page = require("./page").page;
const { AbstractShot } = require("../../../shared/shot");

let model;

exports.launch = function (m) {
  m.shots = m.shots.map((shot) => new AbstractShot(m.backend, shot.id, shot.json));
  let match = /[\?&]q=([^&]+)/.exec(location.href);
  if (match) {
    m.defaultSearch = decodeURIComponent(match[1]);
  }
  model = m;
  render();
};

function render() {
  page.render(model);
}

exports.onChangeSearch = function (query) {
  model.defaultSearch = query;
  let url = `/shots?q=${encodeURIComponent(query)}`;
  if (! query) {
    url = "/shots";
  }
  window.history.pushState(null, "", url);
  refreshModel();
};

window.addEventListener("popstate", () => {
  let match = /[?&]q=([^&]*)/.exec(location.search);
  if (! match) {
    model.defaultSearch = "";
  } else {
    model.defaultSearch = decodeURIComponent(match[1]);
  }
  // FIXME: this isn't the "right" way to research the search box, but given that
  // it's an uncontrolled field it doesn't seem to be reset in this case otherwise:
  let el = document.getElementById("search");
  if (el) {
    el.value = model.defaultSearch;
  }
{'fraction_non_alphanumeric': 0.19022185702547248, 'fraction_numerical': 0.0016433853738701725, 'mean_word_length': 3.7098646034816247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6633521', 'n_tokens_mistral': 809, 'n_tokens_neox': 805, 'n_words': 191}