Skip to content

Commit

Permalink
Resolve search functionality bug with pagination (#1116)
Browse files Browse the repository at this point in the history
Co-authored-by: Shyam Tawli <104145978+shyamtawli@users.noreply.github.com>
  • Loading branch information
Slacky300 and shyamtawli authored Sep 20, 2024
1 parent 4f61f68 commit b9bb605
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
23 changes: 11 additions & 12 deletions public/data/Om-pawarr.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "Om pawar",
"location": "Maharashtra",
"bio": "A Web Developer specializing in HTML5,css, JavaScript, and front-end frameworks",
"avatar": "https://avatars.githubusercontent.com/u/124502159?s=400&u=3691e22cc07794bb421cee5c655dca4d8da244c9&v=4",
"portfolio": "",
"skills": ["Front end frameworks expertise", "AWS associate level certified", "..."],
"social": {
"GitHub": "https://github.com/Om-pawarr",
"Twitter": "https://twitter.com/@_Parth_Dwivedi_",
"LinkedIn": ""
}
"name": "Om pawar",
"location": "Maharashtra",
"bio": "A Web Developer specializing in HTML5,css, JavaScript, and front-end frameworks",
"avatar": "https://avatars.githubusercontent.com/u/124502159?s=400&u=3691e22cc07794bb421cee5c655dca4d8da244c9&v=4",
"portfolio": "",
"skills": ["Front end frameworks expertise", "AWS associate level certified", "..."],
"social": {
"GitHub": "https://github.com/Om-pawarr",
"Twitter": "https://twitter.com/@_Parth_Dwivedi_",
"LinkedIn": ""
}
}
22 changes: 11 additions & 11 deletions public/data/giuliarappo.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "Giulia",
"location": "Italy",
"bio": "Junior fullstack delevoper searching a project to collaborate for improve skills",
"avatar": "https://github.com/giuliarappo.png",
"portfolio": "https://github.com/giuliarappo",
"skills": ["Java", "Spring boot", "Angular", "React"],
"social": {
"GitHub": "https://github.com/<giuliarappo>",
"LinkedIn": "https://www.linkedin.com/in/<giulia-rappo>"
}
}
"name": "Giulia",
"location": "Italy",
"bio": "Junior fullstack delevoper searching a project to collaborate for improve skills",
"avatar": "https://github.com/giuliarappo.png",
"portfolio": "https://github.com/giuliarappo",
"skills": ["Java", "Spring boot", "Angular", "React"],
"social": {
"GitHub": "https://github.com/<giuliarappo>",
"LinkedIn": "https://www.linkedin.com/in/<giulia-rappo>"
}
}
8 changes: 5 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function App() {
const recordsPerPage = 20;

const currentUrl = window.location.pathname;

useEffect(() => {
const fetchData = async (file) => {
try {
Expand All @@ -36,7 +37,7 @@ function App() {
setLoadingProfiles(true);
try {
const promises = filenames.map((file) => fetchData(`/data/${file}`));
const combinedData = await Promise.all(promises);
const combinedData = await Promise.all(promises).then((results) => results.flat());
setCombinedData(combinedData);
setShuffledProfiles(shuffleProfiles(combinedData));
} catch (error) {
Expand Down Expand Up @@ -80,11 +81,12 @@ function App() {
});

setProfiles(filteredResults);
setCurrentPage(1);
setSearching(true);
};

const handleNextPage = () => {
const totalPages = Math.ceil((searching ? profiles.length : combinedData.length) / recordsPerPage);
const totalPages = Math.ceil((searching ? profiles.length : shuffledProfiles.length) / recordsPerPage);
if (currentPage < totalPages) {
setCurrentPage(currentPage + 1);
}
Expand Down Expand Up @@ -132,7 +134,7 @@ function App() {
<div className="w-full pl-5 pr-4 md:h-screen md:w-[77%] md:overflow-y-scroll md:py-7" ref={profilesRef}>
<Search onSearch={handleSearch} />
{profiles.length === 0 && searching ? <NoResultFound /> : renderProfiles()}
{combinedData.length > 0 && (
{(searching ? profiles.length : shuffledProfiles.length) > 0 && (
<Pagination
currentPage={currentPage}
totalPages={Math.ceil((searching ? profiles.length : shuffledProfiles.length) / recordsPerPage)}
Expand Down
2 changes: 1 addition & 1 deletion src/ProfilesList.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,4 @@
"Om-pawarr.json",
"boytur.json",
"giuliarappo.json"
]
]

0 comments on commit b9bb605

Please sign in to comment.