<commit_before>import { connect } from 'react-redux';
import React from 'react';
import PropTypes from 'prop-types';

class ErrorCatcher extends React.Component {
  static propTypes = {
    children: PropTypes.node,
    erroredAction: PropTypes.shape({}),
    reducingError: PropTypes.instanceOf(Error),
    state: PropTypes.shape({}),
  }

  state = {};

  componentDidCatch(error, info) {
    this.setState({ error, info });
  }

  render() {
    if (!this.state.error && !this.props.reducingError) {
      return this.props.children;
    }

    const debugData = [
      ['URL', window.location.href],
      ['Errored Action', this.props.erroredAction],
      ['Reducing Error', this.props.reducingError && this.props.reducingError.stack],
      ['Component Error', this.state.error && this.state.error.stack],
      ['Component Stack', this.state.info && this.state.info.componentStack],
      ['App State', JSON.stringify(this.props.state, null, 2)],
      ['Local Storage', Object
        .keys(localStorage)
        .map(key => `${key}\n${localStorage.getItem(key)}`)
        .join('\n----------------\n'),
      ],
    ];

    return (
      <div style={{ padding: '10px' }}>
        <h1>Ups!</h1>
        <p>
          Voľačo nedobre sa udialo.
        </p>
        <p>
          Prosíme Ťa, <a href="https://github.com/FreemapSlovakia/freemap-v3-react/issues/new" target="_blank" rel="noopener noreferrer">nahlás nám chybu</a>,
          prípadne nám ju pošli na <a href="mailto:<EMAIL>?subject=Nahlásenie%20chyby%20na%20www.freemap.sk"><EMAIL></a>.
          Nezabudni, prosím, priložiť krátky popis, ako sa ti podarilo vyvolať chybu a nižšieuvedené dáta pre ladenie.
        </p>
        <p>
          Ďakujeme.
        </p>
        Akcie:
        <ul>
          <li><a href="">Znovu načítať stránku</a></li>
          <li><a href="/">Znovu načítať úvodnú stránku</a></li>
        </ul>
        <h2>Dáta pre ladenie</h2>
        <pre>
          {
            debugData
              .filter(([, x]) => x)
              .map(([title, detail]) => `================\n${title}\n================\n${detail}`)
              .join('\n')
          }
        </pre>
      </div>
    );
  }
}

export default connect(
  state => ({
    state,
    erroredAction: state.main.erroredAction,
    reducingError: state.main.reducingError,
  }),
)(ErrorCatcher);<commit_msg>simplified code<commit_after>import { connect } from 'react-redux';
import React from 'react';
import PropTypes from 'prop-types';

class ErrorCatcher extends React.Component {
  static propTypes = {
    children: PropTypes.node,
    erroredAction: PropTypes.shape({}),
    reducingError: PropTypes.instanceOf(Error),
    state: PropTypes.shape({}),
  }

  state = {};

  componentDidCatch(error, info) {
    this.setState({ error, info });
  }

  render() {
    if (!this.state.error && !this.props.reducingError) {
      return this.props.children;
    }

    return (
      <div style={{ padding: '10px' }}>
        <h1>Ups!</h1>
        <p>
          Voľačo nedobre sa udialo.
        </p>
        <p>
          Prosíme Ťa, <a href="https://github.com/FreemapSlovakia/freemap-v3-react/issues/new" target="_blank" rel="noopener noreferrer">nahlás nám chybu</a>,
          prípadne nám ju pošli na <a href="mailto:<EMAIL>?subject=Nahlásenie%20chyby%20na%20www.freemap.sk"><EMAIL></a>.
          Nezabudni, prosím, priložiť krátky popis, ako sa ti podarilo vyvolať chybu a nižšieuvedené dáta pre ladenie.
        </p>
        <p>
          Ďakujeme.
        </p>
        Akcie:
        <ul>
          <li><a href="">Znovu načítať stránku</a></li>
          <li><a href="/">Znovu načítať úvodnú stránku</a></li>
        </ul>
        <h2>Dáta pre ladenie</h2>
        <pre>
          {
            [
              ['URL', window.location.href],
              ['Errored Action', this.props.erroredAction],
              ['Reducing Error', this.props.reducingError && this.props.reducingError.stack],
              ['Component Error', this.state.error && this.state.error.stack],
              ['Component Stack', this.state.info && this.state.info.componentStack],
              ['App State', JSON.stringify(this.props.state, null, 2)],
              ['Local Storage', Object
                .keys(localStorage)
                .map(key => `${key}\n${localStorage.getItem(key)}`)
                .join('\n----------------\n'),
              ],
            ]
              .filter(([, x]) => x)
              .map(([title, detail]) => `================\n${title}\n================\n${detail}`)
              .join('\n')
          }
        </pre>
      </div>
    );
  }
}

export default connect(
  state => ({
    state,
    erroredAction: state.main.erroredAction,
    reducingError: state.main.reducingError,
  }),
)(ErrorCatcher);
{'fraction_non_alphanumeric': 0.17700957934194086, 'fraction_numerical': 0.0058309037900874635, 'mean_word_length': 2.1956087824351296, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 71, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '338349', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1618, 'n_words': 305}