Skip to content

Commit 0be5ca9

Browse files
committed
fix display of dropdown filter
1 parent da8c920 commit 0be5ca9

3 files changed

Lines changed: 2921 additions & 3464 deletions

File tree

src/components/Collaboration/Collaboration.jsx

Lines changed: 24 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@ function Collaboration() {
1818
const [totalPages, setTotalPages] = useState(1);
1919
const [categories, setCategories] = useState([]);
2020
const [showCategoryDropdown, setShowCategoryDropdown] = useState(false);
21-
const [showPositionDropdown, setShowPositionDropdown] = useState(false);
2221
const [summaries, setSummaries] = useState(null);
23-
// const [positions, setPositions] = useState([]);
2422
const [selectedPosition, setSelectedPosition] = useState('');
25-
const [selectedCategory, setSelectedCategory] = useState('');
26-
const categoryRef = useRef(null);
27-
const positionRef = useRef(null);
23+
2824
const dropdownRef = useRef(null);
29-
// Modal
3025
const [selectedJob, setSelectedJob] = useState(null);
3126

3227
const darkMode = useSelector(state => state.theme.darkMode);
@@ -64,18 +59,6 @@ function Collaboration() {
6459
}
6560
};
6661

67-
/* ================= FETCH CATEGORIES ================= */
68-
const fetchPositions = async () => {
69-
try {
70-
const res = await fetch(`${ApiEndpoint}/jobs/positions`);
71-
const data = await res.json();
72-
73-
setPositions((data.positions || []).sort((a, b) => a.localeCompare(b)));
74-
} catch {
75-
toast.error('Error fetching positions');
76-
}
77-
};
78-
7962
/* ================= EFFECTS ================= */
8063
useEffect(() => {
8164
fetchCategories();
@@ -84,8 +67,9 @@ function Collaboration() {
8467
useEffect(() => {
8568
setCurrentPage(1);
8669
fetchJobs();
87-
}, [searchTerm, selectedCategory]);
70+
}, [searchTerm, categoriesSelected]);
8871

72+
/* ================= FILTERED JOBS ================= */
8973
const filteredJobs = useMemo(() => {
9074
if (!selectedPosition) return allJobs;
9175

@@ -94,22 +78,7 @@ function Collaboration() {
9478
);
9579
}, [allJobs, selectedPosition]);
9680

97-
const positions = useMemo(() => {
98-
const uniquePositions = [
99-
...new Set(
100-
allJobs
101-
.filter(
102-
job =>
103-
!selectedCategory || job.category?.toLowerCase() === selectedCategory.toLowerCase(),
104-
)
105-
.map(job => job.position || job.title)
106-
.filter(Boolean),
107-
),
108-
];
109-
110-
return uniquePositions.sort((a, b) => a.localeCompare(b));
111-
}, [allJobs, selectedCategory]);
112-
81+
/* ================= PAGINATION ================= */
11382
useEffect(() => {
11483
const start = (currentPage - 1) * ADS_PER_PAGE;
11584
setJobAds(filteredJobs.slice(start, start + ADS_PER_PAGE));
@@ -118,28 +87,25 @@ function Collaboration() {
11887
setTotalPages(Math.max(calculatedPages, 1));
11988
}, [filteredJobs, currentPage]);
12089

90+
/* ================= ESC CLOSE MODAL ================= */
12191
useEffect(() => {
12292
if (!selectedJob) return;
12393
const esc = e => e.key === 'Escape' && setSelectedJob(null);
12494
window.addEventListener('keydown', esc);
12595
return () => window.removeEventListener('keydown', esc);
12696
}, [selectedJob]);
12797

98+
/* ================= CLICK OUTSIDE DROPDOWN ================= */
12899
useEffect(() => {
129100
const handleClickOutside = event => {
130101
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
131102
setShowCategoryDropdown(false);
132103
}
133104
};
134105

135-
if (showCategoryDropdown) {
136-
document.addEventListener('mousedown', handleClickOutside);
137-
}
138-
139-
return () => {
140-
document.removeEventListener('mousedown', handleClickOutside);
141-
};
142-
}, [showCategoryDropdown]);
106+
document.addEventListener('mousedown', handleClickOutside);
107+
return () => document.removeEventListener('mousedown', handleClickOutside);
108+
}, []);
143109

144110
/* ================= HANDLERS ================= */
145111
const handleSubmit = e => {
@@ -148,7 +114,7 @@ function Collaboration() {
148114
};
149115

150116
const handleClearAllFilters = () => {
151-
setSelectedCategory('');
117+
setCategoriesSelected([]);
152118
setSelectedPosition('');
153119
setSearchTerm('');
154120
setQuery('');
@@ -183,7 +149,7 @@ function Collaboration() {
183149

184150
{summaries.jobs?.length ? (
185151
summaries.jobs.map(job => (
186-
<div key={job._id} className="job-summary-item">
152+
<div key={job._id}>
187153
<h4>
188154
<a href={job.jobDetailsLink}>{job.title}</a>
189155
</h4>
@@ -225,11 +191,7 @@ function Collaboration() {
225191
</form>
226192

227193
<div ref={dropdownRef} style={{ position: 'relative' }}>
228-
<button
229-
type="button"
230-
onClick={() => setShowCategoryDropdown(p => !p)}
231-
aria-expanded={showCategoryDropdown}
232-
>
194+
<button type="button" onClick={() => setShowCategoryDropdown(p => !p)}>
233195
Select Categories ▼
234196
</button>
235197

@@ -257,20 +219,17 @@ function Collaboration() {
257219
{/* HEADINGS */}
258220
<div className={styles.headings}>
259221
<h1 className={styles.jobHead}>LIKE TO WORK WITH US? APPLY NOW!</h1>
260-
<a className="btn" href="https://www.onecommunityglobal.org/collaboration/">
261-
← Return to One Community Collaboration Page
262-
</a>
263222
</div>
264223

265224
{/* QUERY TEXT */}
266-
<div className="job-queries">
225+
<div>
267226
<p>
268227
{searchTerm
269228
? `Listing results for '${searchTerm}'`
270229
: selectedPosition
271-
? `Listing results for '${selectedPosition}' in '${selectedCategory}'`
272-
: selectedCategory
273-
? `Listing results for '${selectedCategory}'`
230+
? `Listing results for '${selectedPosition}'`
231+
: categoriesSelected.length
232+
? 'Listing results for selected categories'
274233
: 'Listing all job ads.'}
275234
</p>
276235
<button className="btn btn-secondary" onClick={handleShowSummaries}>
@@ -279,10 +238,13 @@ function Collaboration() {
279238
</div>
280239

281240
{/* FILTER CHIPS */}
282-
{(selectedCategory || selectedPosition) && (
241+
{(categoriesSelected.length > 0 || selectedPosition) && (
283242
<div className={styles.jobQueries}>
284-
{selectedCategory && <span className={styles.chip}>{selectedCategory}</span>}
285-
{selectedPosition && <span className={styles.chip}>{selectedPosition}</span>}
243+
{categoriesSelected.map(cat => (
244+
<span key={cat} className={styles.chip}>
245+
{cat}
246+
</span>
247+
))}
286248
<button className={styles.clearAllButton} onClick={handleClearAllFilters}>
287249
Clear All
288250
</button>
@@ -328,14 +290,9 @@ function Collaboration() {
328290

329291
{/* MODAL */}
330292
{selectedJob && (
331-
<div className={styles.modalOverlay} aria-hidden="true">
293+
<div className={styles.modalOverlay}>
332294
<div className={styles.modal}>
333-
<button
334-
type="button"
335-
className={styles.closeButton}
336-
aria-label="Close role details"
337-
onClick={() => setSelectedJob(null)}
338-
>
295+
<button className={styles.closeButton} onClick={() => setSelectedJob(null)}>
339296
×
340297
</button>
341298

@@ -344,20 +301,6 @@ function Collaboration() {
344301
<strong>Category:</strong> {selectedJob.category}
345302
</p>
346303
<p>{selectedJob.description}</p>
347-
348-
<div className={styles.modalActions}>
349-
<a
350-
className="btn btn-secondary"
351-
href={`https://www.onecommunityglobal.org/collaboration/seeking-${slugify(
352-
selectedJob.category,
353-
)}`}
354-
>
355-
View Full Details
356-
</a>
357-
<button className="btn btn-primary" disabled>
358-
Apply Now
359-
</button>
360-
</div>
361304
</div>
362305
</div>
363306
)}

src/components/Collaboration/Collaboration.module.css

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@
113113
background-color: #84cc16;
114114
}
115115

116+
.dropdownItem input {
117+
width: 16px;
118+
height: 16px;
119+
flex-shrink: 0;
120+
}
121+
116122
.dark .navbar button,
117123
.dark .navbar input {
118124
color: #020617;
@@ -148,17 +154,15 @@
148154
position: absolute;
149155
top: calc(100% + 6px);
150156
left: 0;
151-
width: max-content;
152-
max-width: min(100%, 280px);
153-
min-width: 180px;
154-
max-height: 300px;
157+
width: 240px;
158+
max-height: 280px;
155159
overflow-y: auto;
156160
background-color: #fff;
157-
padding: 8px 0;
158161
border-radius: 8px;
159162
border: 1px solid #ccc;
160-
z-index: 2000;
161-
box-shadow: 0 8px 20px rgb(0 0 0 / 20%);
163+
z-index: 9999;
164+
box-shadow: 0 8px 20px rgb(0 0 0 / 15%);
165+
animation: dropdownFade 0.15s ease-in-out;
162166
}
163167

164168
.dropdownWrapper {
@@ -168,19 +172,13 @@
168172
}
169173

170174
.dropdownItem {
171-
width: 100%;
172-
text-align: left;
175+
display: flex;
176+
align-items: center;
177+
gap: 10px;
173178
padding: 10px 14px;
174179
cursor: pointer;
175180
font-size: 14px;
176-
background: transparent;
177-
border: none;
178-
outline: none;
179181
color: #333;
180-
transition: background 0.2s ease;
181-
white-space: nowrap;
182-
overflow: hidden;
183-
text-overflow: ellipsis;
184182
}
185183

186184
.dropdownItem:hover {

0 commit comments

Comments
 (0)