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

@ -189,7 +189,7 @@
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
)
const translatedSports: ComputedRef<ITranslatedSport[]> = computed(() =>
translateSports(sports.value, t, true, user.value.sports_list)
translateSports(sports.value, t, 'is_active', user.value.sports_list)
)
const loading = computed(
() => store.getters[AUTH_USER_STORE.GETTERS.USER_LOADING]

View File

@ -267,8 +267,8 @@
translateSports(
props.sports,
t,
true,
workout.value.id ? [workout.value.sport_id] : null
'is_active_for_user',
workout.value.id ? [workout.value.sport_id] : []
)
)
const appConfig: ComputedRef<TAppConfig> = computed(

View File

@ -17,3 +17,5 @@ export interface ISportPayload {
id: number
isActive: boolean
}
export type TActiveStatus = 'is_active' | 'is_active_for_user' | 'all'

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,