<commit_before>
import React, { Component } from 'react'
import classnames from 'classnames'
import axios from 'axios'

import List from './list'
import Manage from './manage'
import CreateModal from './modal'

import ContentWrapper from '~/components/Layout/ContentWrapper'
import PageHeader from '~/components/Layout/PageHeader'

const style = require('./style.scss')

export default class ContentView extends Component {
  constructor(props) {
    super(props)

    this.state = {
      loading: true,
      showModal: false
    }
  }

  componentDidMount() {
    this.fetchAllCategoriesMessages()
    .then(::this.fetchCategories)
    .then(() => {
      return this.fetchSchema('trivia')
    })
    .then(() => {
      this.setState({
        loading: false
      })  
    })
  }

  fetchCategories() {
    return axios.get('/content/categories')
    .then(({ data }) => {
      this.setState({
        categories: data
      })
    })
  }

  fetchAllCategoriesMessages() {
    return axios.get('/content/categories/all/items')
    .then(({ data }) => {
      this.setState({
        messages: data
      })
    })
  }

  fetchCategoryMessages(id) {
    return axios.get('/content/categories/' + id + '/items')
    .then(({ data }) => {
      this.setState({
        messages: data
      })
    })
  }

  fetchSchema(id) {
    return axios.get('/content/categories/' + id + '/schema')
    .then(({ data }) => {
      this.setState({
        schema: data
      })
    })
  }

  createItem(data, id) {
    return axios.post('/content/categories/' + id + '/items', { formData: data })
    .then(res => {
      console.log('POST: New item created...')
      console.log(res)
    })
  }

  deleteItems(data) {
    return axios.post('/content/categories/all/bulk_delete', data)
    .then(res => {
      console.log('DELETE: Array of ids deleted...')
      console.log(res)
    })
  } 

  handleToggleModal() {
    this.setState({
      showModal: !this.state.showModal
    })
  }

  handleCreate(data) {
    this.createItem(data, this.state.selectedId)
    .then(() => { return this.fetchCategoryMessages(this.state.selectedId) })
    .then(() => { this.setState({ showModal: false } ) })
  }

  handleCategorySelected(id) {
    this.fetchCategoryMessages(id)
    .then(() => { this.setState({ selectedId: id }) })    
  }

  handleDeleteSelected(ids) {
    this.deleteItems(ids)
    .then(() => { return this.fetchCategoryMessages(this.state.selectedId) })
  }

  handleRefresh() {
    this.fetchCategoryMessages(this.state.selectedId || 'all')
  }
 
  render() {
    if (this.state.loading) {
      return null
    }

    const classNames = classnames({
      [style.content]: true,
      'bp-content': true
    })

    return (
      <ContentWrapper>
        <PageHeader><span>Content Manager</span></PageHeader>
        <table className={classNames}>
          <tbody>
            <tr>
              <td style={{ 'width': '20%' }}>
                <List
                  categories={this.state.categories || []}
                  selectedId={this.state.selectedId || 'all'}
                  handleAdd={::this.handleToggleModal}
                  handleCategorySelected={::this.handleCategorySelected} />
              </td>
              <td style={{ 'width': '80%' }}>
                <Manage 
                  messages={this.state.messages || []}
                  handleRefresh={::this.handleRefresh}
                  handleDeleteSelected={::this.handleDeleteSelected} />
              </td>
            </tr>
          </tbody>
        </table>
        <CreateModal 
          show={this.state.showModal}
          schema={(this.state.schema && this.state.schema.json) || {}}
          uiSchema={(this.state.schema && this.state.schema.ui) || {}}
          handleCreate={::this.handleCreate}
          handleClose={::this.handleToggleModal} />
      </ContentWrapper>
    )
  }
}
<commit_msg>Fetch categories<commit_after>
import React, { Component } from 'react'
import classnames from 'classnames'
import axios from 'axios'

import List from './list'
import Manage from './manage'
import CreateModal from './modal'

import ContentWrapper from '~/components/Layout/ContentWrapper'
import PageHeader from '~/components/Layout/PageHeader'

const style = require('./style.scss')

export default class ContentView extends Component {
  constructor(props) {
    super(props)

    this.state = {
      loading: true,
      showModal: false
    }
  }

  componentDidMount() {
    this.fetchAllCategoriesMessages()
    .then(::this.fetchCategories)
    .then(() => {
      return this.fetchSchema('trivia')
    })
    .then(() => {
      this.setState({
        loading: false
      })  
    })
  }

  fetchCategories() {
    return axios.get('/content/categories')
    .then(({ data }) => {
      this.setState({
        categories: data
      })
    })
  }

  fetchAllCategoriesMessages() {
    return axios.get('/content/categories/all/items')
    .then(({ data }) => {
      this.setState({
        messages: data
      })
    })
  }

  fetchCategoryMessages(id) {
    return axios.get('/content/categories/' + id + '/items')
    .then(({ data }) => {
      this.setState({
        messages: data
      })
    })
  }

  fetchSchema(id) {
    return axios.get('/content/categories/' + id + '/schema')
    .then(({ data }) => {
      this.setState({
        schema: data
      })
    })
  }

  createItem(data, id) {
    return axios.post('/content/categories/' + id + '/items', { formData: data })
    .then(res => {
      console.log('POST: New item created...')
      console.log(res)
    })
  }

  deleteItems(data) {
    return axios.post('/content/categories/all/bulk_delete', data)
    .then(res => {
      console.log('DELETE: Array of ids deleted...')
      console.log(res)
    })
  } 

  handleToggleModal() {
    this.setState({
      showModal: !this.state.showModal
    })
  }

  handleCreate(data) {
    this.createItem(data, this.state.selectedId)
    .then(::this.fetchCategories)
    .then(() => { return this.fetchCategoryMessages(this.state.selectedId) })
    .then(() => { this.setState({ showModal: false } ) })
  }

  handleCategorySelected(id) {
    this.fetchCategoryMessages(id)
    .then(() => { this.setState({ selectedId: id }) })    
  }

  handleDeleteSelected(ids) {
    this.deleteItems(ids)
    .then(::this.fetchCategories)
    .then(() => { return this.fetchCategoryMessages(this.state.selectedId) })
  }

  handleRefresh() {
    this.fetchCategoryMessages(this.state.selectedId || 'all')
  }
 
  render() {
    if (this.state.loading) {
      return null
    }

    const classNames = classnames({
      [style.content]: true,
      'bp-content': true
    })

    return (
      <ContentWrapper>
        <PageHeader><span>Content Manager</span></PageHeader>
        <table className={classNames}>
          <tbody>
            <tr>
              <td style={{ 'width': '20%' }}>
                <List
                  categories={this.state.categories || []}
                  selectedId={this.state.selectedId || 'all'}
                  handleAdd={::this.handleToggleModal}
                  handleCategorySelected={::this.handleCategorySelected} />
              </td>
              <td style={{ 'width': '80%' }}>
                <Manage 
                  messages={this.state.messages || []}
                  handleRefresh={::this.handleRefresh}
                  handleDeleteSelected={::this.handleDeleteSelected} />
              </td>
            </tr>
          </tbody>
        </table>
        <CreateModal 
          show={this.state.showModal}
          schema={(this.state.schema && this.state.schema.json) || {}}
          uiSchema={(this.state.schema && this.state.schema.ui) || {}}
          handleCreate={::this.handleCreate}
          handleClose={::this.handleToggleModal} />
      </ContentWrapper>
    )
  }
}

{'fraction_non_alphanumeric': 0.15615081883965976, 'fraction_numerical': 0.001015615081883966, 'mean_word_length': 2.1920583468395463, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 65, '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': '4915840', 'n_tokens_mistral': 2372, 'n_tokens_neox': 2313, 'n_words': 405}