Skip to content

Commit

Permalink
Merge pull request #269 from ShwetKhatri2001/main
Browse files Browse the repository at this point in the history
Fixed showprojects onclick to default options
  • Loading branch information
rockingrohit9639 authored Jul 24, 2021
2 parents 29b3563 + 39f7122 commit 1d87cb5
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/components/ShowProjects/Showprojects.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,30 @@ function Showprojects()
// "VR"
const [randomProject, setRandomProject] = useState("");

const fetchProjects = async () =>
const fetchProjects = async (queryoption = "") =>
{
setIsLoading(true);

try
{
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)
Expand All @@ -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 = () =>
Expand Down Expand Up @@ -174,13 +181,6 @@ function Showprojects()
<div className="mt">
<SearchBox fetchProjects={fetchProjects} />

{isLoading ? (
<div className="loading_indicator">
<Bars stroke={"#6f6ee1"} fill="#6f6ee1" width="60" height="90" />
<p> Fetching {query} projects </p>
</div>
) : null}

<div className=" default_options filtre-div">
<label className="container">
Beginner Level
Expand Down Expand Up @@ -313,6 +313,12 @@ function Showprojects()
<h2 className="query"> Enter query to search for projects. </h2>
)}

{isLoading ? (
<div className="loading_indicator">
<Bars stroke={"#6f6ee1"} fill="#6f6ee1" width="60" height="90" />
<p> Fetching {query} projects </p>
</div>
) : null}


<div className="projectsList">
Expand Down

0 comments on commit 1d87cb5

Please sign in to comment.