Skip to content

Commit

Permalink
Merge pull request #52 from ecss-soton/society-order-fix
Browse files Browse the repository at this point in the history
fix ordering of members
  • Loading branch information
casperUoS authored Sep 3, 2024
2 parents d6f0d80 + 3fdfe07 commit 186b6ec
Show file tree
Hide file tree
Showing 4 changed files with 1,095 additions and 872 deletions.
38 changes: 37 additions & 1 deletion src/app/_components/CollectionArchive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,34 @@ export const CollectionArchive: React.FC<Props> = props => {
{ encode: false },
)

const societyPositionOrder = [
'President',
'Vice President',
'Vice President Engagement',
'Vice President Operations',
'Secretary',
'Treasurer',
'Events Officer',
'Welfare Officer',
'Web Officer',
'Social Secretary',
'Sports Officer',
'Marketing Officer',
'Hackathon Officer',
'Industry Officer',
'Academic Secretary',
'Gamesmaster',
'Games Officer',
'International Representative',
'Masters Rep',
'Postgraduate Representative',
'Publicity Officer',
'Sports Representative',
'Staff Representative',
'Unknown Role',
'Webmaster',
]

const makeRequest = async () => {
try {
const req = await fetch(
Expand All @@ -141,9 +169,17 @@ export const CollectionArchive: React.FC<Props> = props => {
const json = await req.json()
clearTimeout(timer)

const { docs } = json as { docs: (Post | Project)[] }
let { docs } = json as { docs: (Post | Project | Committee | Sponsor | Society)[] }

if (docs && Array.isArray(docs)) {
if (relationTo === 'committee') {
docs = docs.sort((a, b) => {
const posA = 'position' in a ? a.position : ''
const posB = 'position' in b ? b.position : ''
return societyPositionOrder.indexOf(posA) - societyPositionOrder.indexOf(posB)
})
}

setResults(json)
setIsLoading(false)
if (typeof onResultChange === 'function') {
Expand Down
28 changes: 14 additions & 14 deletions src/payload/collections/Committee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ const Committee: CollectionConfig = {
label: 'Position',
type: 'select',
options: [
'Academic Secretary',
'President',
'Vice President',
'Vice President Engagement',
'Vice President Operations',
'Secretary',
'Treasurer',
'Events Officer',
'Gamesmaster',
'Games Officer',
'Welfare Officer',
'Web Officer',
'Social Secretary',
'Sports Officer',
'Marketing Officer',
'Hackathon Officer',
'Industry Officer',
'Academic Secretary',
'Gamesmaster',
'Games Officer',
'International Representative',
'Marketing Officer',
'Masters Rep',
'Postgraduate Representative',
'President',
'Publicity Officer',
'Secretary',
'Social Secretary',
'Sports Officer',
'Sports Representative',
'Staff Representative',
'Treasurer',
'Unknown Role',
'Vice President',
'Vice President Engagement',
'Vice President Operations',
'Webmaster',
'Web Officer',
'Welfare Officer',
],
},
{
Expand Down
Loading

0 comments on commit 186b6ec

Please sign in to comment.