2021-09-05 17:43:14 +02:00
|
|
|
<template>
|
|
|
|
<div class="calendar-cells">
|
|
|
|
<div class="calendar-row" v-for="(row, index) in rows" :key="index">
|
|
|
|
<div
|
|
|
|
class="calendar-cell"
|
|
|
|
:class="{
|
|
|
|
'disabled-cell': !isSameMonth(day, currentDay),
|
|
|
|
'week-end': isWeekEnd(i),
|
|
|
|
today: isToday(day),
|
|
|
|
}"
|
|
|
|
v-for="(day, i) in row"
|
|
|
|
:key="i"
|
|
|
|
>
|
|
|
|
<CalendarWorkouts
|
|
|
|
:workouts="filterWorkouts(day, workouts)"
|
|
|
|
:sports="sports"
|
2022-07-27 09:04:01 +02:00
|
|
|
:displayHARecord="displayHARecord"
|
2021-09-05 17:43:14 +02:00
|
|
|
/>
|
|
|
|
<div class="calendar-cell-day">
|
|
|
|
{{ format(day, 'd') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
<script setup lang="ts">
|
2021-09-05 17:43:14 +02:00
|
|
|
import { addDays, format, isSameDay, isSameMonth, isToday } from 'date-fns'
|
2021-11-10 21:19:27 +01:00
|
|
|
import { Ref, ref, toRefs, watch, onMounted } from 'vue'
|
2021-09-05 17:43:14 +02:00
|
|
|
|
|
|
|
import CalendarWorkouts from '@/components/Dashboard/UserCalendar/CalendarWorkouts.vue'
|
|
|
|
import { ISport } from '@/types/sports'
|
|
|
|
import { IWorkout } from '@/types/workouts'
|
|
|
|
import { getDateWithTZ } from '@/utils/dates'
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
interface Props {
|
|
|
|
currentDay: Date
|
2022-07-27 09:04:01 +02:00
|
|
|
displayHARecord: boolean
|
2021-11-10 21:19:27 +01:00
|
|
|
endDate: Date
|
|
|
|
sports: ISport[]
|
|
|
|
startDate: Date
|
|
|
|
timezone: string
|
|
|
|
weekStartingMonday: boolean
|
|
|
|
workouts: IWorkout[]
|
|
|
|
}
|
|
|
|
const props = defineProps<Props>()
|
2021-09-29 17:35:21 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
const {
|
|
|
|
currentDay,
|
2022-07-27 09:04:01 +02:00
|
|
|
displayHARecord,
|
2021-11-10 21:19:27 +01:00
|
|
|
endDate,
|
|
|
|
sports,
|
|
|
|
startDate,
|
|
|
|
timezone,
|
|
|
|
weekStartingMonday,
|
|
|
|
workouts,
|
|
|
|
} = toRefs(props)
|
|
|
|
const rows: Ref<Date[][]> = ref([])
|
2021-09-29 17:35:21 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
onMounted(() => getDays())
|
2021-09-05 17:43:14 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
function getDays() {
|
|
|
|
rows.value = []
|
|
|
|
let day = startDate.value
|
|
|
|
while (day <= endDate.value) {
|
|
|
|
const days: Date[] = []
|
|
|
|
for (let i = 0; i < 7; i++) {
|
|
|
|
days.push(day)
|
|
|
|
day = addDays(day, 1)
|
2021-09-05 17:43:14 +02:00
|
|
|
}
|
2021-11-10 21:19:27 +01:00
|
|
|
rows.value.push(days)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function isWeekEnd(day: number): boolean {
|
|
|
|
return weekStartingMonday.value
|
|
|
|
? [5, 6].includes(day)
|
|
|
|
: [0, 6].includes(day)
|
|
|
|
}
|
|
|
|
function filterWorkouts(day: Date, workouts: IWorkout[]) {
|
|
|
|
if (workouts) {
|
|
|
|
return workouts
|
|
|
|
.filter((workout) =>
|
2022-01-01 21:56:05 +01:00
|
|
|
isSameDay(getDateWithTZ(workout.workout_date, timezone.value), day)
|
2021-11-10 21:19:27 +01:00
|
|
|
)
|
|
|
|
.reverse()
|
|
|
|
}
|
|
|
|
return []
|
|
|
|
}
|
2021-09-05 17:43:14 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
watch(
|
|
|
|
() => props.currentDay,
|
|
|
|
() => getDays()
|
|
|
|
)
|
2021-09-05 17:43:14 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-11-29 11:23:21 +01:00
|
|
|
@import '~@/scss/vars.scss';
|
2021-09-05 17:43:14 +02:00
|
|
|
.calendar-cells {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
.calendar-row {
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
border-top: solid 1px var(--calendar-border-color);
|
|
|
|
|
|
|
|
.calendar-cell {
|
|
|
|
border-right: solid 1px var(--calendar-border-color);
|
2021-09-30 21:09:15 +02:00
|
|
|
height: 40px;
|
2021-09-05 17:43:14 +02:00
|
|
|
flex-grow: 1;
|
2021-09-05 22:57:16 +02:00
|
|
|
flex-basis: 8%;
|
|
|
|
padding: $default-padding * 0.5 $default-padding $default-padding * 0.5
|
|
|
|
$default-padding * 0.5;
|
|
|
|
width: 8%;
|
2021-09-05 17:43:14 +02:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.calendar-cell-day {
|
|
|
|
position: absolute;
|
|
|
|
font-size: 0.8em;
|
|
|
|
line-height: 1;
|
|
|
|
top: 0.5em;
|
|
|
|
right: 0.5em;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.calendar-cell:last-child {
|
|
|
|
border-right: 0;
|
2021-10-01 17:40:58 +02:00
|
|
|
@media screen and (max-width: $small-limit) {
|
|
|
|
.calendar-workouts {
|
|
|
|
.more-workouts {
|
|
|
|
left: -45px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-05 17:43:14 +02:00
|
|
|
}
|
|
|
|
.disabled-cell {
|
|
|
|
color: var(--app-color-light);
|
|
|
|
}
|
|
|
|
.week-end {
|
|
|
|
background: var(--calendar-week-end-color);
|
|
|
|
}
|
|
|
|
.today {
|
|
|
|
background: var(--calendar-today-color);
|
|
|
|
}
|
|
|
|
}
|
2021-10-01 17:40:58 +02:00
|
|
|
@media screen and (max-width: $small-limit) {
|
|
|
|
.calendar-row:last-child {
|
|
|
|
.calendar-workouts {
|
|
|
|
.more-workouts {
|
|
|
|
top: inherit;
|
|
|
|
bottom: 20px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-05 17:43:14 +02:00
|
|
|
}
|
|
|
|
</style>
|