2021-10-03 19:23:17 +02:00
|
|
|
<template>
|
2021-10-04 13:53:48 +02:00
|
|
|
<div id="user-statistics" v-if="translatedSports">
|
|
|
|
<StatsMenu
|
|
|
|
@timeFrameUpdate="updateTimeFrame"
|
|
|
|
@arrowClick="handleOnClickArrows"
|
|
|
|
/>
|
|
|
|
<StatChart
|
|
|
|
:sports="sports"
|
|
|
|
:user="user"
|
|
|
|
:chartParams="chartParams"
|
|
|
|
:displayed-sport-ids="selectedSportIds"
|
|
|
|
:fullStats="true"
|
|
|
|
/>
|
|
|
|
<SportsMenu
|
|
|
|
:selected-sport-ids="selectedSportIds"
|
|
|
|
:user-sports="sports"
|
|
|
|
@selectedSportIdsUpdate="updateSelectedSportIds"
|
|
|
|
/>
|
2021-10-03 19:23:17 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { ComputedRef, Ref, computed, ref, toRefs, watch } from 'vue'
|
2021-10-03 19:23:17 +02:00
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
|
|
|
import StatChart from '@/components/Common/StatsChart/index.vue'
|
2021-10-04 13:53:48 +02:00
|
|
|
import StatsMenu from '@/components/Statistics/StatsMenu.vue'
|
2021-10-13 09:57:48 +02:00
|
|
|
import SportsMenu from '@/components/Statistics/StatsSportsMenu.vue'
|
2021-10-03 19:23:17 +02:00
|
|
|
import { ISport, ITranslatedSport } from '@/types/sports'
|
|
|
|
import { IStatisticsDateParams } from '@/types/statistics'
|
2021-10-30 12:01:55 +02:00
|
|
|
import { IUserProfile } from '@/types/user'
|
2021-10-23 15:47:17 +02:00
|
|
|
import { translateSports } from '@/utils/sports'
|
2021-10-04 13:53:48 +02:00
|
|
|
import { getStatsDateParams, updateChartParams } from '@/utils/statistics'
|
2021-10-03 19:23:17 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
interface Props {
|
|
|
|
sports: ISport[]
|
|
|
|
user: IUserProfile
|
|
|
|
}
|
|
|
|
const props = defineProps<Props>()
|
2021-10-03 19:23:17 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
const { t } = useI18n()
|
2021-10-03 19:23:17 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
const { sports, user } = toRefs(props)
|
|
|
|
let selectedTimeFrame = ref('month')
|
|
|
|
const chartParams: Ref<IStatisticsDateParams> = ref(
|
|
|
|
getChartParams(selectedTimeFrame.value)
|
|
|
|
)
|
|
|
|
const translatedSports: ComputedRef<ITranslatedSport[]> = computed(() =>
|
|
|
|
translateSports(props.sports, t)
|
|
|
|
)
|
|
|
|
const selectedSportIds: Ref<number[]> = ref(getSports(props.sports))
|
|
|
|
|
|
|
|
function updateTimeFrame(timeFrame: string) {
|
|
|
|
selectedTimeFrame.value = timeFrame
|
|
|
|
chartParams.value = getChartParams(selectedTimeFrame.value)
|
|
|
|
}
|
|
|
|
function getChartParams(timeFrame: string): IStatisticsDateParams {
|
|
|
|
return getStatsDateParams(new Date(), timeFrame, props.user.weekm)
|
|
|
|
}
|
|
|
|
function handleOnClickArrows(backward: boolean) {
|
|
|
|
chartParams.value = updateChartParams(
|
|
|
|
chartParams.value,
|
|
|
|
backward,
|
|
|
|
props.user.weekm
|
|
|
|
)
|
|
|
|
}
|
|
|
|
function getSports(sports: ISport[]) {
|
|
|
|
return sports.map((sport) => sport.id)
|
|
|
|
}
|
|
|
|
function updateSelectedSportIds(sportId: number) {
|
|
|
|
if (selectedSportIds.value.includes(sportId)) {
|
|
|
|
selectedSportIds.value = selectedSportIds.value.filter(
|
|
|
|
(id) => id !== sportId
|
2021-10-03 19:23:17 +02:00
|
|
|
)
|
2021-11-10 21:19:27 +01:00
|
|
|
} else {
|
|
|
|
selectedSportIds.value.push(sportId)
|
|
|
|
}
|
|
|
|
}
|
2021-10-03 19:23:17 +02:00
|
|
|
|
2021-11-10 21:19:27 +01:00
|
|
|
watch(
|
|
|
|
() => props.sports,
|
|
|
|
(newSports) => {
|
|
|
|
selectedSportIds.value = getSports(newSports)
|
|
|
|
}
|
|
|
|
)
|
2021-10-03 19:23:17 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import '~@/scss/base';
|
|
|
|
|
|
|
|
#user-statistics {
|
2021-10-05 17:52:36 +02:00
|
|
|
&.stats-disabled {
|
|
|
|
opacity: 0.3;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2021-10-05 15:36:09 +02:00
|
|
|
::v-deep(.chart-radio) {
|
2021-10-04 13:53:48 +02:00
|
|
|
justify-content: space-around;
|
2021-10-05 15:36:09 +02:00
|
|
|
padding: $default-padding * 3 $default-padding
|
|
|
|
$default-padding$default-padding;
|
2021-10-03 19:23:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|