Added class councils

This commit is contained in:
Michael Fatemi 2021-01-05 23:59:39 -05:00
parent 2ef9c7ef46
commit 1cbe64af0c

View File

@ -1,20 +1,60 @@
import React from 'react';
import Hero from '../components/Hero';
import MemberRow from '../components/MemberRow';
import PrimaryHeader from '../components/PrimaryHeader';
import useQuery from '../hooks/useQuery';
import sortCommittee from '../lib/sortCommittee';
const roleOrder = [
'President',
'Vice-President',
'Treasurer',
'Secretary',
'Historian',
'Senator',
'Sponsor',
];
export default function ClassCouncil() {
let members =
useQuery<SGA.MemberDocument[]>(
`*[_type == 'member' && role == 'class'] | order (year desc)`
) ?? [];
let members = useQuery<SGA.MemberDocument[]>(
`*[_type == 'member' && committee == 'class'] | order (year desc)`
);
if (!members) {
return null;
}
console.log(members);
let years: [string, SGA.MemberDocument[]][] = [];
let currentYearMembers: SGA.MemberDocument[] = [];
let currentYear = '';
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 = [];
}
currentYear = member.year;
}
currentYearMembers.push(member);
}
console.log(years);
return (
<>
<Hero heading='Class Council' />
<main>
{members.map((member) => (
<MemberRow key={member._id} member={member}></MemberRow>
{years.map(([year, members]) => (
<>
<PrimaryHeader>Class Council {year}</PrimaryHeader>
{members.map((member) => (
<MemberRow key={member._id} member={member}></MemberRow>
))}
</>
))}
</main>
</>