<commit_before>'use strict';

import React from 'react';
import FloatingActionButton from 'material-ui/lib/floating-action-button';
import ActionSettings from 'material-ui/lib/svg-icons/action/settings';
import FlatButton from 'material-ui/lib/flat-button';
import Dialog from 'material-ui/lib/dialog';
import SlideListEditor from './SlideListEditorComponent';
import Snackbar from 'material-ui/lib/snackbar';

require('styles//Settings.scss');

class SettingsComponent extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      dialogOpen: false,
      snackbarOpen: false,
      timeout: undefined
    };
  }

  componentDidMount() {
    const timeToWaitForDBRead = 750;

    if(this.props.slides.length === 0) {
      const timeout = setTimeout(
        () => this.setState({
          dialogOpen: true,
          timeout: undefined
        }), timeToWaitForDBRead );
      this.setState({timeout: timeout})
    }
  }

  componentWillReceiveProps(nextProps) {
    clearTimeout(this.state.timeout);
  }

  onSave = (slide) => {
    this.props.actionAddSlide(slide);
  }

  onUpdate = (id, slide) => {
    this.props.actionEditSlide(id, slide);
  }

  onDelete = (id) => {
    this.props.actionDeleteSlide(id);
  }

  openDialog = () => {
    this.setState({
      dialogOpen: true
    })
  }

  closeDialog = () => {
    if(this.props.slides.length !== 0) {
      this.setState({
        dialogOpen: false
      })
    }
    else {
      this.openSnackbar();
    }
  }

  openSnackbar = () => {
    this.setState({
      snackbarOpen: true
    })
  }

  closeSnackbar = () => {
    this.setState({
      snackbarOpen: false
    })
  }

  render() {
    const actions = [
      <FlatButton
        label="Close"
        primary={true}
        onTouchTap={this.closeDialog}
      />
    ];

    return (
      <div className="settings-component">
        <FloatingActionButton
          mini={true}
          onTouchTap={this.openDialog}>
          <ActionSettings />
        </FloatingActionButton>

        <Dialog
          title="Settings"
          actions={actions}
          modal={this.props.slides.length === 0}
          open={this.state.dialogOpen}
          onRequestClose={this.closeDialog}
          autoScrollBodyContent={true}
        >
          <SlideList
            slides={this.props.slides}
            onDelete={this.onDelete}
            onUpdate={this.onUpdate}
            onSave={this.onSave}/><commit_msg>Renames the SlideList component to a more apropriate name<commit_after>'use strict';

import React from 'react';
import FloatingActionButton from 'material-ui/lib/floating-action-button';
import ActionSettings from 'material-ui/lib/svg-icons/action/settings';
import FlatButton from 'material-ui/lib/flat-button';
import Dialog from 'material-ui/lib/dialog';
import SlideListEditor from './SlideListEditorComponent';
import Snackbar from 'material-ui/lib/snackbar';

require('styles//Settings.scss');

class SettingsComponent extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      dialogOpen: false,
      snackbarOpen: false,
      timeout: undefined
    };
  }

  componentDidMount() {
    const timeToWaitForDBRead = 750;

    if(this.props.slides.length === 0) {
      const timeout = setTimeout(
        () => this.setState({
          dialogOpen: true,
          timeout: undefined
        }), timeToWaitForDBRead );
      this.setState({timeout: timeout})
    }
  }

  componentWillReceiveProps(nextProps) {
    clearTimeout(this.state.timeout);
  }

  onSave = (slide) => {
    this.props.actionAddSlide(slide);
  }

  onUpdate = (id, slide) => {
    this.props.actionEditSlide(id, slide);
  }

  onDelete = (id) => {
    this.props.actionDeleteSlide(id);
  }

  openDialog = () => {
    this.setState({
      dialogOpen: true
    })
  }

  closeDialog = () => {
    if(this.props.slides.length !== 0) {
      this.setState({
        dialogOpen: false
      })
    }
    else {
      this.openSnackbar();
    }
  }

  openSnackbar = () => {
    this.setState({
      snackbarOpen: true
    })
  }

  closeSnackbar = () => {
    this.setState({
      snackbarOpen: false
    })
  }

  render() {
    const actions = [
      <FlatButton
        label="Close"
        primary={true}
        onTouchTap={this.closeDialog}
      />
    ];

    return (
      <div className="settings-component">
        <FloatingActionButton
          mini={true}
          onTouchTap={this.openDialog}>
          <ActionSettings />
        </FloatingActionButton>

        <Dialog
          title="Settings"
          actions={actions}
          modal={this.props.slides.length === 0}
          open={this.state.dialogOpen}
          onRequestClose={this.closeDialog}
          autoScrollBodyContent={true}
        >
          <SlideListEditor
            slides={this.props.slides}
            onDelete={this.onDelete}
            onUpdate={this.onUpdate}
            onSave={this.onSave}/>
{'fraction_non_alphanumeric': 0.12921348314606743, 'fraction_numerical': 0.002407704654895666, 'mean_word_length': 2.347884486232371, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, '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': '348004', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1519, 'n_words': 251}