<commit_before>"use strict";

import React from "react";

import Icon from "./Icon.js";
import MenuToggleButton from "./MenuToggleButton.js";

import SearchStore from "../stores/SearchStore.js";
import SearchActions from "../actions/SearchActions.js";

import ContainerStore from "../stores/ContainerStore.js";

function getTopState() {
  return {
    searchValue: SearchStore.getInput(),
    title: ContainerStore.getTitle(),
  };
}

export default class Top extends React.Component {
  constructor(props) {
    super(props);

    this._onChange = this._onChange.bind(this);
    this._onInputChange = this._onInputChange.bind(this);
    this._onClick = this._onClick.bind(this);
    this.state = getTopState();
  }

  componentDidMount() {
    SearchStore.addChangeListener(this._onChange);
    ContainerStore.addChangeListener(this._onChange);
  }

  componentWillUnmount() {
    SearchStore.removeChangeListener(this._onChange);
    ContainerStore.removeChangeListener(this._onChange);
  }

  render() {
    return (
      <div className="top-container">
        <MenuToggleButton />
        <span className="title">{this.state.title}</span>
        <div className="search">
          <Icon icon="search" />
          <input type="text" name="search" placeholder="Search"
            value={this.state.searchValue}
            onChange={this._onInputChange} onClick={this._onClick} />
        </div>
      </div>
    );
  }

  _onChange() {
    this.setState(getTopState());<commit_msg>Correctly restore state after hard-reload of search results.<commit_after>"use strict";

import React from "react";

import Icon from "./Icon.js";
import MenuToggleButton from "./MenuToggleButton.js";

import SearchStore from "../stores/SearchStore.js";
import SearchActions from "../actions/SearchActions.js";

import ContainerStore from "../stores/ContainerStore.js";

function getTopState() {
  return {
    searchValue: SearchStore.getInput(),
    title: ContainerStore.getTitle(),
  };
}

export default class Top extends React.Component {
  constructor(props) {
    super(props);

    this._onChange = this._onChange.bind(this);
    this._onInputChange = this._onInputChange.bind(this);
    this._onClick = this._onClick.bind(this);
    this.state = getTopState();
  }

  componentDidMount() {
    SearchStore.addChangeListener(this._onChange);
    ContainerStore.addChangeListener(this._onChange);

    if (this.state.searchValue !== "") {
      SearchActions.search(this.state.searchValue);
    }
  }

  componentWillUnmount() {
    SearchStore.removeChangeListener(this._onChange);
    ContainerStore.removeChangeListener(this._onChange);
  }

  render() {
    return (
      <div className="top-container">
        <MenuToggleButton />
        <span className="title">{this.state.title}</span>
        <div className="search">
          <Icon icon="search" />
          <input type="text" name="search" placeholder="Search"
            value={this.state.searchValue}
            onChange={this._onInputChange} onClick={this._onClick} />
        </div>
      </div>
    );
  }

  _onChange() {
    this.setState(getTopState());
{'fraction_non_alphanumeric': 0.13664, 'fraction_numerical': 0.0, 'mean_word_length': 3.4593437945791727, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '2757497', 'n_tokens_mistral': 903, 'n_tokens_neox': 894, 'n_words': 163}