Client - init store for users workouts displayed in timeline
This commit is contained in:
parent
03241cfe83
commit
5ab293b9e7
@ -10,12 +10,11 @@ import {
|
||||
import { IWorkoutsPayload } from '@/types/workouts'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
export const actions: ActionTree<IWorkoutsState, IRootState> &
|
||||
IWorkoutsActions = {
|
||||
[WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS](
|
||||
const getWorkouts = (
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
): void {
|
||||
payload: IWorkoutsPayload,
|
||||
target: string
|
||||
): void => {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
authApi
|
||||
.get('workouts', {
|
||||
@ -24,7 +23,9 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
context.commit(
|
||||
WORKOUTS_STORE.MUTATIONS.SET_CALENDAR_WORKOUTS,
|
||||
target === 'CALENDAR_WORKOUTS'
|
||||
? WORKOUTS_STORE.MUTATIONS.SET_CALENDAR_WORKOUTS
|
||||
: WORKOUTS_STORE.MUTATIONS.SET_USER_WORKOUTS,
|
||||
res.data.data.workouts
|
||||
)
|
||||
} else {
|
||||
@ -32,5 +33,20 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
|
||||
}
|
||||
})
|
||||
.catch((error) => handleError(context, error))
|
||||
}
|
||||
|
||||
export const actions: ActionTree<IWorkoutsState, IRootState> &
|
||||
IWorkoutsActions = {
|
||||
[WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS](
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
): void {
|
||||
getWorkouts(context, payload, 'CALENDAR_WORKOUTS')
|
||||
},
|
||||
[WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS](
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
): void {
|
||||
getWorkouts(context, payload, 'USER_WORKOUTS')
|
||||
},
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
export enum WorkoutsActions {
|
||||
GET_CALENDAR_WORKOUTS = 'GET_CALENDAR_WORKOUTS',
|
||||
GET_USER_WORKOUTS = 'GET_USER_WORKOUTS',
|
||||
}
|
||||
|
||||
export enum WorkoutsGetters {
|
||||
CALENDAR_WORKOUTS = 'CALENDAR_WORKOUTS',
|
||||
USER_WORKOUTS = 'USER_WORKOUTS',
|
||||
}
|
||||
|
||||
export enum WorkoutsMutations {
|
||||
SET_CALENDAR_WORKOUTS = 'SET_CALENDAR_WORKOUTS',
|
||||
SET_USER_WORKOUTS = 'SET_USER_WORKOUTS',
|
||||
}
|
||||
|
@ -12,4 +12,7 @@ export const getters: GetterTree<IWorkoutsState, IRootState> &
|
||||
[WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS]: (state: IWorkoutsState) => {
|
||||
return state.calendar_workouts
|
||||
},
|
||||
[WORKOUTS_STORE.GETTERS.USER_WORKOUTS]: (state: IWorkoutsState) => {
|
||||
return state.user_workouts
|
||||
},
|
||||
}
|
||||
|
@ -14,4 +14,10 @@ export const mutations: MutationTree<IWorkoutsState> & TWorkoutsMutations = {
|
||||
) {
|
||||
state.calendar_workouts = workouts
|
||||
},
|
||||
[WORKOUTS_STORE.MUTATIONS.SET_USER_WORKOUTS](
|
||||
state: IWorkoutsState,
|
||||
workouts: IWorkout[]
|
||||
) {
|
||||
state.user_workouts = workouts
|
||||
},
|
||||
}
|
||||
|
@ -19,10 +19,15 @@ export interface IWorkoutsActions {
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
): void
|
||||
[WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS](
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
): void
|
||||
}
|
||||
|
||||
export interface IWorkoutsGetters {
|
||||
[WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS](state: IWorkoutsState): IWorkout[]
|
||||
[WORKOUTS_STORE.GETTERS.USER_WORKOUTS](state: IWorkoutsState): IWorkout[]
|
||||
}
|
||||
|
||||
export type TWorkoutsMutations<S = IWorkoutsState> = {
|
||||
@ -30,6 +35,10 @@ export type TWorkoutsMutations<S = IWorkoutsState> = {
|
||||
state: S,
|
||||
workouts: IWorkout[]
|
||||
): void
|
||||
[WORKOUTS_STORE.MUTATIONS.SET_USER_WORKOUTS](
|
||||
state: S,
|
||||
workouts: IWorkout[]
|
||||
): void
|
||||
}
|
||||
|
||||
export type TWorkoutsStoreModule<S = IWorkoutsState> = Omit<
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { IStatisticsParams } from '@/types/statistics'
|
||||
|
||||
export interface IWorkoutSegment {
|
||||
ascent: number
|
||||
ave_speed: number
|
||||
|
Loading…
Reference in New Issue
Block a user