Client - refactoring workouts (WIP)

This commit is contained in:
Sam 2021-11-02 12:24:31 +01:00
parent c5428c28a6
commit 288a78e2a0
7 changed files with 27 additions and 16 deletions

View File

@ -47,6 +47,7 @@
import { IUserProfile } from '@/types/user' import { IUserProfile } from '@/types/user'
import { IWorkout } from '@/types/workouts' import { IWorkout } from '@/types/workouts'
import { useStore } from '@/use/useStore' import { useStore } from '@/use/useStore'
import { defaultOrder } from '@/utils/workouts'
export default defineComponent({ export default defineComponent({
name: 'Timeline', name: 'Timeline',
@ -86,6 +87,7 @@
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS, { store.dispatch(WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS, {
page: page.value, page: page.value,
per_page, per_page,
...defaultOrder,
}) })
} }
function loadMoreWorkouts() { function loadMoreWorkouts() {
@ -93,6 +95,7 @@
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS, { store.dispatch(WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS, {
page: page.value, page: page.value,
per_page, per_page,
...defaultOrder,
}) })
} }

View File

@ -38,9 +38,10 @@
import { WORKOUTS_STORE } from '@/store/constants' import { WORKOUTS_STORE } from '@/store/constants'
import { ISport } from '@/types/sports' import { ISport } from '@/types/sports'
import { IUserProfile } from '@/types/user' import { IUserProfile } from '@/types/user'
import { IWorkout, IWorkoutsPayload } from '@/types/workouts' import { IWorkout, TWorkoutsPayload } from '@/types/workouts'
import { useStore } from '@/use/useStore' import { useStore } from '@/use/useStore'
import { getCalendarStartAndEnd } from '@/utils/dates' import { getCalendarStartAndEnd } from '@/utils/dates'
import { defaultOrder } from '@/utils/workouts'
export default defineComponent({ export default defineComponent({
name: 'UserCalendar', name: 'UserCalendar',
@ -78,11 +79,12 @@
day.value, day.value,
props.user.weekm props.user.weekm
) )
const apiParams: IWorkoutsPayload = { const apiParams: TWorkoutsPayload = {
from: format(calendarDates.value.start, dateFormat), from: format(calendarDates.value.start, dateFormat),
to: format(calendarDates.value.end, dateFormat), to: format(calendarDates.value.end, dateFormat),
order: 'desc', page: 1,
per_page: 100, per_page: 100,
...defaultOrder,
} }
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS, apiParams) store.dispatch(WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS, apiParams)
} }

View File

@ -122,6 +122,7 @@
import { IWorkout } from '@/types/workouts' import { IWorkout } from '@/types/workouts'
import { useStore } from '@/use/useStore' import { useStore } from '@/use/useStore'
import { getDateWithTZ } from '@/utils/dates' import { getDateWithTZ } from '@/utils/dates'
import { defaultOrder } from '@/utils/workouts'
export default defineComponent({ export default defineComponent({
name: 'WorkoutsList', name: 'WorkoutsList',
@ -164,6 +165,7 @@
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS, { store.dispatch(WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS, {
page: page.value, page: page.value,
per_page, per_page,
...defaultOrder,
...props.params, ...props.params,
}) })
} }
@ -172,6 +174,7 @@
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS, { store.dispatch(WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS, {
page: page.value, page: page.value,
per_page, per_page,
...defaultOrder,
...props.params, ...props.params,
}) })
} }

View File

@ -12,13 +12,13 @@ import {
IWorkout, IWorkout,
IWorkoutForm, IWorkoutForm,
IWorkoutPayload, IWorkoutPayload,
IWorkoutsPayload, TWorkoutsPayload,
} from '@/types/workouts' } from '@/types/workouts'
import { handleError } from '@/utils' import { handleError } from '@/utils'
const getWorkouts = ( const getWorkouts = (
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload, payload: TWorkoutsPayload,
target: string, target: string,
append = false append = false
): void => { ): void => {
@ -48,20 +48,20 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
IWorkoutsActions = { IWorkoutsActions = {
[WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS]( [WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS](
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload payload: TWorkoutsPayload
): void { ): void {
context.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_CALENDAR_WORKOUTS) context.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_CALENDAR_WORKOUTS)
getWorkouts(context, payload, 'CALENDAR_WORKOUTS') getWorkouts(context, payload, 'CALENDAR_WORKOUTS')
}, },
[WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS]( [WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS](
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload payload: TWorkoutsPayload
): void { ): void {
getWorkouts(context, payload, 'USER_WORKOUTS') getWorkouts(context, payload, 'USER_WORKOUTS')
}, },
[WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS]( [WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS](
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload payload: TWorkoutsPayload
): void { ): void {
getWorkouts(context, payload, 'USER_WORKOUTS', true) getWorkouts(context, payload, 'USER_WORKOUTS', true)
}, },

View File

@ -10,7 +10,7 @@ import { IRootState } from '@/store/modules/root/types'
import { import {
IWorkout, IWorkout,
IWorkoutApiChartData, IWorkoutApiChartData,
IWorkoutsPayload, TWorkoutsPayload,
IWorkoutData, IWorkoutData,
IWorkoutPayload, IWorkoutPayload,
IWorkoutForm, IWorkoutForm,
@ -25,15 +25,15 @@ export interface IWorkoutsState {
export interface IWorkoutsActions { export interface IWorkoutsActions {
[WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS]( [WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS](
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload payload: TWorkoutsPayload
): void ): void
[WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS]( [WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS](
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload payload: TWorkoutsPayload
): void ): void
[WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS]( [WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS](
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,
payload: IWorkoutsPayload payload: TWorkoutsPayload
): void ): void
[WORKOUTS_STORE.ACTIONS.GET_WORKOUT_DATA]( [WORKOUTS_STORE.ACTIONS.GET_WORKOUT_DATA](
context: ActionContext<IWorkoutsState, IRootState>, context: ActionContext<IWorkoutsState, IRootState>,

View File

@ -1,3 +1,4 @@
import { TPaginationPayload } from '@/types/api'
import { IChartDataset } from '@/types/chart' import { IChartDataset } from '@/types/chart'
export interface IWorkoutSegment { export interface IWorkoutSegment {
@ -113,12 +114,9 @@ export interface IWorkoutPayload {
data?: IWorkoutForm data?: IWorkoutForm
} }
export interface IWorkoutsPayload { export type TWorkoutsPayload = TPaginationPayload & {
from?: string from?: string
to?: string to?: string
order?: string
per_page?: number
page?: number
ave_speed_from?: string ave_speed_from?: string
ave_speed_to?: string ave_speed_to?: string
max_speed_from?: string max_speed_from?: string

View File

@ -67,3 +67,8 @@ export const getDonutDatasets = (
return datasets return datasets
} }
export const defaultOrder = {
order: 'desc',
order_by: 'workout_date',
}