Skip to content

Commit

Permalink
[Filters] Fix age filter
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen committed Aug 22, 2024
1 parent 066a212 commit 2918cfc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions services/frontend/src/components/FilterView/filters/age.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { max, min } from 'lodash'
import { useCallback, useMemo } from 'react'

import { useDebounce } from '@/common/hooks'
Expand Down Expand Up @@ -40,6 +39,12 @@ export const ageFilter = createFilter({

isActive: ({ min, max }) => min !== null || max !== null,

precompute: ({ students }) => {
const ages = students.map(student => getAge(student.birthdate))

return { min: Math.min(...ages), max: Math.max(...ages) }
},

filter: (student, { min, max }) => {
const age = getAge(student.birthdate)

Expand All @@ -54,8 +59,5 @@ export const ageFilter = createFilter({
return true
},

render: props => {
const ages = props.withoutSelf().map(student => getAge(student.birthdate))
return <AgeFilterCard {...props} bounds={{ min: min(ages), max: max(ages) }} />
},
render: (props, { precomputed }) => <AgeFilterCard {...props} bounds={precomputed} />,
})

0 comments on commit 2918cfc

Please sign in to comment.