From 7030ca67f55382f329add840784950b470e0c994 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Sep 2024 00:00:21 +0100 Subject: [PATCH] Job Search --- app/(guest)/jobs/components/available-jobs.js | 1 + app/(guest)/jobs/components/dropdown.js | 108 ++++++++++++------ app/(guest)/jobs/page.js | 6 +- 3 files changed, 79 insertions(+), 36 deletions(-) diff --git a/app/(guest)/jobs/components/available-jobs.js b/app/(guest)/jobs/components/available-jobs.js index f6e7639..0996281 100644 --- a/app/(guest)/jobs/components/available-jobs.js +++ b/app/(guest)/jobs/components/available-jobs.js @@ -39,6 +39,7 @@ export default function AvailableJobs({ initialData }) { ? '&date=' + searchQueries.date : '' }` + getJobs({ url: jobsInfo?.next_page_url?.slice(33) + searchUrl || '/jobs', setLoading, diff --git a/app/(guest)/jobs/components/dropdown.js b/app/(guest)/jobs/components/dropdown.js index 5b0e870..6a8c15f 100644 --- a/app/(guest)/jobs/components/dropdown.js +++ b/app/(guest)/jobs/components/dropdown.js @@ -1,41 +1,79 @@ -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from '@/components/ui/select' +'use client' +import { useRef, useState, useEffect } from 'react' + +import { ChevronDown } from 'lucide-react' +import { AnimatePresence, motion } from 'framer-motion' export default function DropdownMenu({ value, onChange, list, placeholder }) { + const [open, setOpen] = useState(false) + const dropdownRef = useRef(null) + + // Function to handle clicks outside the dropdown + const handleClickOutside = event => { + if ( + dropdownRef.current && + !dropdownRef.current.contains(event.target) + ) { + setOpen(false) + } + } + + // Add and clean up event listener for clicks outside + useEffect(() => { + if (open) { + document.addEventListener('mousedown', handleClickOutside) + } else { + document.removeEventListener('mousedown', handleClickOutside) + } + + return () => { + document.removeEventListener('mousedown', handleClickOutside) + } + }, [open]) + return ( -
- +
+ + + + {open && ( + + {list.map(item => { + return ( + + ) + })} + + )} +
) } diff --git a/app/(guest)/jobs/page.js b/app/(guest)/jobs/page.js index 22acfb2..b376051 100644 --- a/app/(guest)/jobs/page.js +++ b/app/(guest)/jobs/page.js @@ -52,7 +52,11 @@ export default async function Page({ searchParams }) { const getJobs = async (page, searchParams) => { try { - const url = new URL('https://api.analogueshifts.app/api/jobs') + const url = new URL( + searchParams.search + ? 'https://api.analogueshifts.app/api/job/search' + : 'https://api.analogueshifts.app/api/jobs', + ) // Always include the page query parameter url.searchParams.append('page', page)