Skip to content

Commit acab1b2

Browse files
authored
Merge pull request #145 from aspc/feature/ASPC-45-engage-search
ASPC-45: Add search bar to Engage Events popup in open forum dashbaord
2 parents 974f6cf + b6b1ebd commit acab1b2

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

frontend/src/components/ui/ForumDashboard.tsx

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Link from 'next/link';
55
import Loading from '@/components/Loading';
66
import { StaffMember, Event, ForumEvent } from '@/types';
77
import { FormattedReviewText, formatReviewText } from '@/utils/textFormatting';
8+
import { useMemo } from 'react';
89

910
const ForumDashboard = () => {
1011
const { loading } = useAuth();
@@ -17,6 +18,7 @@ const ForumDashboard = () => {
1718
const [isEngagePopupOpen, setIsEngagePopupOpen] = useState(false);
1819
const [isEngageLoading, setIsEngageLoading] = useState(false);
1920
const [engageEvents, setEngageEvents] = useState<Event[]>([]);
21+
const [searchTerm, setSearchTerm] = useState<string>('');
2022

2123
// Form state
2224
const [title, setTitle] = useState<string>('');
@@ -135,6 +137,18 @@ const ForumDashboard = () => {
135137
}
136138
}, [isEngagePopupOpen]);
137139

140+
// Filter Engage events based on search term
141+
const filteredEngageEvents = useMemo(() => {
142+
const term = searchTerm.toLowerCase();
143+
return engageEvents.filter(
144+
(event) =>
145+
event.name.toLowerCase().includes(term) ||
146+
(event.location &&
147+
event.location.toLowerCase().includes(term)) ||
148+
(event.host && event.host.toLowerCase().includes(term))
149+
);
150+
}, [searchTerm, engageEvents]);
151+
138152
const resetForm = () => {
139153
setTitle('');
140154
setDescription('');
@@ -401,22 +415,37 @@ const ForumDashboard = () => {
401415
Import from Engage
402416
</h2>
403417
<button
404-
onClick={() => setIsEngagePopupOpen(false)}
418+
onClick={() => {
419+
setIsEngagePopupOpen(false);
420+
setSearchTerm('');
421+
}}
405422
className="text-gray-500 hover:text-gray-700 text-2xl leading-none"
406423
>
407424
×
408425
</button>
409426
</div>
410427

411-
{/* List of Events */}
428+
<div className="mb-4">
429+
<input
430+
type="text"
431+
placeholder="Search events by name, location, or host"
432+
className="w-full p-3 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 transition"
433+
value={searchTerm}
434+
onChange={(e) =>
435+
setSearchTerm(e.target.value)
436+
}
437+
/>
438+
</div>
439+
440+
{/* List of events */}
412441
<div className="flex-1 flex flex-col overflow-y-auto">
413442
{isEngageLoading ? (
414443
<div className="flex-1 flex items-center justify-center">
415444
<div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-blue-500"></div>
416445
</div>
417-
) : engageEvents.length > 0 ? (
446+
) : filteredEngageEvents.length > 0 ? (
418447
<ul className="space-y-4">
419-
{engageEvents.map(
448+
{filteredEngageEvents.map(
420449
(event: Event, index) => (
421450
<li
422451
key={index}
@@ -485,16 +514,22 @@ const ForumDashboard = () => {
485514
setLocation(
486515
event.location
487516
);
517+
488518
setEventDate(
489519
toDatetimeLocal(
490520
new Date(
491521
event.start
492522
).toISOString()
493523
)
494524
);
525+
495526
setIsEngagePopupOpen(
496527
false
497528
);
529+
530+
setSearchTerm(
531+
''
532+
);
498533
}}
499534
className="bg-blue-500 text-white px-3 py-1.5 rounded hover:bg-blue-600 text-sm"
500535
>
@@ -517,7 +552,10 @@ const ForumDashboard = () => {
517552
{/* Footer */}
518553
<div className="flex justify-end mt-4">
519554
<button
520-
onClick={() => setIsEngagePopupOpen(false)}
555+
onClick={() => {
556+
setIsEngagePopupOpen(false);
557+
setSearchTerm('');
558+
}}
521559
className="bg-gray-300 text-gray-800 px-4 py-2 rounded hover:bg-gray-400"
522560
>
523561
Close

0 commit comments

Comments
 (0)