diff --git a/fittrackee_client/src/store/modules/workouts/actions.ts b/fittrackee_client/src/store/modules/workouts/actions.ts index 219f49dd..e2ce5e9d 100644 --- a/fittrackee_client/src/store/modules/workouts/actions.ts +++ b/fittrackee_client/src/store/modules/workouts/actions.ts @@ -10,27 +10,43 @@ import { import { IWorkoutsPayload } from '@/types/workouts' import { handleError } from '@/utils' +const getWorkouts = ( + context: ActionContext, + payload: IWorkoutsPayload, + target: string +): void => { + context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES) + authApi + .get('workouts', { + params: payload, + }) + .then((res) => { + if (res.data.status === 'success') { + context.commit( + target === 'CALENDAR_WORKOUTS' + ? WORKOUTS_STORE.MUTATIONS.SET_CALENDAR_WORKOUTS + : WORKOUTS_STORE.MUTATIONS.SET_USER_WORKOUTS, + res.data.data.workouts + ) + } else { + handleError(context, null) + } + }) + .catch((error) => handleError(context, error)) +} + export const actions: ActionTree & IWorkoutsActions = { [WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS]( context: ActionContext, payload: IWorkoutsPayload ): void { - context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES) - authApi - .get('workouts', { - params: payload, - }) - .then((res) => { - if (res.data.status === 'success') { - context.commit( - WORKOUTS_STORE.MUTATIONS.SET_CALENDAR_WORKOUTS, - res.data.data.workouts - ) - } else { - handleError(context, null) - } - }) - .catch((error) => handleError(context, error)) + getWorkouts(context, payload, 'CALENDAR_WORKOUTS') + }, + [WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS]( + context: ActionContext, + payload: IWorkoutsPayload + ): void { + getWorkouts(context, payload, 'USER_WORKOUTS') }, } diff --git a/fittrackee_client/src/store/modules/workouts/enums.ts b/fittrackee_client/src/store/modules/workouts/enums.ts index 209d29a6..563197fd 100644 --- a/fittrackee_client/src/store/modules/workouts/enums.ts +++ b/fittrackee_client/src/store/modules/workouts/enums.ts @@ -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', } diff --git a/fittrackee_client/src/store/modules/workouts/getters.ts b/fittrackee_client/src/store/modules/workouts/getters.ts index 7a27b1ee..0e48ca85 100644 --- a/fittrackee_client/src/store/modules/workouts/getters.ts +++ b/fittrackee_client/src/store/modules/workouts/getters.ts @@ -12,4 +12,7 @@ export const getters: GetterTree & [WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS]: (state: IWorkoutsState) => { return state.calendar_workouts }, + [WORKOUTS_STORE.GETTERS.USER_WORKOUTS]: (state: IWorkoutsState) => { + return state.user_workouts + }, } diff --git a/fittrackee_client/src/store/modules/workouts/mutations.ts b/fittrackee_client/src/store/modules/workouts/mutations.ts index d59cd5ff..1c237178 100644 --- a/fittrackee_client/src/store/modules/workouts/mutations.ts +++ b/fittrackee_client/src/store/modules/workouts/mutations.ts @@ -14,4 +14,10 @@ export const mutations: MutationTree & TWorkoutsMutations = { ) { state.calendar_workouts = workouts }, + [WORKOUTS_STORE.MUTATIONS.SET_USER_WORKOUTS]( + state: IWorkoutsState, + workouts: IWorkout[] + ) { + state.user_workouts = workouts + }, } diff --git a/fittrackee_client/src/store/modules/workouts/types.ts b/fittrackee_client/src/store/modules/workouts/types.ts index 83a85e20..db3a8b91 100644 --- a/fittrackee_client/src/store/modules/workouts/types.ts +++ b/fittrackee_client/src/store/modules/workouts/types.ts @@ -19,10 +19,15 @@ export interface IWorkoutsActions { context: ActionContext, payload: IWorkoutsPayload ): void + [WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS]( + context: ActionContext, + 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 = { @@ -30,6 +35,10 @@ export type TWorkoutsMutations = { state: S, workouts: IWorkout[] ): void + [WORKOUTS_STORE.MUTATIONS.SET_USER_WORKOUTS]( + state: S, + workouts: IWorkout[] + ): void } export type TWorkoutsStoreModule = Omit< diff --git a/fittrackee_client/src/types/workouts.ts b/fittrackee_client/src/types/workouts.ts index a2f3d9f9..aca209ff 100644 --- a/fittrackee_client/src/types/workouts.ts +++ b/fittrackee_client/src/types/workouts.ts @@ -1,5 +1,3 @@ -import { IStatisticsParams } from '@/types/statistics' - export interface IWorkoutSegment { ascent: number ave_speed: number