From 288a78e2a07680013db83e3313fb70ad17a93b2b Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 2 Nov 2021 12:24:31 +0100 Subject: [PATCH] Client - refactoring workouts (WIP) --- .../src/components/Dashboard/Timeline.vue | 3 +++ .../src/components/Dashboard/UserCalendar/index.vue | 8 +++++--- .../src/components/Workouts/WorkoutsList.vue | 3 +++ .../src/store/modules/workouts/actions.ts | 10 +++++----- fittrackee_client/src/store/modules/workouts/types.ts | 8 ++++---- fittrackee_client/src/types/workouts.ts | 6 ++---- fittrackee_client/src/utils/workouts.ts | 5 +++++ 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/fittrackee_client/src/components/Dashboard/Timeline.vue b/fittrackee_client/src/components/Dashboard/Timeline.vue index 85771c74..ec5644b4 100644 --- a/fittrackee_client/src/components/Dashboard/Timeline.vue +++ b/fittrackee_client/src/components/Dashboard/Timeline.vue @@ -47,6 +47,7 @@ import { IUserProfile } from '@/types/user' import { IWorkout } from '@/types/workouts' import { useStore } from '@/use/useStore' + import { defaultOrder } from '@/utils/workouts' export default defineComponent({ name: 'Timeline', @@ -86,6 +87,7 @@ store.dispatch(WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS, { page: page.value, per_page, + ...defaultOrder, }) } function loadMoreWorkouts() { @@ -93,6 +95,7 @@ store.dispatch(WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS, { page: page.value, per_page, + ...defaultOrder, }) } diff --git a/fittrackee_client/src/components/Dashboard/UserCalendar/index.vue b/fittrackee_client/src/components/Dashboard/UserCalendar/index.vue index 728c1eec..ce6d3ebf 100644 --- a/fittrackee_client/src/components/Dashboard/UserCalendar/index.vue +++ b/fittrackee_client/src/components/Dashboard/UserCalendar/index.vue @@ -38,9 +38,10 @@ import { WORKOUTS_STORE } from '@/store/constants' import { ISport } from '@/types/sports' import { IUserProfile } from '@/types/user' - import { IWorkout, IWorkoutsPayload } from '@/types/workouts' + import { IWorkout, TWorkoutsPayload } from '@/types/workouts' import { useStore } from '@/use/useStore' import { getCalendarStartAndEnd } from '@/utils/dates' + import { defaultOrder } from '@/utils/workouts' export default defineComponent({ name: 'UserCalendar', @@ -78,11 +79,12 @@ day.value, props.user.weekm ) - const apiParams: IWorkoutsPayload = { + const apiParams: TWorkoutsPayload = { from: format(calendarDates.value.start, dateFormat), to: format(calendarDates.value.end, dateFormat), - order: 'desc', + page: 1, per_page: 100, + ...defaultOrder, } store.dispatch(WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS, apiParams) } diff --git a/fittrackee_client/src/components/Workouts/WorkoutsList.vue b/fittrackee_client/src/components/Workouts/WorkoutsList.vue index 6c1d34d4..239f4a2c 100644 --- a/fittrackee_client/src/components/Workouts/WorkoutsList.vue +++ b/fittrackee_client/src/components/Workouts/WorkoutsList.vue @@ -122,6 +122,7 @@ import { IWorkout } from '@/types/workouts' import { useStore } from '@/use/useStore' import { getDateWithTZ } from '@/utils/dates' + import { defaultOrder } from '@/utils/workouts' export default defineComponent({ name: 'WorkoutsList', @@ -164,6 +165,7 @@ store.dispatch(WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS, { page: page.value, per_page, + ...defaultOrder, ...props.params, }) } @@ -172,6 +174,7 @@ store.dispatch(WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS, { page: page.value, per_page, + ...defaultOrder, ...props.params, }) } diff --git a/fittrackee_client/src/store/modules/workouts/actions.ts b/fittrackee_client/src/store/modules/workouts/actions.ts index b736291a..b5a6d79b 100644 --- a/fittrackee_client/src/store/modules/workouts/actions.ts +++ b/fittrackee_client/src/store/modules/workouts/actions.ts @@ -12,13 +12,13 @@ import { IWorkout, IWorkoutForm, IWorkoutPayload, - IWorkoutsPayload, + TWorkoutsPayload, } from '@/types/workouts' import { handleError } from '@/utils' const getWorkouts = ( context: ActionContext, - payload: IWorkoutsPayload, + payload: TWorkoutsPayload, target: string, append = false ): void => { @@ -48,20 +48,20 @@ export const actions: ActionTree & IWorkoutsActions = { [WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS]( context: ActionContext, - payload: IWorkoutsPayload + payload: TWorkoutsPayload ): void { context.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_CALENDAR_WORKOUTS) getWorkouts(context, payload, 'CALENDAR_WORKOUTS') }, [WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS]( context: ActionContext, - payload: IWorkoutsPayload + payload: TWorkoutsPayload ): void { getWorkouts(context, payload, 'USER_WORKOUTS') }, [WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS]( context: ActionContext, - payload: IWorkoutsPayload + payload: TWorkoutsPayload ): void { getWorkouts(context, payload, 'USER_WORKOUTS', true) }, diff --git a/fittrackee_client/src/store/modules/workouts/types.ts b/fittrackee_client/src/store/modules/workouts/types.ts index 3a01653f..8ab30ddd 100644 --- a/fittrackee_client/src/store/modules/workouts/types.ts +++ b/fittrackee_client/src/store/modules/workouts/types.ts @@ -10,7 +10,7 @@ import { IRootState } from '@/store/modules/root/types' import { IWorkout, IWorkoutApiChartData, - IWorkoutsPayload, + TWorkoutsPayload, IWorkoutData, IWorkoutPayload, IWorkoutForm, @@ -25,15 +25,15 @@ export interface IWorkoutsState { export interface IWorkoutsActions { [WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS]( context: ActionContext, - payload: IWorkoutsPayload + payload: TWorkoutsPayload ): void [WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS]( context: ActionContext, - payload: IWorkoutsPayload + payload: TWorkoutsPayload ): void [WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS]( context: ActionContext, - payload: IWorkoutsPayload + payload: TWorkoutsPayload ): void [WORKOUTS_STORE.ACTIONS.GET_WORKOUT_DATA]( context: ActionContext, diff --git a/fittrackee_client/src/types/workouts.ts b/fittrackee_client/src/types/workouts.ts index d3dcec3e..189784ab 100644 --- a/fittrackee_client/src/types/workouts.ts +++ b/fittrackee_client/src/types/workouts.ts @@ -1,3 +1,4 @@ +import { TPaginationPayload } from '@/types/api' import { IChartDataset } from '@/types/chart' export interface IWorkoutSegment { @@ -113,12 +114,9 @@ export interface IWorkoutPayload { data?: IWorkoutForm } -export interface IWorkoutsPayload { +export type TWorkoutsPayload = TPaginationPayload & { from?: string to?: string - order?: string - per_page?: number - page?: number ave_speed_from?: string ave_speed_to?: string max_speed_from?: string diff --git a/fittrackee_client/src/utils/workouts.ts b/fittrackee_client/src/utils/workouts.ts index 5a75e353..3ca7755f 100644 --- a/fittrackee_client/src/utils/workouts.ts +++ b/fittrackee_client/src/utils/workouts.ts @@ -67,3 +67,8 @@ export const getDonutDatasets = ( return datasets } + +export const defaultOrder = { + order: 'desc', + order_by: 'workout_date', +}