<commit_before>import GeneralNavbar from './GeneralNavbar';
import requireAuth from './requireAuth';
import React from 'react';
import Router from 'react-router';
import auth from './auth';
import Comment from './Comment';
let { Link } = Router;

export var TutorPage = requireAuth(class extends React.Component {

  constructor() {
    super();
    this.state = {
      selected: "choose a subject",
      name: "",
      tutorName: "",
      email : "",
      price: "",
      phone: "",
      classes: [],
      tutorClasses: [],
      reviews: [],
      likes: [],
      dislikes: [],
      showGrades: true,
    };

    this.handlelogout = this.handlelogout.bind(this);
  }

  handlelogout () {
    auth.logout();
  }

  componentDidMount(){
    this.reloadData();
    $.ajax({
      url: '/users/'+localStorage.user,
      type: 'GET',
      success: function (data) {
        this.setState({
          name: data.name,
        });
      }.bind(this)
    })
  }

  reloadData() {
    $.ajax({
      url: '/users/'+this.props.params.id,
      type: 'GET',
      success: function (data) {
        this.setState({
          tutorName: data.name,
          price: data.price,
          phone: data.phone,
          email: data.email,
          classes: data.classes,
          tutorClasses: data.tutorClasses,
          reviews : data.reviews,
          likes : data.likes,
          dislikes: data.dislikes,
          showGrades: data.showGrades
        });
      }.bind(this)
    })
  }

  handleClick(e) {
    this.setState({selected: e.target.innerHTML});
  }

  sendLike(value) {
    var that = this;
    $.ajax({
      url: 'like/' + this.props.params.id,
      type: 'POST',
      data: {user: localStorage.user, vote: value},
      dataType: 'json',
      success: function() {
        that.reloadData();
      }
    })
  }

  handleLike(e) {
    if(e.target.classList.contains("up")) {
      this.sendLike(1);
    }

    if(e.target.classList.contains("down")) {
      this.sendLike(-1);
    }
  }

  onButtonClick(e) {
    $.ajax({
      url: 'request/' + this.props.params.id,
      type: 'POST',
      data: {localUser:{user: localStorage.user, course: this.state.selected }},
      dataType: 'json',
      success: function() {
        alert('tutor notified');
      }
    })
  }

  handleComment(e) {
    let comment = React.findDOMNode(this.refs.comment).value;
    let that = this;
    $.ajax({
      url: 'review/' + this.props.params.id,
      type: 'POST',
      data: {user: localStorage.user, comment: comment.trim()},
      dataType: 'json',
      success: function() {
        alert('comment sent');
        React.findDOMNode(that.refs.comment).value = " ";
        that.reloadData();
      }
    })

  }

  render () {
    const left = this.state.tutorClasses.slice(0,5).map(course => {
      return(<li>{course.name}{this.state.showGrades?": "+course.grade:""}</li>);
    })
    const right = this.state.tutorClasses.slice(5).map(course => {<commit_msg>removed more alerts except tutor notified<commit_after>import GeneralNavbar from './GeneralNavbar';
import requireAuth from './requireAuth';
import React from 'react';
import Router from 'react-router';
import auth from './auth';
import Comment from './Comment';
let { Link } = Router;

export var TutorPage = requireAuth(class extends React.Component {

  constructor() {
    super();
    this.state = {
      selected: "choose a subject",
      name: "",
      tutorName: "",
      email : "",
      price: "",
      phone: "",
      classes: [],
      tutorClasses: [],
      reviews: [],
      likes: [],
      dislikes: [],
      showGrades: true,
    };

    this.handlelogout = this.handlelogout.bind(this);
  }

  handlelogout () {
    auth.logout();
  }

  componentDidMount(){
    this.reloadData();
    $.ajax({
      url: '/users/'+localStorage.user,
      type: 'GET',
      success: function (data) {
        this.setState({
          name: data.name,
        });
      }.bind(this)
    })
  }

  reloadData() {
    $.ajax({
      url: '/users/'+this.props.params.id,
      type: 'GET',
      success: function (data) {
        this.setState({
          tutorName: data.name,
          price: data.price,
          phone: data.phone,
          email: data.email,
          classes: data.classes,
          tutorClasses: data.tutorClasses,
          reviews : data.reviews,
          likes : data.likes,
          dislikes: data.dislikes,
          showGrades: data.showGrades
        });
      }.bind(this)
    })
  }

  handleClick(e) {
    this.setState({selected: e.target.innerHTML});
  }

  sendLike(value) {
    var that = this;
    $.ajax({
      url: 'like/' + this.props.params.id,
      type: 'POST',
      data: {user: localStorage.user, vote: value},
      dataType: 'json',
      success: function() {
        that.reloadData();
      }
    })
  }

  handleLike(e) {
    if(e.target.classList.contains("up")) {
      this.sendLike(1);
    }

    if(e.target.classList.contains("down")) {
      this.sendLike(-1);
    }
  }

  onButtonClick(e) {
    $.ajax({
      url: 'request/' + this.props.params.id,
      type: 'POST',
      data: {localUser:{user: localStorage.user, course: this.state.selected }},
      dataType: 'json',
      success: function() {
        alert('tutor notified');
      }
    })
  }

  handleComment(e) {
    let comment = React.findDOMNode(this.refs.comment).value;
    let that = this;
    $.ajax({
      url: 'review/' + this.props.params.id,
      type: 'POST',
      data: {user: localStorage.user, comment: comment.trim()},
      dataType: 'json',
      success: function() {
        React.findDOMNode(that.refs.comment).value = " ";
        that.reloadData();
      }
    })

  }

  render () {
    const left = this.state.tutorClasses.slice(0,5).map(course => {
      return(<li>{course.name}{this.state.showGrades?": "+course.grade:""}</li>);
    })
    const right = this.state.tutorClasses.slice(5).map(course => {
{'fraction_non_alphanumeric': 0.16328242993790903, 'fraction_numerical': 0.0016781339150864238, 'mean_word_length': 2.1634819532908707, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 11, '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': '3257413', 'n_tokens_mistral': 1940, 'n_tokens_neox': 1907, 'n_words': 367}