From 13051317c45efe2e3a78c32206d66add3ae075ae Mon Sep 17 00:00:00 2001 From: mjaydenkim Date: Tue, 14 Jan 2025 01:35:53 -0500 Subject: [PATCH] Fixed up Results --- .../modules/Results/Components/Results.tsx | 78 +++++++------------ .../Results/Components/ResultsDisplay.tsx | 2 +- 2 files changed, 31 insertions(+), 49 deletions(-) diff --git a/client/src/modules/Results/Components/Results.tsx b/client/src/modules/Results/Components/Results.tsx index 825247aa..65e91f10 100644 --- a/client/src/modules/Results/Components/Results.tsx +++ b/client/src/modules/Results/Components/Results.tsx @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { Component, useEffect, useState } from 'react'; import axios from 'axios'; import Navbar from '../../Globals/Navbar'; @@ -25,57 +25,39 @@ type ResultsLists = { * Results Component * Used to render the results page. Uses Navbar and ResultsDisplay components directly. */ -export class Results extends Component { - constructor(props: ResultsProps) { - super(props); - this.state = { - courseList: [], - loading: true - }; - - this.updateResults = this.updateResults.bind(this); - } +export const Results = ({match, history}: ResultsProps) => { + const [courseList, setCourseList] = useState([]); + const [loading, setLoading] = useState(true); - async updateResults() { + const updateResults = async () => { const response = await axios.post(`/api/search/get-courses`, { - query: this.props.match.params.input.toLowerCase() + query: match.params.input.toLowerCase() }); - const courseList = response.data.result.courses; - this.setState({ - courseList: !courseList.error && courseList.length > 0 ? courseList : [], - loading: false - }); - } - - componentDidUpdate(prevProps: ResultsProps) { - if (prevProps !== this.props) { - this.setState({ - courseList: [], - loading: true - }); - this.updateResults(); - } - } - - componentDidMount() { - this.updateResults(); + setCourseList(!courseList.error && courseList.length > 0 ? courseList : []); + setLoading(false); } - render() { - const userInput = this.props.match.params.input.split('+').join(' '); - return ( -
- - - -
- ); - } + useEffect(() => { + setCourseList([]); + setLoading(true); + updateResults(); + }, [match, history]) + + const userInput = match.params.input.split('+').join(' '); + return ( +
+ + + +
+ ); } + +export default Results; \ No newline at end of file diff --git a/client/src/modules/Results/Components/ResultsDisplay.tsx b/client/src/modules/Results/Components/ResultsDisplay.tsx index bb95eca3..f9fbe77f 100644 --- a/client/src/modules/Results/Components/ResultsDisplay.tsx +++ b/client/src/modules/Results/Components/ResultsDisplay.tsx @@ -320,7 +320,7 @@ export const ResultsDisplay = ({courses, loading, type, userInput}: ResultsDispl