<commit_before>import React, { Component } from 'react';
import Thread from './Thread';
import ThreadList from './ThreadList';
import ThreadSubmitForm from './ThreadSubmitForm';
import './styles/Board.css';

class Board extends Component {
  constructor(props) {
    super(props);

    this.state = {
      info: {
        name: 'Loading',
        abbreviation: props.params.abbreviation,
        description: ''
      }
    };
  }

  componentDidMount() {
    // fetch initial state when the Board component is used for the first time
    this.fetchBoardInfo();
  }

  componentDidUpdate(oldProps) {
    // user probably switched from a board to another board, ignore if old board === this board
    if (oldProps.params.abbreviation !== this.props.params.abbreviation)
      this.fetchBoardInfo();
  }

  fetchBoardInfo() {
    fetch('/api/boards/' + this.props.params.abbreviation).then((data, err) => {
      if (err) {
        // TODO: UI for API errors
        console.error(this.constructor.name, err);
        return;
      }
      data.json().then(jsonData => {
        console.log("Board::fetchBoardInfo", "Got board info!", jsonData);
        if (!jsonData || jsonData.status !== 'Success') {
          throw new Error('Parsed data was bad! ' + data);
        }
        this.setState({ info: jsonData.data });
      });
    })
      .catch(err => {
        console.error("Board::fetchBoardInfo", 'Error while fetching posts!', err);
      });
  }

  getChildToShow() {
    // yes, I know what the ?: is but this is more readable
    if (this.props.params.threadId) {
      // we are in the `/boards/b/:threadId` path
      return (<Thread abbreviation={this.props.params.abbreviation} id={this.props.params.threadId} />);
    } else {
      // we are in the `boards/b/` path
      return (<ThreadList abbreviation={this.props.params.abbreviation} />);
    }
  }

  submitNewThread(formData) {
    formData.board = this.props.params.abbreviation;
    if (this.props.params.threadId) {
      // set the thread we're replying to if we're in an existing thread,
      // otherwise we're creating a new thread
      formData.topic_id = this.props.params.threadId;
    }

    fetch('/api/boards/' + this.props.params.abbreviation + '/posts/', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8',
        'Accept': 'application/json'
      },
      body: JSON.stringify(formData)
    })
      .then((data, err) => {
        console.log("Board::submitNewThread", data);
      });
  }

  render() {
    console.log("Board props", this.props);
    let name = this.state.info.name;<commit_msg>Add reload after new post<commit_after>import React, { Component } from 'react';
import Thread from './Thread';
import ThreadList from './ThreadList';
import ThreadSubmitForm from './ThreadSubmitForm';
import './styles/Board.css';

class Board extends Component {
  constructor(props) {
    super(props);

    this.state = {
      info: {
        name: 'Loading',
        abbreviation: props.params.abbreviation,
        description: ''
      }
    };
  }

  componentDidMount() {
    // fetch initial state when the Board component is used for the first time
    this.fetchBoardInfo();
  }

  componentDidUpdate(oldProps) {
    // user probably switched from a board to another board, ignore if old board === this board
    if (oldProps.params.abbreviation !== this.props.params.abbreviation)
      this.fetchBoardInfo();
  }

  fetchBoardInfo() {
    fetch('/api/boards/' + this.props.params.abbreviation).then((data, err) => {
      if (err) {
        // TODO: UI for API errors
        console.error(this.constructor.name, err);
        return;
      }
      data.json().then(jsonData => {
        console.log("Board::fetchBoardInfo", "Got board info!", jsonData);
        if (!jsonData || jsonData.status !== 'Success') {
          throw new Error('Parsed data was bad! ' + data);
        }
        this.setState({ info: jsonData.data });
      });
    })
      .catch(err => {
        console.error("Board::fetchBoardInfo", 'Error while fetching posts!', err);
      });
  }

  getChildToShow() {
    // yes, I know what the ?: is but this is more readable
    if (this.props.params.threadId) {
      // we are in the `/boards/b/:threadId` path
      return (<Thread abbreviation={this.props.params.abbreviation} id={this.props.params.threadId} />);
    } else {
      // we are in the `boards/b/` path
      return (<ThreadList abbreviation={this.props.params.abbreviation} />);
    }
  }

  submitNewThread(formData) {
    formData.board = this.props.params.abbreviation;
    if (this.props.params.threadId) {
      // set the thread we're replying to if we're in an existing thread,
      // otherwise we're creating a new thread
      formData.topic_id = this.props.params.threadId;
    }

    fetch('/api/boards/' + this.props.params.abbreviation + '/posts/', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8',
        'Accept': 'application/json'
      },
      body: JSON.stringify(formData)
    })
      .then((data, err) => {
        console.log("Board::submitNewThread", data);
        window.location.reload();
      });
  }

  render() {
    console.log("Board props", this.props);
    let name = this.state.info.name;
{'fraction_non_alphanumeric': 0.14444027047332833, 'fraction_numerical': 0.0003756574004507889, 'mean_word_length': 2.583445491251682, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '5644187', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1575, 'n_words': 386}