Fix class council page bug

This commit is contained in:
Michael Fatemi 2021-01-11 18:55:58 -05:00
parent ca66eb23c8
commit e82a33b0b9

View File

@ -17,7 +17,7 @@ const roleOrder = [
export default function ClassCouncil() {
let members = useQuery<SGA.MemberDocument[]>(
`*[_type == 'member' && committee == 'class'] | order (year desc)`
`*[_type == 'member' && committee == 'class'] | order year`
);
if (!members) {
@ -28,18 +28,26 @@ export default function ClassCouncil() {
let currentYearMembers: SGA.MemberDocument[] = [];
let currentYear = '';
const saveCurrentYear = () => {
// Clear the members of the current year
years.push([currentYear, sortCommittee(currentYearMembers, roleOrder)]);
currentYearMembers = [];
};
for (let member of members) {
if (member.year !== currentYear) {
if (currentYear !== '') {
// Clear the members of the current year
years.push([currentYear, sortCommittee(currentYearMembers, roleOrder)]);
currentYearMembers = [];
saveCurrentYear();
}
currentYear = member.year;
}
currentYearMembers.push(member);
}
if (currentYearMembers.length > 0) {
saveCurrentYear();
}
return (
<>
<Hero heading='Class Council' />