Client - init store for users workouts displayed in timeline

This commit is contained in:
Sam 2021-09-08 18:56:16 +02:00
parent 03241cfe83
commit 5ab293b9e7
6 changed files with 53 additions and 18 deletions

View File

@ -10,12 +10,11 @@ import {
import { IWorkoutsPayload } from '@/types/workouts' import { IWorkoutsPayload } from '@/types/workouts'
import { handleError } from '@/utils' import { handleError } from '@/utils'
export const actions: ActionTree<IWorkoutsState, IRootState> & const getWorkouts = (
IWorkoutsActions = {
[WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS](
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload payload: IWorkoutsPayload,
): void { target: string
): void => {
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES) context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
authApi authApi
.get('workouts', { .get('workouts', {
@ -24,7 +23,9 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
.then((res) => { .then((res) => {
if (res.data.status === 'success') { if (res.data.status === 'success') {
context.commit( 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 res.data.data.workouts
) )
} else { } else {
@ -32,5 +33,20 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
} }
}) })
.catch((error) => handleError(context, error)) .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')
}, },
} }

View File

@ -1,11 +1,14 @@
export enum WorkoutsActions { export enum WorkoutsActions {
GET_CALENDAR_WORKOUTS = 'GET_CALENDAR_WORKOUTS', GET_CALENDAR_WORKOUTS = 'GET_CALENDAR_WORKOUTS',
GET_USER_WORKOUTS = 'GET_USER_WORKOUTS',
} }
export enum WorkoutsGetters { export enum WorkoutsGetters {
CALENDAR_WORKOUTS = 'CALENDAR_WORKOUTS', CALENDAR_WORKOUTS = 'CALENDAR_WORKOUTS',
USER_WORKOUTS = 'USER_WORKOUTS',
} }
export enum WorkoutsMutations { export enum WorkoutsMutations {
SET_CALENDAR_WORKOUTS = 'SET_CALENDAR_WORKOUTS', SET_CALENDAR_WORKOUTS = 'SET_CALENDAR_WORKOUTS',
SET_USER_WORKOUTS = 'SET_USER_WORKOUTS',
} }

View File

@ -12,4 +12,7 @@ export const getters: GetterTree<IWorkoutsState, IRootState> &
[WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS]: (state: IWorkoutsState) => { [WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS]: (state: IWorkoutsState) => {
return state.calendar_workouts return state.calendar_workouts
}, },
[WORKOUTS_STORE.GETTERS.USER_WORKOUTS]: (state: IWorkoutsState) => {
return state.user_workouts
},
} }

View File

@ -14,4 +14,10 @@ export const mutations: MutationTree<IWorkoutsState> & TWorkoutsMutations = {
) { ) {
state.calendar_workouts = workouts state.calendar_workouts = workouts
}, },
[WORKOUTS_STORE.MUTATIONS.SET_USER_WORKOUTS](
state: IWorkoutsState,
workouts: IWorkout[]
) {
state.user_workouts = workouts
},
} }

View File

@ -19,10 +19,15 @@ export interface IWorkoutsActions {
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload payload: IWorkoutsPayload
): void ): void
[WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS](
context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload
): void
} }
export interface IWorkoutsGetters { export interface IWorkoutsGetters {
[WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS](state: IWorkoutsState): IWorkout[] [WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS](state: IWorkoutsState): IWorkout[]
[WORKOUTS_STORE.GETTERS.USER_WORKOUTS](state: IWorkoutsState): IWorkout[]
} }
export type TWorkoutsMutations<S = IWorkoutsState> = { export type TWorkoutsMutations<S = IWorkoutsState> = {
@ -30,6 +35,10 @@ export type TWorkoutsMutations<S = IWorkoutsState> = {
state: S, state: S,
workouts: IWorkout[] workouts: IWorkout[]
): void ): void
[WORKOUTS_STORE.MUTATIONS.SET_USER_WORKOUTS](
state: S,
workouts: IWorkout[]
): void
} }
export type TWorkoutsStoreModule<S = IWorkoutsState> = Omit< export type TWorkoutsStoreModule<S = IWorkoutsState> = Omit<

View File

@ -1,5 +1,3 @@
import { IStatisticsParams } from '@/types/statistics'
export interface IWorkoutSegment { export interface IWorkoutSegment {
ascent: number ascent: number
ave_speed: number ave_speed: number