hensei-web/utils/organizeRaids.tsx
Justin Edmund 247d2a466a Clean up setServerSideProps
Here we extracted the common methods used in pages into utils and included them, getting rid of a lot of duplicate code in the process.
2022-12-22 21:43:09 -08:00

30 lines
554 B
TypeScript

export default (raids: Raid[]) => {
console.log('organizing raids...')
// Set up empty raid for "All raids"
const all = {
id: '0',
name: {
en: 'All raids',
ja: '全て',
},
slug: 'all',
level: 0,
group: 0,
element: 0,
}
const numGroups = Math.max.apply(
Math,
raids.map((raid) => raid.group)
)
let groupedRaids = []
for (let i = 0; i <= numGroups; i++) {
groupedRaids[i] = raids.filter((raid) => raid.group == i)
}
return {
raids: raids,
sortedRaids: groupedRaids,
}
}