<commit_before>import React, { Component } from 'react'
import { Link } from 'react-router'
import { connect } from 'react-redux'
import { pushPath } from 'redux-simple-router'
import { firebaseRef, CATEGORIES } from '../config'

class GiveHelpComponent extends Component {

	constructor(props) {
		super(props)
		this.state = {
			category: 'TDT4100',
			questions: [],
			counter: 0
		}

		this.changeCourse = this.changeCourse.bind(this)
		this.firebaseRef = firebaseRef.child(`questions/`).orderByChild('closed').equalTo(false)
		this.convertToDate = this.convertToDate.bind(this)
		this.interval = setInterval(() => this.tick(), 1000)
	}

	componentWillUnmount() {
		clearInterval(this.interval);
		this.firebaseRef.off()
	}

	componentDidMount() {
		this.firebaseRef.on('value', snapshot => {
		  if (snapshot.exists()) {
		      let questions = []
		      snapshot.forEach(question => {

		      	if (!question.val().closed && !question.val().tutor) {
		        	questions.push(question.val())
		      	};
		      })
		      this.setState({questions: questions})
		  }
		})
	}

	changeCourse(event) {
		this.setState({
			category: event.target.value
		})
	}

	convertToDate(stamp) {
		let time = new Date(stamp * 1000)
		let now = Date.now()

		if ((now-stamp) > 3600000)
			return "+60"
		else
			return Math.floor(((now-stamp)/ 1000)/60)
	}

	// This counter is only used to update question.createdAt every minute.
	tick() {
		this.forceUpdate()
	  // this.setState({
	  //   counter: this.state.counter + 1
	  // });
	}

	render() {
		return (
			<div className="container">
				<select className="form-control" id="select" onChange={this.changeCourse} value={this.state.category}>
				  { CATEGORIES.map(category => <option key={category.id} value={category.id}>{ category.name }</option> )}
				</select>
				<table className="table table-striped table-hover">
				  <thead>
				    <tr>
				      <th>Question</th>
				      <th>Student</th>
				      <th>Time</th>
				    </tr>
				  </thead>
				  <tbody>
				  	{ this.state.questions.map(question => {
				  		if(question.category === this.state.category) {
					  		return (
					  			<tr key={question.id}>
					  				<td><Link className="GREEN-TEXT" to={`/question/${question.id}`}>{question.text}</Link></td><commit_msg>Querying for closed = false on Questions, forcing update on tutor-dashboard to see time since question was asked.<commit_after>import React, { Component } from 'react'
import { Link } from 'react-router'
import { connect } from 'react-redux'
import { pushPath } from 'redux-simple-router'
import { firebaseRef, CATEGORIES } from '../config'

class GiveHelpComponent extends Component {

	constructor(props) {
		super(props)
		this.state = {
			category: 'TDT4100',
			questions: []
		}

		this.changeCourse = this.changeCourse.bind(this)
		this.onValueChange = this.onValueChange.bind(this)
		this.firebaseRef = firebaseRef.child(`questions/`).orderByChild('closed').equalTo(false)
		this.interval = setInterval(() => this.tick(), 60000)
	}

	componentWillUnmount() {
		clearInterval(this.interval);
		this.firebaseRef.off('value', this.onValueChange)
	}

	onValueChange(snapshot) {
		if (snapshot.exists()) {
			let questions = []
			snapshot.forEach(snap => {
				let question = snap.val()
				if (!question.tutor) {
					questions.push(question)
				}
			})
			if (questions.length > 0) {
				this.setState({questions: questions})
			}
	  }
	}

	componentDidMount() {
		this.firebaseRef.on('value', this.onValueChange)
	}

	changeCourse(event) {
		this.setState({
			category: event.target.value
		})
	}

	tick() {
		this.forceUpdate() // Force the questions to update every minute
	}

	render() {
		return (
			<div className="container">
				<select className="form-control" id="select" onChange={this.changeCourse} value={this.state.category}>
				  { CATEGORIES.map(category => <option key={category.id} value={category.id}>{ category.name }</option> )}
				</select>
				<table className="table table-striped table-hover">
				  <thead>
				    <tr>
				      <th>Question</th>
				      <th>Student</th>
				      <th>Time</th>
				    </tr>
				  </thead>
				  <tbody>
				  	{ this.state.questions.map(question => {
				  		if(question.category === this.state.category) {
					  		return (
					  			<tr key={question.id}>
					  				<td><Link className="GREEN-TEXT" to={`/question/${question.id}`}>{question.text}</Link></td>
{'fraction_non_alphanumeric': 0.15842924847664183, 'fraction_numerical': 0.008801624915368992, 'mean_word_length': 3.115134633240483, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 58, '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': '4901658', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1432, 'n_words': 267}