diff --git a/backend/routers/psOne.js b/backend/routers/psOne.js index 2a33a64..a672c46 100644 --- a/backend/routers/psOne.js +++ b/backend/routers/psOne.js @@ -1,11 +1,14 @@ -const express = require('express'); +const express = require("express"); const router = new express.Router(); -const auth = require('../middleware/auth'); -const Station = require('../models/station'); +const auth = require("../middleware/auth"); +const Station = require("../models/station"); // get details of a station for ps1 -router.get('/api/1/:station', async (req, res) => { - const station = await Station.findOne({ category: { type: 'ps1' }, slug: req.params.station }); +router.get("/api/1/:station", async (req, res) => { + const station = await Station.findOne({ + category: { type: "ps1" }, + slug: req.params.station, + }); if (!station) { res.status(404).send(); @@ -16,26 +19,28 @@ router.get('/api/1/:station', async (req, res) => { }); // search the stations by name for ps1 -router.get('/api/1', async (req, res) => { +router.get("/api/1", async (req, res) => { const queries = { - category: { type: 'ps1' } + category: { type: "ps1" }, }; if (req.query.name) { - queries.name = { $regex: new RegExp(req.query.name, 'i') }; + queries.name = { $regex: new RegExp(req.query.name, "i") }; } if (req.query.location) { - queries.location = { $regex: new RegExp(req.query.location, 'i') }; + queries.location = { $regex: new RegExp(req.query.location, "i") }; } try { - const stations = await Station.find(queries, - 'name category field location cg slug', + const stations = await Station.find( + queries, + "name category field location cg slug", { limit: parseInt(req.query.limit), - skip: parseInt(req.query.skip) - }); + skip: parseInt(req.query.skip), + } + ); res.send(stations); } catch (e) { @@ -44,18 +49,21 @@ router.get('/api/1', async (req, res) => { }); // post a new comment on the opportunity for ps1 -router.post('/api/1/:station/comment', auth, async (req, res) => { - const station = await Station.findOne({ category: { type: 'ps1' }, slug: req.params.station }); +router.post("/api/1/:station/comment", auth, async (req, res) => { + const station = await Station.findOne({ + category: { type: "ps1" }, + slug: req.params.station, + }); if (!station) { - return res.status(404).send('Station not found'); + return res.status(404).send("Station not found"); } station.discussion.push({ comment: { user: req.user._id, - data: req.body.data - } + data: req.body.data, + }, }); try { @@ -68,23 +76,28 @@ router.post('/api/1/:station/comment', auth, async (req, res) => { }); // post a new reply on a comment for ps1 -router.post('/api/1/:station/:comment/reply', auth, async (req, res) => { - const station = await Station.findOne({ category: { type: 'ps1' }, slug: req.params.station }); +router.post("/api/1/:station/:comment/reply", auth, async (req, res) => { + const station = await Station.findOne({ + category: { type: "ps1" }, + slug: req.params.station, + }); if (!station) { - return res.status(404).send('Station not found'); + return res.status(404).send("Station not found"); } // eslint-disable-next-line eqeqeq - const commentIndex = station.discussion.findIndex((comment) => comment._id == req.params.comment); + const commentIndex = station.discussion.findIndex( + (comment) => comment._id == req.params.comment + ); if (commentIndex === -1) { - return res.status(404).send('Comment not found'); + return res.status(404).send("Comment not found"); } station.discussion[commentIndex].comment.replies.push({ user: req.user._id, - data: req.body.data + data: req.body.data, }); try { diff --git a/frontend/public/index.html b/frontend/public/index.html index bdf9cea..ca6aa9a 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -27,7 +27,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - React App + BITSandPSes diff --git a/frontend/src/containers/Choose/chooseComponent.js b/frontend/src/containers/Choose/chooseComponent.js index d68a49a..8cba5fc 100644 --- a/frontend/src/containers/Choose/chooseComponent.js +++ b/frontend/src/containers/Choose/chooseComponent.js @@ -1,84 +1,85 @@ -import React from 'react'; -import './chooser.css'; -import { Link, Redirect } from 'react-router-dom'; +import React from "react"; +import "./chooser.css"; +import { Link, Redirect } from "react-router-dom"; //the website should be navigatable through url sharing. All base url cases will //be diverted to this component. -//website has 3 sub-parts. 1 for ps1, 2 for ps2, 3 for electives. If user has ever visited the +//website has 3 sub-parts. 1 for ps1, 2 for ps2, 3 for electives. If user has ever visited the //website in past, base url redirects to last used sub-part of the website. Otherwise, chooser helps in selecting them one. -//user's current sub-part is always stored and updated in the localStorage. -function Choose () { - const storedChoice = parseInt(window.localStorage.getItem("stationNo")); //fetch user's last used sub-part of website - if(storedChoice === 1 || storedChoice === 2 || storedChoice === 3 ) { //validation for redirecting to sub-part's home page - return( - - ); - } - else { //if not found in localStorage, render Chooser component - return( -
-
-
-

- BITS - and - PS - es +//user's current sub-part is always stored and updated in the localStorage. +function Choose() { + const storedChoice = parseInt(window.localStorage.getItem("stationNo")); //fetch user's last used sub-part of website + if (storedChoice === 1 || storedChoice === 2 || storedChoice === 3) { + //validation for redirecting to sub-part's home page + return ; + } else { + //if not found in localStorage, render Chooser component + return ( +
+
+
+

+ BITS + and + PS + es

-
-

- might save you from the factories +
+

+ might save you from the factories

-
- -
-

- PS1 -

-
- if you lost your 60k -
+
+ +
+

PS1

+
if you lost your 60k
-

PS1

+

PS1

-
- -
-

- PS2 -

-
+
+ +
+

PS2

+
if you want to redeem your 60k
-

PS2

+

PS2

-
-
- +
+
+ Electives
-
-

- Made by two lonely guys in their pyjamas, dont shove our throats - if content on this website turns out to be slightly deviating from actual data. Just like with you, - BITS Admin was a jerk to us too. +
+

+ Made by two lonely guys in their pyjamas, dont shove our throats + if content on this website turns out to be slightly deviating from + actual data. Just like with you, BITS Admin was a jerk to us too.

-

- Choose the left one if you were robbed - of 60k. Right one if you are looking - to redeem the 60k. +

+ Choose the left one if you were robbed of 60k. Right one if you + are looking to redeem the 60k.

); } -}; +} -export default Choose; \ No newline at end of file +export default Choose; diff --git a/frontend/src/containers/Home/CourseDisplay/courseDisplayComponent.js b/frontend/src/containers/Home/CourseDisplay/courseDisplayComponent.js index 2a168c2..7ae6c16 100644 --- a/frontend/src/containers/Home/CourseDisplay/courseDisplayComponent.js +++ b/frontend/src/containers/Home/CourseDisplay/courseDisplayComponent.js @@ -1,47 +1,45 @@ -import React, { Component } from 'react'; -import './courseDisplay.css'; -import NotFound from '../../NotFound/notfoundComponent'; -import { FormGroup, Form, Input, Button} from 'reactstrap'; -import axios from 'axios'; -import RenderComment from './courseComments/courseComments'; //component to display each comment with its replies -import { withRouter } from 'react-router-dom'; -import SearchBar from '../searchCourseNav/searchCourseNavComponent'; //component that allows to search right from course page -import baseUrl from '../../../baseUrl'; //for directing requests to backend +import React, { Component } from "react"; +import "./courseDisplay.css"; +import NotFound from "../../NotFound/notfoundComponent"; +import { FormGroup, Form, Input, Button } from "reactstrap"; +import axios from "axios"; +import RenderComment from "./courseComments/courseComments"; //component to display each comment with its replies +import { withRouter } from "react-router-dom"; +import SearchBar from "../searchCourseNav/searchCourseNavComponent"; //component that allows to search right from course page +import baseUrl from "../../../baseUrl"; //for directing requests to backend -function RenderComments ({list, authorlist, courseSlug}) { //to render all comments in discussion container - if(!list || list.length === 0) { - return( -
-

No comments

+function RenderComments({ list, authorlist, courseSlug }) { + //to render all comments in discussion container + if (!list || list.length === 0) { + return ( +
+

No comments

); } - + console.log(list); console.log(authorlist); - if( !authorlist || authorlist.length === 0) { - return( -
- ); - } - - else { - return( -
- { list.map((comment) => { - return( - + if (!authorlist || authorlist.length === 0) { + return
; + } else { + return ( +
+ {list.map((comment) => { + return ( + ); - })} + })}
); } -}; +} class CourseDisplay extends Component { constructor(props) { @@ -49,195 +47,241 @@ class CourseDisplay extends Component { this.handleCommentChange = this.handleCommentChange.bind(this); this.handleCommentSubmit = this.handleCommentSubmit.bind(this); this.state = { - courseDetails: { //structure defined here to prevent initial callback failure - course: { //promise updates and fills this object + courseDetails: { + //structure defined here to prevent initial callback failure + course: { + //promise updates and fills this object title: null, - discussion: [] + discussion: [], }, - users: [] + users: [], }, - courseFound: true, //boolean to store whether courseSlug in url is found or not - commentField: null, //stores and updates comment typed by the user after every change - courseDesc: { //stores all course data fetched from timetable api - lectures: [] //structure defined here to prevent initial callback failure - } - } + courseFound: true, //boolean to store whether courseSlug in url is found or not + commentField: null, //stores and updates comment typed by the user after every change + courseDesc: { + //stores all course data fetched from timetable api + lectures: [], //structure defined here to prevent initial callback failure + }, + }; } - - async componentDidMount() { - const query = this.props.match.params.courseSlug; //extracting courseSlug from url + + async componentDidMount() { + const query = this.props.match.params.courseSlug; //extracting courseSlug from url try { - const response = await fetch( baseUrl + '/api/course/' + query); //fetching all the course details thru backend - if(response.ok) { - const json = await response.json(); + const response = await fetch(baseUrl + "/api/course/" + query); //fetching all the course details thru backend + if (response.ok) { + const json = await response.json(); console.log(json); this.setState({ - courseDetails: json, //updating courseDetails - courseFound: true + courseDetails: json, //updating courseDetails + courseFound: true, }); - } - else if(response.status === 404) { + } else if (response.status === 404) { this.setState({ - courseFound: false //redirects to not found component on re-render - }) - } - else { - var error = new Error('Error ' + response.status + ': ' + response.statusText); + courseFound: false, //redirects to not found component on re-render + }); + } else { + var error = new Error( + "Error " + response.status + ": " + response.statusText + ); error.response = response; this.setState({ - courseFound: false + courseFound: false, }); throw error; } - + //course details from timetable api are fetched - const fresponse = await fetch('https://timetablevisualiser-api.herokuapp.com/CourseData?course_number=' + this.state.courseDetails.course.number); - if(fresponse.ok) { + const fresponse = await fetch( + "https://timetablevisualiser-api.herokuapp.com/CourseData?course_number=" + + this.state.courseDetails.course.number + ); + if (fresponse.ok) { const json = await fresponse.json(); console.log(json); this.setState({ - courseDesc: json //updates courseDesc + courseDesc: json, //updates courseDesc }); - } - else if(fresponse.status === 404) { + } else if (fresponse.status === 404) { this.setState({ - courseFound: false //redirects to not found component on re-render + courseFound: false, //redirects to not found component on re-render }); - } - else { - var error = new Error('Error ' + response.status + ': ' + response.statusText); + } else { + var error = new Error( + "Error " + response.status + ": " + response.statusText + ); error.response = response; this.setState({ - courseFound: false + courseFound: false, }); throw error; } - } catch(error) { - alert("could not fetch course Details.\nError: "+ error.message); + } catch (error) { + alert("could not fetch course Details.\nError: " + error.message); } } - handleCommentChange = (event) => { //on every change in input ,this is triggered to store the updated comment in state + handleCommentChange = (event) => { + //on every change in input ,this is triggered to store the updated comment in state this.setState({ - commentField: event.target.value + commentField: event.target.value, }); }; - handleCommentSubmit = async e => { //triggers every time client hits "post Comment" + handleCommentSubmit = async (e) => { + //triggers every time client hits "post Comment" e.preventDefault(); - if(document.cookie.split(';').some((item) => item.trim().startsWith('jwt='))) { //checking whether client has logged in - const cookies = document.cookie.split('; '); - const value = cookies.find(item => item.startsWith('jwt')).split('=')[1]; //extracting bearer token from login cookie + if ( + document.cookie.split(";").some((item) => item.trim().startsWith("jwt=")) + ) { + //checking whether client has logged in + const cookies = document.cookie.split("; "); + const value = cookies + .find((item) => item.startsWith("jwt")) + .split("=")[1]; //extracting bearer token from login cookie console.log(value); - const response = await axios({ //posting the comment request on backend - method: 'post', - url: "/api/course/" + this.props.match.params.courseSlug + "/comment" , + const response = await axios({ + //posting the comment request on backend + method: "post", + url: "/api/course/" + this.props.match.params.courseSlug + "/comment", headers: { - Authorization: `Bearer ${value}` + Authorization: `Bearer ${value}`, }, data: { - data: this.state.commentField - } + data: this.state.commentField, + }, }); - if(response.status === 200) { - window.location.reload(); //reload tha page to show new updated comment - } - else { - alert('Error ' + response.status + ': ' + response.statusText); + if (response.status === 200) { + window.location.reload(); //reload tha page to show new updated comment + } else { + alert("Error " + response.status + ": " + response.statusText); } - } - else { //if client has not logged in + } else { + //if client has not logged in alert("you must be logged in to comment on stations."); } - } + }; render() { - window.localStorage.setItem("stationNo", "3"); - if(this.state.courseFound === true) { //check if course has been found (true default value so that notfound isnt shown while page reloads) - let professors = []; - this.state.courseDesc.lectures.forEach((section) => { //finding all unique profs currently taking the course + window.localStorage.setItem("stationNo", "3"); + if (this.state.courseFound === true) { + //check if course has been found (true default value so that notfound isnt shown while page reloads) + let professors = []; + this.state.courseDesc.lectures.forEach((section) => { + //finding all unique profs currently taking the course let counter = 3; const substrings = section.split(","); - while(counter < substrings.length) { + while (counter < substrings.length) { professors.push(substrings[counter]); counter++; - } + } }); - let uniprofs = [...new Set(professors)]; //removes repetition of same names from array - let uniprofstring = ""; + let uniprofs = [...new Set(professors)]; //removes repetition of same names from array + let uniprofstring = ""; let count = 0; - while( count < uniprofs.length ) //creating string for display from professors array - { - if( count !== 0) { + while (count < uniprofs.length) { + //creating string for display from professors array + if (count !== 0) { uniprofstring = uniprofstring + ", "; } uniprofstring = uniprofstring + uniprofs[count]; count++; } - return( -
- -
-
-

{this.state.courseDetails.course.title}

{this.state.courseDetails.course.number}

+ return ( +
+ +
+
+

+ {this.state.courseDetails.course.title} +

+ {this.state.courseDetails.course.number} +
+

-
-
- Instructor in-charge:  - +
+
+ + Instructor in-charge:  + + {this.state.courseDesc.ic} -
- Professors:  - {uniprofstring}
- No of credits on completion:  - {this.state.courseDesc.credits}
- Description:  -
+ +
+ Professors:  + {uniprofstring} +
+ + No of credits on completion:  + + + {this.state.courseDesc.credits} + +
+ Description:  + +
-
-

Resources

+
+

Resources

-
-

Discussion

-
- -
-
+
+

Discussion

+
+ +
+ - {this.handleCommentChange(event) }}> - -
- + { + this.handleCommentChange(event); + }} + > +
+
-
-
- +
); + } else { + return ; } - else { - return( - - ); - } - }; -}; + } +} -export default withRouter(CourseDisplay); \ No newline at end of file +export default withRouter(CourseDisplay); diff --git a/frontend/src/containers/Home/ElecHomed/elechomedComponent.js b/frontend/src/containers/Home/ElecHomed/elechomedComponent.js index e746bbb..c057738 100644 --- a/frontend/src/containers/Home/ElecHomed/elechomedComponent.js +++ b/frontend/src/containers/Home/ElecHomed/elechomedComponent.js @@ -1,34 +1,43 @@ -import React, { Component } from 'react'; -import { Form, FormGroup, Input, Button, Label } from 'reactstrap'; +import React, { Component } from "react"; +import { Form, FormGroup, Input, Button, Label } from "reactstrap"; import "./elecHomed.css"; -import { Link } from 'react-router-dom'; -import CheckBox from './checkBoxComponent'; -import baseUrl from '../../../baseUrl'; -import { CSSTransition } from 'react-transition-group'; +import { Link } from "react-router-dom"; +import CheckBox from "./checkBoxComponent"; +import baseUrl from "../../../baseUrl"; +import { CSSTransition } from "react-transition-group"; -function ListDisplay ({list,title}) { +function ListDisplay({ list, title }) { console.log(list); - if(list === null) { - return( -
- ); - } - else { - return( + if (list === null) { + return
; + } else { + return (
-

{title}

-
    - { list.map((item) => { - return( -
  • - -
    -
    {item.title}
    -
    {"Number: " + item.number}
    -
    - -
  • - ); +

    {title}

    +
      + {list.map((item) => { + return ( +
    • + +
      +
      + {item.title} +
      +
      + {"Number: " + item.number} +
      +
      + +
    • + ); })}
@@ -38,7 +47,7 @@ function ListDisplay ({list,title}) { class CourseDisplay extends Component { constructor(props) { - window.localStorage.setItem("stationNo","3") + window.localStorage.setItem("stationNo", "3"); super(props); this.findplaceholder = this.findplaceholder.bind(this); this.handleEmptytype = this.handleEmptytype.bind(this); @@ -53,14 +62,19 @@ class CourseDisplay extends Component { shouldLoadMore: true, allCheck: true, courses: [ - { id: 1, value: "BITS", name: "General", isChecked: false}, + { id: 1, value: "BITS", name: "General", isChecked: false }, { id: 2, value: "BIO", name: "Biology", isChecked: false }, { id: 3, value: "CE", name: "Civil", isChecked: false }, { id: 4, value: "CHE", name: "Chemical", isChecked: false }, { id: 5, value: "CHEM", name: "Chemistry", isChecked: false }, { id: 6, value: "CS", name: "Computer Science", isChecked: false }, { id: 7, value: "ECON", name: "Economics", isChecked: false }, - { id: 8, value: "EEE", name: "Electrical & Electronics", isChecked: false }, + { + id: 8, + value: "EEE", + name: "Electrical & Electronics", + isChecked: false, + }, { id: 9, value: "GS|\bHSS", name: "Humanities", isChecked: false }, { id: 10, value: "INSTR", name: "Instrumentation", isChecked: false }, { id: 12, value: "MATH", name: "Mathematics", isChecked: false }, @@ -71,12 +85,12 @@ class CourseDisplay extends Component { { id: 17, value: "PHY", name: "Physics", isChecked: false }, ], searchMethod: "name", - isfilterOpen: false - } + isfilterOpen: false, + }; } - + componentDidUpdate(prevProps) { - if(prevProps.location.key !== this.props.location.key) { + if (prevProps.location.key !== this.props.location.key) { window.location.reload(false); } } @@ -84,38 +98,47 @@ class CourseDisplay extends Component { async componentDidMount() { let courses = this.state.courses; let allCheck; - window.sessionStorage.getItem("allCheck") === "0" ? allCheck = false : allCheck = true; + window.sessionStorage.getItem("allCheck") === "0" + ? (allCheck = false) + : (allCheck = true); courses.forEach((course) => { - if(window.sessionStorage.getItem(course.name) === "0") { - course.isChecked = false; - } - else { + if (window.sessionStorage.getItem(course.name) === "0") { + course.isChecked = false; + } else { course.isChecked = true; } }); this.setState({ courses: courses, - allCheck: allCheck + allCheck: allCheck, }); console.log(this.props); try { - if(this.props.location.search !== "") { + if (this.props.location.search !== "") { const query = this.props.location.search.split("=")[1].split("&")[0]; const sender = this.props.location.search.split("=")[2]; - const response = await fetch( baseUrl + '/api/course?' + sender + '=' + query + '&limit=10&skip=' + this.state.stationsDisplayed ); - if(response.ok) - { + const response = await fetch( + baseUrl + + "/api/course?" + + sender + + "=" + + query + + "&limit=10&skip=" + + this.state.stationsDisplayed + ); + if (response.ok) { const json = await response.json(); this.setState({ searchData: json, resultTitle: "Search Courses", stationsDisplayed: this.state.stationsDisplayed + json.length, - shouldLoadMore: ( json.length === 10 ), - searchMethod: sender + shouldLoadMore: json.length === 10, + searchMethod: sender, }); - } - else { - var error = new Error('Error ' + response.status + ': ' + response.statusText); + } else { + var error = new Error( + "Error " + response.status + ": " + response.statusText + ); error.response = response; throw error; } @@ -123,142 +146,151 @@ class CourseDisplay extends Component { let query = "("; let counter = 0; this.state.courses.forEach((course) => { - if(course.isChecked) { - if(counter === 0) { - query = query + '\\b' + course.value; - } - else { - query = query + '|\\b' + course.value; + if (course.isChecked) { + if (counter === 0) { + query = query + "\\b" + course.value; + } else { + query = query + "|\\b" + course.value; } counter++; } }); - query = query + ')'; - const response = await fetch( baseUrl + '/api/course?number=' + query + '&limit=10&skip=' + this.state.stationsDisplayed ); - if(response.ok) - { + query = query + ")"; + const response = await fetch( + baseUrl + + "/api/course?number=" + + query + + "&limit=10&skip=" + + this.state.stationsDisplayed + ); + if (response.ok) { const json = await response.json(); this.setState({ searchData: json, stationsDisplayed: this.state.stationsDisplayed + json.length, - shouldLoadMore: ( json.length === 10 ), - searchMethod: "number" + shouldLoadMore: json.length === 10, + searchMethod: "number", }); - } - else { - var error = new Error('Error ' + response.status + ': ' + response.statusText); + } else { + var error = new Error( + "Error " + response.status + ": " + response.statusText + ); error.response = response; throw error; } } - } catch(error) { - alert("could not fetch search results.\nError: "+ error.message); + } catch (error) { + alert("could not fetch search results.\nError: " + error.message); } } handleFilters = (event) => { event.preventDefault(); - } + }; togglefiltersmall = () => { this.setState({ - isfilterOpen: !this.state.isfilterOpen + isfilterOpen: !this.state.isfilterOpen, }); - } + }; toggleCheck = (event) => { let courses = this.state.courses; - if(event.target.checked) { - window.sessionStorage.setItem("allCheck","1"); + if (event.target.checked) { + window.sessionStorage.setItem("allCheck", "1"); this.setState({ - allCheck: true + allCheck: true, }); - } - else { - window.sessionStorage.setItem("allCheck","0"); + } else { + window.sessionStorage.setItem("allCheck", "0"); this.setState({ - allCheck: false - }) + allCheck: false, + }); } courses.forEach((course) => { - course.isChecked = event.target.checked - if(course.isChecked) { - window.sessionStorage.setItem(course.name,"1"); - } - else { - window.sessionStorage.setItem(course.name,"0"); + course.isChecked = event.target.checked; + if (course.isChecked) { + window.sessionStorage.setItem(course.name, "1"); + } else { + window.sessionStorage.setItem(course.name, "0"); } }); this.setState({ - courses: courses + courses: courses, }); - } + }; handleCheckChild = (event) => { let courses = this.state.courses; courses.forEach((course) => { - if(event.target.value === course.value) { - course.isChecked = event.target.checked - if(course.isChecked) { - window.sessionStorage.setItem(course.name,"1"); - } - else { - window.sessionStorage.setItem(course.name,"0"); + if (event.target.value === course.value) { + course.isChecked = event.target.checked; + if (course.isChecked) { + window.sessionStorage.setItem(course.name, "1"); + } else { + window.sessionStorage.setItem(course.name, "0"); } } }); this.setState({ - courses: courses + courses: courses, }); - } - + }; + changeSearchMethod = (changeEvent) => { this.setState({ - searchMethod: changeEvent.target.value + searchMethod: changeEvent.target.value, }); - } + }; findplaceholder = () => { - if( this.props.location.search !== "") { + if (this.props.location.search !== "") { return this.props.location.search.split("=")[1].split("&")[0]; - } - else { + } else { return null; } }; handleEmptytype = (event) => { - if(this.state.searchField === null || this.state.searchField === "") { + if (this.state.searchField === null || this.state.searchField === "") { event.preventDefault(); } - } + }; storeSearch = (event) => { this.setState({ - searchField: event.target.value + searchField: event.target.value, }); - } + }; - loadMore = async(event) => { + loadMore = async (event) => { var x = window.scrollX; var y = window.scrollY; try { - if(this.props.location.search !== "") { + if (this.props.location.search !== "") { const query = this.props.location.search.split("=")[1].split("&")[0]; const sender = this.props.location.search.split("=")[2]; - const response = await fetch( baseUrl + '/api/course?' + sender + '=' + query + '&limit=10&skip=' + this.state.stationsDisplayed ); - if(response.ok) - { + const response = await fetch( + baseUrl + + "/api/course?" + + sender + + "=" + + query + + "&limit=10&skip=" + + this.state.stationsDisplayed + ); + if (response.ok) { const json = await response.json(); this.setState({ - searchData: [...this.state.searchData,...json], + searchData: [...this.state.searchData, ...json], resultTitle: "Searched Courses", stationsDisplayed: this.state.stationsDisplayed + json.length, - shouldLoadMore: ( json.length === 10 ) + shouldLoadMore: json.length === 10, }); - } - else { - var error = new Error('Error ' + response.status + ': ' + response.statusText); + } else { + var error = new Error( + "Error " + response.status + ": " + response.statusText + ); error.response = response; throw error; } @@ -266,194 +298,279 @@ class CourseDisplay extends Component { let query = "("; let counter = 0; this.state.courses.forEach((course) => { - if(course.isChecked) { - if(counter === 0) { - query = query + '\\b' + course.value; - } - else { - query = query + '|\\b' + course.value; + if (course.isChecked) { + if (counter === 0) { + query = query + "\\b" + course.value; + } else { + query = query + "|\\b" + course.value; } counter++; } }); - query = query + ')'; - const response = await fetch( baseUrl + '/api/course?number=' + query + '&limit=10&skip=' + this.state.stationsDisplayed ); - if(response.ok) - { + query = query + ")"; + const response = await fetch( + baseUrl + + "/api/course?number=" + + query + + "&limit=10&skip=" + + this.state.stationsDisplayed + ); + if (response.ok) { const json = await response.json(); this.setState({ - searchData: [...this.state.searchData,...json], + searchData: [...this.state.searchData, ...json], stationsDisplayed: this.state.stationsDisplayed + json.length, - shouldLoadMore: ( json.length === 10 ) + shouldLoadMore: json.length === 10, }); - } - else { - var error = new Error('Error ' + response.status + ': ' + response.statusText); + } else { + var error = new Error( + "Error " + response.status + ": " + response.statusText + ); error.response = response; throw error; } } - } catch(error) { - alert("could not fetch search results.\nError: "+ error.message); + } catch (error) { + alert("could not fetch search results.\nError: " + error.message); } - window.scrollTo(x,y); - } + window.scrollTo(x, y); + }; render() { - return( -
-
-
-
-

Search.

-
- Find the course you are looking for according to the priorities you set.
- Search by name or courseNo, filter according to your preferences. + return ( +
+
+
+
+

+ Search. +

+
+ Find the course you are looking for according to the priorities + you set. +
+ Search by name or courseNo, filter according to your + preferences.
-
- We will try to find what you are looking for +
+ We will try to find what you are looking for
-
-
-
- {this.storeSearch(event)}} /> +
+ +
+ { + this.storeSearch(event); + }} + />
-
- -
-
-
-
-

Filters

-
- -