<commit_before>import React, { useState } from "react";
import { Link, useRouteMatch } from "react-router-dom";
import styles from "./panels.module.scss";
import encodeCategories from "./encodeCategories";

export default function({ categoriesList }) {
  const [chosenCategories, setChosenCategories] = useState([]);
  const decodedCategories = encodeCategories(chosenCategories);
  const list = categoriesList.map((c, i) => (
    <li
      key={i}
      onClick={() => {
        const found = chosenCategories.findIndex(ch => ch.value === c);
        if (found !== -1) {
          chosenCategories.splice(found, 1);
          setChosenCategories([...chosenCategories]);
        } else {
          setChosenCategories([...chosenCategories, { value: c, i }]);
        }
      }}
      className={`list-group-item ${styles["panel-item"]} ${
        chosenCategories.find(ch => ch.value === c)
          ? styles["panel-item-active"]
          : ""
      }`}
    >
      {c}
    </li>
  ));

  return (
    <>
      <div className="row">
        <div className="col-12">
          <h4>
            Choose category
            <button
              type="button"
              className="btn btn-info float-right"
              onClick={() => {
                if (categoriesList.length === chosenCategories.length) {
                  setChosenCategories([]);
                } else {
                  setChosenCategories(
                    categoriesList.map((c, i) => ({ value: c, i }))
                  );
                }
              }}
            >
              {categoriesList.length === chosenCategories.length
                ? "Deselect all"
                : "Select all"}
            </button>
          </h4>
          <hr />
        </div>
      </div>

      <div className="row justify-content-center">
        <div className="col-5" style={{ padding: "0px" }}>
          <ul className="list-group list-group-flush">
            {list.slice(0, list.length / 2)}
          </ul>
        </div>
        <div className="col-5" style={{ padding: "0px" }}>
          <ul className="list-group list-group-flush">
            {list.slice(list.length / 2)}
          </ul>
        </div>
        <div className="col-12">
          <hr />
          <button type="button" className="btn btn-secondary float-left">
            Ran away
          </button>
          {decodedCategories === 0 ? null : (
            <Link to={`${useRouteMatch().path}/game/${decodedCategories}`}>
              <button
                type="button"
                className="btn btn-success btn-lg float-right"
              >
                Fight
              </button>
            </Link>
          )}
        </div>
      </div>
    </>
  );
}<commit_msg>fix react router hook error<commit_after>import React, { useState } from "react";
import { Link, useRouteMatch } from "react-router-dom";
import styles from "./panels.module.scss";
import encodeCategories from "./encodeCategories";

export default function({ categoriesList }) {
  const [chosenCategories, setChosenCategories] = useState([]);
  const decodedCategories = encodeCategories(chosenCategories);
  const list = categoriesList.map((c, i) => (
    <li
      key={i}
      onClick={() => {
        const found = chosenCategories.findIndex(ch => ch.value === c);
        if (found !== -1) {
          chosenCategories.splice(found, 1);
          setChosenCategories([...chosenCategories]);
        } else {
          setChosenCategories([...chosenCategories, { value: c, i }]);
        }
      }}
      className={`list-group-item ${styles["panel-item"]} ${
        chosenCategories.find(ch => ch.value === c)
          ? styles["panel-item-active"]
          : ""
      }`}
    >
      {c}
    </li>
  ));
  const relPath = useRouteMatch().path;

  return (
    <>
      <div className="row">
        <div className="col-12">
          <h4>
            Choose category
            <button
              type="button"
              className="btn btn-info float-right"
              onClick={() => {
                if (categoriesList.length === chosenCategories.length) {
                  setChosenCategories([]);
                } else {
                  setChosenCategories(
                    categoriesList.map((c, i) => ({ value: c, i }))
                  );
                }
              }}
            >
              {categoriesList.length === chosenCategories.length
                ? "Deselect all"
                : "Select all"}
            </button>
          </h4>
          <hr />
        </div>
      </div>

      <div className="row justify-content-center">
        <div className="col-5" style={{ padding: "0px" }}>
          <ul className="list-group list-group-flush">
            {list.slice(0, list.length / 2)}
          </ul>
        </div>
        <div className="col-5" style={{ padding: "0px" }}>
          <ul className="list-group list-group-flush">
            {list.slice(list.length / 2)}
          </ul>
        </div>
        <div className="col-12">
          <hr />
          <Link to="">
            <button type="button" className="btn btn-secondary float-left">
              Ran away
            </button>
          </Link>
          {decodedCategories === 0 ? null : (
            <Link to={`${relPath}/game/${decodedCategories}`}>
              <button
                type="button"
                className="btn btn-success btn-lg float-right"
              >
                Fight
              </button>
            </Link>
          )}
        </div>
      </div>
    </>
  );
}
{'fraction_non_alphanumeric': 0.14985693848354792, 'fraction_numerical': 0.005722460658082976, 'mean_word_length': 1.5342093339374716, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 81, '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': '6402666', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1523, 'n_words': 312}