Skip to content

Commit

Permalink
Updated the Members Filtering and Sorting on the CC About page
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavberi committed May 27, 2024
1 parent e6afe10 commit 905a406
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 19 deletions.
19 changes: 18 additions & 1 deletion src/app/about/clubs-council/content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,24 @@ The primary aim of the Clubs Council is to ensure that all student-driven organi
{props.ccMembers}

<Stack direction="row" pt={2} mb={2} mt={3}>
### Tech Team
### Advisory Board
<Box sx={{ flexGrow: 1 }} />
<Button
variant="none"
color="secondary"
component={Link}
href="/about/clubs-council/cc-members"
>
<Typography variant="button" color="text.primary">
View all
</Typography>
<Icon variant="chevron-right" />
</Button>
</Stack>
{props.advisoryMembers}

<Stack direction="row" pt={2} mb={2} mt={3}>
### SLC-CC Tech Team
<Box sx={{ flexGrow: 1 }} />
<Button
variant="none"
Expand Down
103 changes: 86 additions & 17 deletions src/app/about/clubs-council/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import LocalUsersGrid from "components/users/LocalUsersGrid";

import {
executiveBoardWords,
advisorWords,
techTeamWords,
extendedMembersWords,
} from "constants/ccMembersFilterWords";

export const metadata = {
Expand All @@ -28,13 +30,46 @@ export default async function ClubsCouncil() {
const executiveBoardRoles = filterRoles(
roles,
executiveBoardWords,
techTeamWords,
techTeamWords
);
const newMember = { ...member, roles: executiveBoardRoles };
return newMember;
})
?.filter((member) => {
return member.roles.length > 0;
})
?.sort((a, b) => {
const roleNameA = a.roles[0]?.name.toLowerCase();
const roleNameB = b.roles[0]?.name.toLowerCase();
if (roleNameA < roleNameB) {
return -1;
}
if (roleNameA > roleNameB) {
return 1;
}
return 0;
});

const advisoryMembers = members
?.map((member) => {
const { roles } = member;
const advisorWordsCombined = advisorWords.concat(executiveBoardWords);
const advisorRoles = filterRoles(
roles,
advisorWordsCombined,
techTeamWords
);
const newMember = { ...member, roles: advisorRoles };
return newMember;
})
?.filter((member) => {
if (member.roles.length <= 0) return false;

const role0 = member.roles[0]?.name.toLowerCase();
const matchesAdvisoryFilterWords = advisorWords.some((word) =>
role0.includes(word)
);
return matchesAdvisoryFilterWords;
});

const techMembers = members
Expand All @@ -46,14 +81,31 @@ export default async function ClubsCouncil() {
})
?.filter((member) => {
return member.roles.length > 0;
})
?.sort((a, b) => {
const roleNameA = a.roles[0]?.name.toLowerCase();
const roleNameB = b.roles[0]?.name.toLowerCase();
if (roleNameA.includes("lead") && !roleNameB.includes("lead")) {
return -1;
}
if (roleNameB.includes("lead") && !roleNameA.includes("lead")) {
return 1;
}
if (roleNameA.includes("advisor") && !roleNameB.includes("advisor")) {
return 1;
}
if (roleNameB.includes("advisor") && !roleNameA.includes("advisor")) {
return -1;
}

return 0;
});

const extendedMembers = members
?.map((member) => {
const { roles } = member;
const newWords = executiveBoardWords.concat(techTeamWords);
const techTeamRoles = filterRoles(roles, [], newWords);
const newMember = { ...member, roles: techTeamRoles };
const extendedMembersRoles = filterRoles(roles, extendedMembersWords);
const newMember = { ...member, roles: extendedMembersRoles };
return newMember;
})
?.filter((member) => {
Expand All @@ -68,6 +120,11 @@ export default async function ClubsCouncil() {
<LocalUsersGrid users={executiveMembers} />
) : null
}
advisoryMembers={
advisoryMembers?.length ? (
<LocalUsersGrid users={advisoryMembers} />
) : null
}
techMembers={
techMembers?.length ? <LocalUsersGrid users={techMembers} /> : null
}
Expand All @@ -87,27 +144,39 @@ const filterRoles = (roles, filterWords, unfilterWords = []) => {
const { name, endYear } = role;
const lowercaseName = name.toLowerCase();
const matchesFilterWords = filterWords.some((word) =>
lowercaseName.includes(word),
lowercaseName.includes(word)
);
const matchesUnfilterWords = unfilterWords.some((word) =>
lowercaseName.includes(word),
lowercaseName.includes(word)
);
return matchesFilterWords && !matchesUnfilterWords && endYear === null;
});

// If any roles are filtered, return those that match filterWords and not unfilterWords
if (filteredRoles?.length > 0) {
return roles?.filter((role) => {
const { name, endYear } = role;
const lowercaseName = name.toLowerCase();
const matchesFilterWords = filterWords.some((word) =>
lowercaseName.includes(word),
);
const matchesUnfilterWords = unfilterWords.some((word) =>
lowercaseName.includes(word),
);
return matchesFilterWords && !matchesUnfilterWords;
});
return roles
?.filter((role) => {
const { name } = role;
const lowercaseName = name.toLowerCase();
const matchesFilterWords = filterWords.some((word) =>
lowercaseName.includes(word)
);
const matchesUnfilterWords = unfilterWords.some((word) =>
lowercaseName.includes(word)
);
return matchesFilterWords && !matchesUnfilterWords;
})
?.sort((a, b) => {
// Place roles with endYear=null at the top
if (a.endYear === null && b.endYear !== null) {
return -1;
} else if (a.endYear !== null && b.endYear === null) {
return 1;
} else {
// Sort based on endYear in descending order
return b.endYear - a.endYear;
}
});
} else {
return filteredRoles;
}
Expand Down
4 changes: 3 additions & 1 deletion src/constants/ccMembersFilterWords.jsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const executiveBoardWords = ["secretary", "advisor"];
export const executiveBoardWords = ["secretary"];
export const advisorWords = ["advisor"];
export const techTeamWords = ["tech", "web", "system"];
export const extendedMembersWords = ["design", "pg"];

0 comments on commit 905a406

Please sign in to comment.