2021-09-05 17:43:14 +02:00
|
|
|
<template>
|
|
|
|
<div id="user-calendar">
|
2021-10-05 19:02:08 +02:00
|
|
|
<div class="calendar-card box">
|
|
|
|
<CalendarHeader
|
|
|
|
:day="day"
|
2021-11-11 10:10:55 +01:00
|
|
|
:locale-options="localeOptions"
|
2021-10-05 19:02:08 +02:00
|
|
|
@displayNextMonth="displayNextMonth"
|
|
|
|
@displayPreviousMonth="displayPreviousMonth"
|
|
|
|
/>
|
2021-11-11 10:10:55 +01:00
|
|
|
<CalendarDays
|
|
|
|
:start-date="calendarDates.start"
|
|
|
|
:locale-options="localeOptions"
|
|
|
|
/>
|
2021-10-05 19:02:08 +02:00
|
|
|
<CalendarCells
|
|
|
|
:currentDay="day"
|
2022-07-27 09:04:01 +02:00
|
|
|
:displayHARecord="user.display_ascent"
|
2021-10-05 19:02:08 +02:00
|
|
|
:end-date="calendarDates.end"
|
|
|
|
:sports="sports"
|
|
|
|
:start-date="calendarDates.start"
|
|
|
|
:timezone="user.timezone"
|
|
|
|
:workouts="calendarWorkouts"
|
|
|
|
:weekStartingMonday="user.weekm"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-09-05 17:43:14 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
<script setup lang="ts">
|
2021-11-11 10:10:55 +01:00
|
|
|
import { Locale, addMonths, format, subMonths } from 'date-fns'
|
2021-11-10 21:19:27 +01:00
|
|
|
import { ComputedRef, computed, ref, toRefs, onBeforeMount } from 'vue'
|
2021-09-05 17:43:14 +02:00
|
|
|
|
2021-09-27 13:06:17 +02:00
|
|
|
import CalendarCells from '@/components/Dashboard/UserCalendar/CalendarCells.vue'
|
2021-09-05 17:43:14 +02:00
|
|
|
import CalendarDays from '@/components/Dashboard/UserCalendar/CalendarDays.vue'
|
|
|
|
import CalendarHeader from '@/components/Dashboard/UserCalendar/CalendarHeader.vue'
|
2021-11-11 10:10:55 +01:00
|
|
|
import { ROOT_STORE, WORKOUTS_STORE } from '@/store/constants'
|
2021-09-27 13:06:17 +02:00
|
|
|
import { ISport } from '@/types/sports'
|
2022-03-20 19:48:51 +01:00
|
|
|
import { IAuthUserProfile } from '@/types/user'
|
2021-11-02 12:24:31 +01:00
|
|
|
import { IWorkout, TWorkoutsPayload } from '@/types/workouts'
|
2021-09-05 17:43:14 +02:00
|
|
|
import { useStore } from '@/use/useStore'
|
|
|
|
import { getCalendarStartAndEnd } from '@/utils/dates'
|
2021-11-02 12:24:31 +01:00
|
|
|
import { defaultOrder } from '@/utils/workouts'
|
2021-09-05 17:43:14 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
interface Props {
|
|
|
|
sports: ISport[]
|
2022-03-20 19:48:51 +01:00
|
|
|
user: IAuthUserProfile
|
2021-11-10 21:19:27 +01:00
|
|
|
}
|
|
|
|
const props = defineProps<Props>()
|
2021-09-27 13:06:17 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
const store = useStore()
|
2021-09-05 17:43:14 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
const { sports, user } = toRefs(props)
|
|
|
|
const dateFormat = 'yyyy-MM-dd'
|
2022-06-22 17:53:59 +02:00
|
|
|
const day = ref(new Date())
|
|
|
|
const calendarDates = ref(getCalendarStartAndEnd(day.value, props.user.weekm))
|
2021-11-10 21:19:27 +01:00
|
|
|
const calendarWorkouts: ComputedRef<IWorkout[]> = computed(
|
|
|
|
() => store.getters[WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS]
|
|
|
|
)
|
2021-11-11 10:10:55 +01:00
|
|
|
const localeOptions: ComputedRef<Locale> = computed(
|
|
|
|
() => store.getters[ROOT_STORE.GETTERS.LOCALE]
|
|
|
|
)
|
2021-09-29 17:35:21 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
onBeforeMount(() => getCalendarWorkouts())
|
2021-09-29 17:35:21 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
function getCalendarWorkouts() {
|
|
|
|
calendarDates.value = getCalendarStartAndEnd(day.value, props.user.weekm)
|
|
|
|
const apiParams: TWorkoutsPayload = {
|
|
|
|
from: format(calendarDates.value.start, dateFormat),
|
|
|
|
to: format(calendarDates.value.end, dateFormat),
|
|
|
|
page: 1,
|
|
|
|
per_page: 100,
|
|
|
|
...defaultOrder,
|
|
|
|
}
|
|
|
|
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS, apiParams)
|
|
|
|
}
|
|
|
|
function displayNextMonth() {
|
|
|
|
day.value = addMonths(day.value, 1)
|
|
|
|
getCalendarWorkouts()
|
|
|
|
}
|
|
|
|
function displayPreviousMonth() {
|
|
|
|
day.value = subMonths(day.value, 1)
|
|
|
|
getCalendarWorkouts()
|
|
|
|
}
|
2021-09-05 17:43:14 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
#user-calendar {
|
|
|
|
.calendar-card {
|
|
|
|
padding: 0;
|
2021-09-08 19:31:28 +02:00
|
|
|
|
|
|
|
.card-content {
|
|
|
|
padding: 0;
|
|
|
|
}
|
2021-09-05 17:43:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|