From 39f71221a5e319f5960e0977eaa92b90fa853131 Mon Sep 17 00:00:00 2001 From: ShwetKhatri2001 <19dcs001@lnmiit.ac.in> Date: Thu, 22 Jul 2021 21:17:09 +0530 Subject: [PATCH] fixed showprojects onclick to default options --- src/components/ShowProjects/Showprojects.js | 34 ++++++++++++--------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/components/ShowProjects/Showprojects.js b/src/components/ShowProjects/Showprojects.js index 5d0e10d..77ca783 100644 --- a/src/components/ShowProjects/Showprojects.js +++ b/src/components/ShowProjects/Showprojects.js @@ -99,7 +99,7 @@ function Showprojects() // "VR" const [randomProject, setRandomProject] = useState(""); - const fetchProjects = async () => + const fetchProjects = async (queryoption = "") => { setIsLoading(true); @@ -107,15 +107,22 @@ function Showprojects() { setRandomProject(""); - if (query !== "") + if (queryoption !== "") { - const results = await server.get(`/getprojects?q=${ query }`); + const results = await server.get(`/getprojects?q=${ queryoption }`); setIsLoading(false); setProjects(results.data); setTotalPages(Math.ceil(results.data.length / itemsPerPage)); - } else + + } else if( query !== "") { - toast.error("Please enter a query first"); + const results = await server.get(`/getprojects?q=${ query }`); + setIsLoading(false); + setProjects(results.data); + setTotalPages(Math.ceil(results.data.length / itemsPerPage)); + + } else { + toast.error("Please enter or select a query first"); setIsLoading(false); } } catch (error) @@ -133,8 +140,8 @@ function Showprojects() query: e.target.innerText, }); - // fetchProjects(); - toast.success("Click on search button to search.") + fetchProjects(e.target.innerText); + }; const handleRandomProject = () => @@ -174,13 +181,6 @@ function Showprojects()
Fetching {query} projects
-