hensei-web/utils/extractFilters.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

26 lines
855 B
TypeScript

import { elements, allElement } from '~utils/Element'
export default (query: { [index: string]: string }, raids: Raid[]) => {
// Extract recency filter
const recencyParam: number = parseInt(query.recency)
// Extract element filter
const elementParam: string = query.element
const teamElement: TeamElement | undefined =
elementParam === 'all'
? allElement
: elements.find(
(element) => element.name.en.toLowerCase() === elementParam
)
// Extract raid filter
const raidParam: string = query.raid
const raid: Raid | undefined = raids.find((r) => r.slug === raidParam)
// Return filter object
return {
recency: recencyParam && recencyParam !== -1 ? recencyParam : undefined,
element: teamElement && teamElement.id > -1 ? teamElement.id : undefined,
raid: raid ? raid.id : undefined,
}
}