From 070e60a46ff137b1fd69655c349067147a5241ff Mon Sep 17 00:00:00 2001 From: Sumukh Sridhara Date: Fri, 17 Mar 2017 18:19:56 -0700 Subject: [PATCH 1/7] Simple prototype of Piazza Search for 61A --- .../static/js/components/description_box.js | 38 +++++++++++++++++++ oh_queue/static/js/state.js | 1 + oh_queue/templates/default.html | 6 ++- oh_queue/views.py | 5 ++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/oh_queue/static/js/components/description_box.js b/oh_queue/static/js/components/description_box.js index cd7cca8..c4439c7 100644 --- a/oh_queue/static/js/components/description_box.js +++ b/oh_queue/static/js/components/description_box.js @@ -3,6 +3,9 @@ class DescriptionBox extends React.Component { super(props); this.handleChange = this.handleChange.bind(this); this.submit = this.submit.bind(this); + this.searchPiazza = this.searchPiazza.bind(this); + + this.searchPiazza() } handleChange(event) { @@ -14,10 +17,40 @@ class DescriptionBox extends React.Component { submit() { let ticket = this.props.ticket; app.makeRequest('describe', {'id': ticket.id, 'description': this.newDescription} ); + // Search Piazza if available + this.searchPiazza(this.newDescription); this.newDescription = null; this.setState(this.props.state); // force a render } + searchPiazza(description) { + let ticket = this.props.ticket; + let assgn = ticket.assignment.replace('Project', 'Proj').replace('Homework', 'HW'); + let assignment = assgn + " Q" + ticket.question + let query = encodeURIComponent(assignment) + let user = encodeURIComponent(this.props.state.currentUser.hash) + + if (description) { + query += ' ' + description; + } + + axios.get(`https://oh-help.cs61a.org/api/v1/algolia/search?query=` + query + '&user=' + user) + .then(res => { + this.piazzaResults = [] + for (var i in res.data['results']) { + this.piazzaResults.push(
+ {res.data['results'][i].subject} +
+
👍
+
👎
+
+
+
) + } + this.setState(this.props.state); // force a render + }); + } + render() { let {state, ticket} = this.props; let staff = isStaff(state); @@ -34,6 +67,11 @@ class DescriptionBox extends React.Component {