diff --git a/oh_queue/static/css/style.css b/oh_queue/static/css/style.css index 1397b89..4971859 100644 --- a/oh_queue/static/css/style.css +++ b/oh_queue/static/css/style.css @@ -315,6 +315,13 @@ hr { margin-bottom: 10px; } +/* Piazza Search Experiment */ + +.piazza-vote { + margin-top: -5px; +} + + /* Mostly stolen from offline.js */ .offline { diff --git a/oh_queue/static/js/components/description_box.js b/oh_queue/static/js/components/description_box.js index cd7cca8..6a9bb0e 100644 --- a/oh_queue/static/js/components/description_box.js +++ b/oh_queue/static/js/components/description_box.js @@ -3,6 +3,11 @@ class DescriptionBox extends React.Component { super(props); this.handleChange = this.handleChange.bind(this); this.submit = this.submit.bind(this); + + this.piazzaFeedback = this.piazzaFeedback.bind(this); + this.searchPiazza = this.searchPiazza.bind(this); + + this.searchPiazza() } handleChange(event) { @@ -14,18 +19,75 @@ 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 } + piazzaFeedback(e, postId, semester, vote) { + let {state, ticket} = this.props; + e.persist() // Use the event in the async callback. + axios.post(`https://oh-help.cs61a.org/api/v1/algolia/vote`, { + user: this.state.currentUser.hash, + post: postId, + semester: semester, + assignment: ticket.assignment, + isStaff: isStaff(state), + question: ticket.question, + ticketTime: ticket.created, + ticketStatus: ticket.status, + location: ticket.location, + description: ticket.description, + vote: vote + }).then(res => { + app.addMessage("Thanks for your feedback!", 'success'); + }); + } + + 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 += encodeURIComponent(' ' + description); + } + + axios.get(`https://oh-help.cs61a.org/api/v1/algolia/search?query=` + query + '&user=' + user) + .then(res => { + this.piazzaResults = [] + var post; + for (var i in res.data['results']) { + if (i <= 4) { + post = res.data['results'][i]; + this.piazzaResults.push(
{ticket.description ? ticket.description : No description}
+{ticket.description ? ticket.description : No description}
+ { this.piazzaResults } +While you are waiting - check out these resources:
+ { this.piazzaResults } +