Client - display only active sports (+ workout sport) on workout edition
fix #129
This commit is contained in:
@ -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]
|
||||
|
@ -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(
|
||||
|
@ -17,3 +17,5 @@ export interface ISportPayload {
|
||||
id: number
|
||||
isActive: boolean
|
||||
}
|
||||
|
||||
export type TActiveStatus = 'is_active' | 'is_active_for_user' | 'all'
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user