diff --git a/client/src/pages/DirectoryPage/DirectoryPage.tsx b/client/src/pages/DirectoryPage/DirectoryPage.tsx index 4686f3d..45b6c25 100644 --- a/client/src/pages/DirectoryPage/DirectoryPage.tsx +++ b/client/src/pages/DirectoryPage/DirectoryPage.tsx @@ -14,50 +14,79 @@ const DirectoryPage = (): JSX.Element => { dispatch(fetchAlumni({ page, name: nameSearch, company: companySearch })); }, [dispatch, page, nameSearch, companySearch]); + const handlePreviousPage = () => { + if (page > 1) { + dispatch( + fetchAlumni({ + page: page - 1, + name: nameSearch, + company: companySearch, + }) + ); + } + }; + + const handleNextPage = () => { + if (page < totalPages) { + dispatch( + fetchAlumni({ + page: page + 1, + name: nameSearch, + company: companySearch, + }) + ); + } + }; + return ( -
-

Alumni Directory

-
- setNameSearch(e.target.value)} - placeholder="Search by name" - className="mb-4 p-2 text-gray-900" - /> - setCompanySearch(e.target.value)} - placeholder="Search by company" - className="mb-4 p-2 text-gray-900" - /> +
+
+

Alumni Directory

+
+ setNameSearch(e.target.value)} + placeholder="Search by name" + className="mb-4 p-2 text-gray-900" + /> + setCompanySearch(e.target.value)} + placeholder="Search by company" + className="mb-4 p-2 text-gray-900" + /> +
- {status === "loading" ? ( -

Loading...

- ) : ( -
-
-
- Name -
-
- Company -
-
- Email -
-
- {alumni.map((alum) => ( -
-
{alum.name}
-
{alum.company}
-
{alum.email}
-
- ))} +
+
+ Name + Company + Email
- )} - {/* TODO Pagination controls! */} +
+ {status === "loading" ? ( +

Loading...

+ ) : ( + alumni.map((alum) => ( +
+
{alum.name}
+
{alum.company}
+
{alum.email}
+
+ )) + )} +
+
+ + +
+
); }; diff --git a/server/controllers/alumniControllers.ts b/server/controllers/alumniControllers.ts index a364bcc..6390748 100644 --- a/server/controllers/alumniControllers.ts +++ b/server/controllers/alumniControllers.ts @@ -8,7 +8,7 @@ const getAllAlumniData = async ( next: NextFunction ) => { const page = parseInt(req.query.page as string) || 1; - const limit = parseInt(req.query.limit as string) || 20; + const limit = parseInt(req.query.limit as string) || 10; const nameSearch = (req.query.name as string) || ""; const companySearch = (req.query.company as string) || ""; @@ -32,7 +32,6 @@ const getAllAlumniData = async ( totalPages: Math.ceil(count / limit), currentPage: page, }); - } catch (error) { console.log("Awesome error handling"); }