mirror of
https://github.com/tjsga/tj-sga-website-react.git
synced 2025-04-03 20:00:17 -04:00
Added class councils
This commit is contained in:
parent
2ef9c7ef46
commit
1cbe64af0c
|
@ -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>
|
||||
</>
|
||||
|
|
Loading…
Reference in New Issue
Block a user