-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathOfficers.js
More file actions
103 lines (92 loc) · 3.03 KB
/
Officers.js
File metadata and controls
103 lines (92 loc) · 3.03 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
import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import "../CSS/Officers.css";
import ProfileCard from "./profileCard";
const Officers = () => {
const SHOW_OFFICER_APPLICATION = false;
const APPLICATION_YEAR = "2025-2026";
const [selectedYear, setSelectedYear] = useState(null);
const [teamMembers, setTeamMembers] = useState([]);
const [yearOptions, setYearOptions] = useState([]);
const yearSetup = async () => {
const currentDate = new Date();
const availableYears = [];
// officer data will be out at the end of June, this will update beginning of July
const defaultToThisYear = currentDate.getMonth() > 5;
// check if officer json data for the current year should be added
// and exists first, then add previous years back to 2022
for (let year = currentDate.getFullYear(); year >= 2022; year--) {
if (defaultToThisYear || year !== currentDate.getFullYear()) {
try {
await import(`../Data/officers${year}.json`);
availableYears.push(year);
} catch (error) {
// officer data for this year won't be added
console.log("Error loading year:", error);
}
}
}
// set year options and default year to most recent available year
setYearOptions(availableYears);
setSelectedYear(availableYears[0]);
};
useEffect(() => {
yearSetup();
}, []); // only runs after initial render
useEffect(() => {
const loadTeamMembers = async () => {
try {
const members = await import(`../Data/officers${selectedYear}.json`);
setTeamMembers(members.default);
} catch (error) {
console.error("Error loading team members:", error);
setTeamMembers([]);
}
};
loadTeamMembers();
}, [selectedYear]);
const handleYearChange = (year) => {
setSelectedYear(year);
};
return (
<div>
<div>
<div className="about-message-section">
<h1>Our Officers</h1>
</div>
<div className="Officer-content">
{/* CONTROLLED BY FLAG ABOVE */}
{SHOW_OFFICER_APPLICATION && (
<div className="officer-application-link">
<Link to="/OfficerApplication">
<button className="apply-button">
Apply to be an Officer for {APPLICATION_YEAR}!
</button>
</Link>
</div>
)}
</div>
<nav className="officer-sidebar">
<h2>Year</h2>
<ul>
{yearOptions.map((year) => (
<li key={year}>
<button
onClick={() => handleYearChange(year)}
className={selectedYear === year ? "selected" : ""}
>
{year}
</button>
</li>
))}
</ul>
</nav>
<div className="officer-info">
<h2>{selectedYear} Officers</h2>
<ProfileCard info={teamMembers} />
</div>
</div>
</div>
);
};
export default Officers;