<commit_before>'use strict';

const React = require('react');
const Card = require('react-material/components/Card');
const List = require('react-material/components/List');
const ListItem = require('react-material/components/ListItem');
const AppBar = require('react-material/components/AppBar');
const Overlay = require('react-material/components/Overlay');
const SideNavigation = require('react-material/components/SideNavigation');
const Button = require('react-material/components/Button');
const TextField = require('react-material/components/TextField');

const styles = require('./styles');

const TopBar = React.createClass({
  getInitialState: function(){
    return {
      show: false,
      chooserType: '',
      projectName: ''
    };
  },
  showSidebar: function(){
    this.setState({
      show: true
    });
  },
  hideSidebar: function(){
    this.setState({
      show: false,
      chooserType: ''
    });
  },
  showNewChooser: function(){
    this.setState({
      chooserType: 'new'
    });
  },
  showOpenChooser: function(){
    this.setState({
      chooserType: 'open'
    });
  },
  hideChooser: function(){
    this.setState({
      chooserType: ''
    });
  },

  updateName: function(evt){
    evt.stopPropagation();
    evt.preventDefault();

    this.setState({
      projectName: evt.target.value
    });
  },

  openDir: function(name){
    this.setState({
      projectName: name
    }, this.changeProject);
  },

  changeProject: function(){
    const space = this.props.app.workspace;

    space.changeDir(this.state.projectName, () => {
      // TODO: handle error
      this.setState({ projectName: '' }, this.hideSidebar)
    });
  },

  renderChooser: function(){
    const space = this.props.app.workspace;

    if(!this.state.chooserType){
      return null;
    }

    if(this.state.chooserType === 'new'){
      return (
        <Card styles={styles.chooser} title="New Project">
          <TextField
            placeHolder="Enter Project Name"
            floatingLabel
            styles={styles.textField}
            value={this.state.projectName}
            onChange={this.updateName} />
          <div style={styles.buttonGroup}>
            <Button raised onClick={this.hideChooser}>Cancel</Button>
            <Button raised styles={styles.createButton} onClick={this.changeProject}>Create Project</Button>
          </div>
        </Card>
      )
    }

    if(this.state.chooserType === 'open'){
      return (
        <Card styles={styles.chooser} title="Open Project">
          <List>
            {space.projects.map((dirname) => (
              <ListItem icon="folder" key={dirname} onClick={() => this.openDir(dirname)}>
                {dirname}<commit_msg>whitespace cleanup<commit_after>'use strict';

const React = require('react');
const Card = require('react-material/components/Card');
const List = require('react-material/components/List');
const ListItem = require('react-material/components/ListItem');
const AppBar = require('react-material/components/AppBar');
const Overlay = require('react-material/components/Overlay');
const SideNavigation = require('react-material/components/SideNavigation');
const Button = require('react-material/components/Button');
const TextField = require('react-material/components/TextField');

const styles = require('./styles');

const TopBar = React.createClass({
  getInitialState: function(){
    return {
      show: false,
      chooserType: '',
      projectName: ''
    };
  },
  showSidebar: function(){
    this.setState({
      show: true
    });
  },
  hideSidebar: function(){
    this.setState({
      show: false,
      chooserType: ''
    });
  },
  showNewChooser: function(){
    this.setState({
      chooserType: 'new'
    });
  },
  showOpenChooser: function(){
    this.setState({
      chooserType: 'open'
    });
  },
  hideChooser: function(){
    this.setState({
      chooserType: ''
    });
  },
  updateName: function(evt){
    evt.stopPropagation();
    evt.preventDefault();

    this.setState({
      projectName: evt.target.value
    });
  },
  openDir: function(name){
    this.setState({
      projectName: name
    }, this.changeProject);
  },
  changeProject: function(){
    const space = this.props.app.workspace;

    space.changeDir(this.state.projectName, () => {
      // TODO: handle error
      this.setState({ projectName: '' }, this.hideSidebar)
    });
  },
  renderChooser: function(){
    const space = this.props.app.workspace;

    if(!this.state.chooserType){
      return null;
    }

    if(this.state.chooserType === 'new'){
      return (
        <Card styles={styles.chooser} title="New Project">
          <TextField
            placeHolder="Enter Project Name"
            floatingLabel
            styles={styles.textField}
            value={this.state.projectName}
            onChange={this.updateName} />
          <div style={styles.buttonGroup}>
            <Button raised onClick={this.hideChooser}>Cancel</Button>
            <Button raised styles={styles.createButton} onClick={this.changeProject}>Create Project</Button>
          </div>
        </Card>
      )
    }

    if(this.state.chooserType === 'open'){
      return (
        <Card styles={styles.chooser} title="Open Project">
          <List>
            {space.projects.map((dirname) => (
              <ListItem icon="folder" key={dirname} onClick={() => this.openDir(dirname)}>
                {dirname}
{'fraction_non_alphanumeric': 0.14944005874793465, 'fraction_numerical': 0.0, 'mean_word_length': 2.788595271210014, 'pattern_counts': {'":': 0, '<': 27, '<?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': '7291219', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1564, 'n_words': 284}