-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathProgramsList.tsx
More file actions
113 lines (100 loc) · 3.78 KB
/
Copy pathProgramsList.tsx
File metadata and controls
113 lines (100 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"use client";
import { useState, useMemo, useCallback } from "react";
import { Program } from "@/data/oss-programs/types";
import { SearchInput, TagFilter, ProgramCard } from "@/components/oss-programs";
import StatusFilter from "@/components/oss-programs/StatusFilter";
import { matchesStatusFilters } from "@/utils/date-utils";
interface ProgramsListProps {
programs: Program[];
tags: string[];
}
/**
* Filters OSS programs based on search query, selected tags, and selected statuses.
* Handles status filtering based on application dates with special handling for TBD status.
*/
export default function ProgramsList({ programs, tags }: ProgramsListProps) {
const [searchQuery, setSearchQuery] = useState("");
const [selectedTags, setSelectedTags] = useState<string[]>([]);
const [selectedStatuses, setSelectedStatuses] = useState<string[]>([]);
// Memoize handlers to prevent child re-renders
/**
* Updates search query state when user types in search input
* @param value - The new search query string
*/
const handleSearchChange = useCallback((value: string) => {
setSearchQuery(value);
}, []);
/**
* Updates selected tags state when user adds/removes tags
* @param newTags - Array of currently selected tag strings
*/
const handleTagsChange = useCallback((newTags: string[]) => {
setSelectedTags(newTags);
}, []);
/**
* Updates selected statuses state when user adds/removes status filters
* @param newStatuses - Array of currently selected status strings
*/
const handleStatusesChange = useCallback((newStatuses: string[]) => {
setSelectedStatuses(newStatuses);
}, []);
const filteredPrograms = useMemo(() => {
return programs.filter((program) => {
const matchesSearch =
program.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
program.tags.some((tag) =>
tag.toLowerCase().includes(searchQuery.toLowerCase())
);
const matchesTags =
selectedTags.length === 0 ||
selectedTags.every((tag) => program.tags.includes(tag));
const matchesStatuses = matchesStatusFilters(
program.applicationStart,
program.applicationEnd,
selectedStatuses
);
return matchesSearch && matchesTags && matchesStatuses;
});
}, [programs, searchQuery, selectedTags, selectedStatuses]);
return (
<div className="min-h-full w-[99vw] lg:w-[80vw] bg-dash-base text-white p-4 md:p-8 lg:p-12 overflow-x-hidden">
<div className="max-w-6xl mx-auto w-full min-w-0">
{/* Header Section */}
<div className="flex flex-col gap-8 mb-12 min-w-0">
<h1 className="text-3xl md:text-4xl font-bold text-text-primary break-words">
OSS Programs
</h1>
<div className="flex flex-col md:flex-row gap-4 w-full min-w-0">
<SearchInput
value={searchQuery}
onChange={handleSearchChange}
placeholder="Search programs..."
/>
<TagFilter
tags={tags}
selectedTags={selectedTags}
onTagsChange={handleTagsChange}
/>
<StatusFilter
statuses={["Active","Upcoming","TBD","Historical"]}
selectedStatuses={selectedStatuses}
onStatusesChange={handleStatusesChange}
/>
</div>
</div>
{/* List Section */}
<div className="flex flex-col gap-2 md:gap-3 min-w-0">
{filteredPrograms.length === 0 ? (
<div className="text-center py-20 text-text-muted">
No programs found matching your criteria.
</div>
) : (
filteredPrograms.map((program) => (
<ProgramCard key={program.slug} program={program} />
))
)}
</div>
</div>
</div>
);
}