From 957b0e485ce67d298ec3188e4866716225c00221 Mon Sep 17 00:00:00 2001 From: amamc Date: Tue, 21 May 2024 22:35:11 -0700 Subject: [PATCH 1/3] Updated the route --- src/app/api/job-posting/route.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/api/job-posting/route.js b/src/app/api/job-posting/route.js index e42a329..7869958 100644 --- a/src/app/api/job-posting/route.js +++ b/src/app/api/job-posting/route.js @@ -3,6 +3,7 @@ import { connectMongoDB } from '@/libs/mongodb'; import posting from '@/app/api/posting'; import mongoose from 'mongoose'; import { + getPaginationParams, fetchJobPostings, parseSortCriteria, parseFilterCriteria, @@ -10,6 +11,7 @@ import { export async function GET(req) { try { + const { skip, pageSize } = getPaginationParams(req); const email = req.nextUrl.searchParams.get('email'); const sortBy = req.nextUrl.searchParams.get('sort'); const etFilters = req.nextUrl.searchParams.getAll('et'); @@ -27,8 +29,6 @@ export async function GET(req) { } const siteCriteria = { email }; - const skip = 0; - const pageSize = 0; // Query job postings with pagination and sort criteria if provided const jobPostings = await fetchJobPostings( From 68218c6712a6d2362c8d09eab551665279788456 Mon Sep 17 00:00:00 2001 From: mai-vu Date: Tue, 21 May 2024 23:30:34 -0700 Subject: [PATCH 2/3] adjusted fetch posting to match new API endpoint implementation --- src/app/admin-panel/home/page.js | 55 ++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/src/app/admin-panel/home/page.js b/src/app/admin-panel/home/page.js index cee8ad6..b157f18 100644 --- a/src/app/admin-panel/home/page.js +++ b/src/app/admin-panel/home/page.js @@ -8,6 +8,8 @@ import jobPostingService from './jobPostingService'; import { useCallback } from 'react'; import Navbar from '@/components/ui/navbar'; +const MAX_PAGES = 999; + // Define your component export default function Home() { // State to store the list of job postings @@ -41,31 +43,52 @@ export default function Home() { }, []); const [showForm, setShowForm] = useState(false); - // Function to fetch job postings from the API const fetchJobPostings = useCallback(async () => { try { setLoading(true); - const sortCriteria = JSON.stringify({ _id: -1 }); - const apiURL = `${JOB_POSTING_API_URL}?email=${user.email}&sort=${sortCriteria}`; - const response = await fetch(apiURL, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }); + let page = 1; + let jobPostingsArray = []; - if (response.ok) { - const res = await response.json(); - setJobPostings(res.jobPostings); - } else { - console.error('Failed to fetch job postings:', response.statusText); + while (page <= MAX_PAGES) { + const apiURL = `${JOB_POSTING_API_URL}?page_num=${page}&email=${user.email}`; + const response = await fetch(apiURL, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }); + + if (response.ok) { + if (response.status === 204) { + // If the API returns no content status, break the loop + break; + } + + const res = await response.json(); + const jobPostings = res.jobPostings; + + if (jobPostings.length === 0) { + // If no job postings found, break the loop + break; + } else { + // Add the fetched job postings to the array + jobPostingsArray = [...jobPostingsArray, ...jobPostings]; + page++; // Increment the page number for the next request + } + } else { + console.error('Failed to fetch job postings:', response.statusText); + break; + } } + + // Set the job postings array in state + setJobPostings(jobPostingsArray); } catch (error) { console.error('Error fetching job postings:', error); } finally { setLoading(false); } - }, [user]); + }, [user, JOB_POSTING_API_URL]); useEffect(() => { fetchUser(); @@ -75,7 +98,7 @@ export default function Home() { if (user) { fetchJobPostings(); } - }, [user]); + }, [user, fetchJobPostings]); // Function to handle deletion of job posting const handleDelete = async jobPostingId => { From 1e6dfdb3af7752ddff2f8d128ebdf1a82779033c Mon Sep 17 00:00:00 2001 From: mai-vu Date: Tue, 21 May 2024 23:31:10 -0700 Subject: [PATCH 3/3] deleted unused component --- src/components/ui/checkbox.jsx | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 src/components/ui/checkbox.jsx diff --git a/src/components/ui/checkbox.jsx b/src/components/ui/checkbox.jsx deleted file mode 100644 index 413cb17..0000000 --- a/src/components/ui/checkbox.jsx +++ /dev/null @@ -1,25 +0,0 @@ -'use client'; - -import * as React from 'react'; -import * as CheckboxPrimitive from '@radix-ui/react-checkbox'; -import { Check } from 'lucide-react'; - -import { cn } from '@/libs/utils'; - -const Checkbox = React.forwardRef(({ className, ...props }, ref) => ( - - - - - -)); -Checkbox.displayName = CheckboxPrimitive.Root.displayName; - -export { Checkbox };