Client - refactoring workouts (WIP)
This commit is contained in:
parent
c5428c28a6
commit
288a78e2a0
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
@ -12,13 +12,13 @@ import {
|
||||
IWorkout,
|
||||
IWorkoutForm,
|
||||
IWorkoutPayload,
|
||||
IWorkoutsPayload,
|
||||
TWorkoutsPayload,
|
||||
} from '@/types/workouts'
|
||||
import { handleError } from '@/utils'
|
||||
|
||||
const getWorkouts = (
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload,
|
||||
payload: TWorkoutsPayload,
|
||||
target: string,
|
||||
append = false
|
||||
): void => {
|
||||
@ -48,20 +48,20 @@ export const actions: ActionTree<IWorkoutsState, IRootState> &
|
||||
IWorkoutsActions = {
|
||||
[WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS](
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
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<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
payload: TWorkoutsPayload
|
||||
): void {
|
||||
getWorkouts(context, payload, 'USER_WORKOUTS')
|
||||
},
|
||||
[WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS](
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
payload: TWorkoutsPayload
|
||||
): void {
|
||||
getWorkouts(context, payload, 'USER_WORKOUTS', true)
|
||||
},
|
||||
|
@ -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<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
payload: TWorkoutsPayload
|
||||
): void
|
||||
[WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS](
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
payload: TWorkoutsPayload
|
||||
): void
|
||||
[WORKOUTS_STORE.ACTIONS.GET_MORE_USER_WORKOUTS](
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
payload: IWorkoutsPayload
|
||||
payload: TWorkoutsPayload
|
||||
): void
|
||||
[WORKOUTS_STORE.ACTIONS.GET_WORKOUT_DATA](
|
||||
context: ActionContext<IWorkoutsState, IRootState>,
|
||||
|
@ -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
|
||||
|
@ -67,3 +67,8 @@ export const getDonutDatasets = (
|
||||
|
||||
return datasets
|
||||
}
|
||||
|
||||
export const defaultOrder = {
|
||||
order: 'desc',
|
||||
order_by: 'workout_date',
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user