Client - display only active sports (+ workout sport) on workout edition

fix #129
This commit is contained in:
Sam
2022-01-01 18:33:06 +01:00
parent f8df393d2d
commit be0ac9b238
17 changed files with 143 additions and 61 deletions

View File

@ -1,4 +1,4 @@
import { ISport, ITranslatedSport } from '@/types/sports'
import { ISport, ITranslatedSport, TActiveStatus } from '@/types/sports'
import { IWorkout } from '@/types/workouts'
// TODO: allow user to change colors
@ -39,16 +39,14 @@ const sortSports = (a: ITranslatedSport, b: ITranslatedSport): number => {
export const translateSports = (
sports: ISport[],
t: CallableFunction,
onlyActive = false,
userSports: number[] | null = null
activeStatus: TActiveStatus = 'all',
sportsToInclude: number[] = []
): ITranslatedSport[] =>
sports
.filter((sport) =>
onlyActive
? userSports === null
? sport.is_active_for_user
: userSports.includes(sport.id) || sport.is_active
: true
activeStatus === 'all'
? true
: sportsToInclude.includes(sport.id) || sport[activeStatus]
)
.map((sport) => ({
...sport,