<commit_before>var React = require('react');
var Router = require('react-router');

var HomeView = require('./views/HomeView.jsx');
var OverView = require('./views/Overview.jsx');
var DetailView = require('./views/DetailView.jsx');
var UserView = require('./views/UserView.jsx');
var TestView = require('./views/TestView.jsx');
var SubmitView = require('./views/SubmitView.jsx');
var Link = Router.Link;
var OverView = require('./views/Overview.jsx');
var DetailView = require('./views/DetailView.jsx');
var LoginView = require('./views/loginView.jsx');

var Router = require('react-router');
var RouteHandler = Router.RouteHandler;

var DefaultRoute = Router.DefaultRoute;
var Route = Router.Route;
var RouteHandler = Router.RouteHandler;

var mui = require('material-ui');
var ThemeManager = new mui.Styles.ThemeManager();
var AppBar = mui.AppBar,
    LeftNav = mui.LeftNav,
    List = mui.List,
    ListItem = mui.ListItem, 
    FlatButton = mui.FlatButton,
    TextField = mui.TextField,
    RaisedButton = mui.RaisedButton,
    IconButton = mui.IconButton,
    IconMenu = mui.IconMenu;
    FontIcon = mui.FontIcon;

var Menu = require('material-ui/lib/menus/menu'),
    MenuItem = require('material-ui/lib/menus/menu-item'); 

// var MoreVertIcon = require('./svg-icons/navigation/more-vert');


var App = React.createClass({
  childContextTypes: {
    muiTheme: React.PropTypes.object
  },
  getChildContext: function() {
    return {
      muiTheme: ThemeManager.getCurrentTheme()
    };
  },
  getInitialState: function(){
    return {
      questions: [],
      user: undefined
    };
  },

  loadAllQuestions: function(){
    $.ajax({
      url: window.location.origin + '/questions',
      method: 'GET',
      dataType: 'json',
      success: function(data){
      //   // this probably should be sorted by difficulty
      //   data.sort(function(a, b){
      //     return a.qNumber - b.qNumber;
      //   });
      //   this.setState({questions: data});
      // }.bind(this),
        console.log(data);
        if(data === 'not logged in'){
          React.render(React.createElement(loginView), document.body);
        }else{
          data.sort(function(a, b){
            return a.qNumber - b.qNumber;
          });
          this.setState({questions: data});
          }
        }.bind(this),
      error: function(xhr, status, err){
        console.error(xhr, status, err.message);
      }
    });
  },

  // expect to get user data from route /user
  getUserInfo: function() {
    var that = this;
    console.log('Get userinfo executed.');
     $.ajax({
      url: window.location.origin + '/user',
      method: 'GET',
      dataType: 'json',
      success: function(data){
        console.log('user', data);
        that.setState({user: data});
      }.bind(this),
      error: function(xhr, status, err){
        console.error(xhr, status, err.message);
        this.setState({user: undefined});
      }.bind(this)

    });
  },

  // Fetch initial data in componentDidMount. 
  // When the response arrives, store the data in state, triggering a render to update your UI.
  // https://facebook.github.io/react/tips/initial-ajax.html
  componentDidMount: function(){
    this.loadAllQuestions();<commit_msg>(questions) changed ajax requests in app.jsx<commit_after>var React = require('react');
var Router = require('react-router');

var HomeView = require('./views/HomeView.jsx');
var OverView = require('./views/Overview.jsx');
var DetailView = require('./views/DetailView.jsx');
var UserView = require('./views/UserView.jsx');
var TestView = require('./views/TestView.jsx');
var SubmitView = require('./views/SubmitView.jsx');
var Link = Router.Link;
var OverView = require('./views/Overview.jsx');
var DetailView = require('./views/DetailView.jsx');
var LoginView = require('./views/loginView.jsx');

var Router = require('react-router');
var RouteHandler = Router.RouteHandler;

var DefaultRoute = Router.DefaultRoute;
var Route = Router.Route;
var RouteHandler = Router.RouteHandler;

var mui = require('material-ui');
var ThemeManager = new mui.Styles.ThemeManager();
var AppBar = mui.AppBar,
    LeftNav = mui.LeftNav,
    List = mui.List,
    ListItem = mui.ListItem, 
    FlatButton = mui.FlatButton,
    TextField = mui.TextField,
    RaisedButton = mui.RaisedButton,
    IconButton = mui.IconButton,
    IconMenu = mui.IconMenu;
    FontIcon = mui.FontIcon;

var Menu = require('material-ui/lib/menus/menu'),
    MenuItem = require('material-ui/lib/menus/menu-item'); 

// var MoreVertIcon = require('./svg-icons/navigation/more-vert');


var App = React.createClass({
  childContextTypes: {
    muiTheme: React.PropTypes.object
  },
  getChildContext: function() {
    return {
      muiTheme: ThemeManager.getCurrentTheme()
    };
  },
  getInitialState: function(){
    return {
      questions: [],
      user: undefined
    };
  },

  loadAllQuestions: function(){
    var that = this;  
    $.ajax({
      url: window.location.origin + '/questions',
      method: 'GET',
      dataType: 'json',
      success: function(data){
        console.log(data);
        if(data === 'not logged in'){
          React.render(React.createElement(loginView), document.body);
        }else{
          data.sort(function(a, b){
            return a.qNumber - b.qNumber;
          });
          that.setState({questions: data});
          }
        },
      error: function(xhr, status, err){
        console.error(xhr, status, err.message);
      }
    });
  },

  // expect to get user data from route /user
  getUserInfo: function() {
    var that = this;
    console.log('Get userinfo executed.');
     $.ajax({
      url: window.location.origin + '/user',
      method: 'GET',
      dataType: 'json',
      success: function(data){
        console.log('user', data);
        that.setState({user: data});
        console.log(that.state(user));
      },
      error: function(xhr, status, err){
        console.error(xhr, status, err.message);
        that.setState({user: 'error'});
      }
    });
  },

  // Fetch initial data in componentDidMount. 
  // When the response arrives, store the data in state, triggering a render to update your UI.
  // https://facebook.github.io/react/tips/initial-ajax.html
  componentDidMount: function(){
    this.loadAllQuestions();
{'fraction_non_alphanumeric': 0.15167380612406792, 'fraction_numerical': 0.0, 'mean_word_length': 2.8722358722358723, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4395369', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1935, 'n_words': 430}