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>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import {
|
|
|
|
ComputedRef,
|
|
|
|
PropType,
|
|
|
|
Ref,
|
|
|
|
computed,
|
|
|
|
defineComponent,
|
|
|
|
ref,
|
|
|
|
watch,
|
|
|
|
} from 'vue'
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
|
|
|
import StatChart from '@/components/Common/StatsChart/index.vue'
|
2021-10-04 13:53:48 +02:00
|
|
|
import SportsMenu from '@/components/Statistics/SportsMenu.vue'
|
|
|
|
import StatsMenu from '@/components/Statistics/StatsMenu.vue'
|
2021-10-03 19:23:17 +02:00
|
|
|
import { ISport, ITranslatedSport } from '@/types/sports'
|
|
|
|
import { IStatisticsDateParams } from '@/types/statistics'
|
|
|
|
import { IAuthUserProfile } from '@/types/user'
|
|
|
|
import { translateSports, sportColors } 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
|
|
|
|
|
|
|
export default defineComponent({
|
2021-10-04 13:53:48 +02:00
|
|
|
name: 'Statistics',
|
2021-10-03 19:23:17 +02:00
|
|
|
components: {
|
2021-10-04 13:53:48 +02:00
|
|
|
SportsMenu,
|
2021-10-03 19:23:17 +02:00
|
|
|
StatChart,
|
2021-10-04 13:53:48 +02:00
|
|
|
StatsMenu,
|
2021-10-03 19:23:17 +02:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
sports: {
|
|
|
|
type: Object as PropType<ISport[]>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
type: Object as PropType<IAuthUserProfile>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setup(props) {
|
|
|
|
const { t } = useI18n()
|
|
|
|
let selectedTimeFrame = ref('month')
|
|
|
|
const timeFrames = ['week', 'month', 'year']
|
|
|
|
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 {
|
2021-10-04 13:53:48 +02:00
|
|
|
return getStatsDateParams(new Date(), timeFrame, props.user.weekm)
|
2021-10-03 19:23:17 +02:00
|
|
|
}
|
|
|
|
function handleOnClickArrows(backward: boolean) {
|
2021-10-04 13:53:48 +02:00
|
|
|
chartParams.value = updateChartParams(
|
|
|
|
chartParams.value,
|
|
|
|
backward,
|
|
|
|
props.user.weekm
|
|
|
|
)
|
2021-10-03 19:23:17 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
selectedSportIds.value.push(sportId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
watch(
|
|
|
|
() => props.sports,
|
|
|
|
(newSports) => {
|
|
|
|
selectedSportIds.value = getSports(newSports)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return {
|
|
|
|
chartParams,
|
|
|
|
selectedTimeFrame,
|
|
|
|
sportColors,
|
|
|
|
t,
|
|
|
|
timeFrames,
|
|
|
|
translatedSports,
|
|
|
|
selectedSportIds,
|
|
|
|
handleOnClickArrows,
|
|
|
|
updateSelectedSportIds,
|
|
|
|
updateTimeFrame,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import '~@/scss/base';
|
|
|
|
|
|
|
|
#user-statistics {
|
2021-10-04 13:53:48 +02:00
|
|
|
.chart-radio {
|
|
|
|
justify-content: space-around;
|
|
|
|
padding: $default-padding * 2 $default-padding;
|
2021-10-03 19:23:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|