Client - dashboard refactoring
This commit is contained in:
parent
6c29050d27
commit
f8c0f89852
@ -25,7 +25,7 @@
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
import WorkoutCard from '@/components/Dashboard/Timeline/WorkoutCard.vue'
|
import WorkoutCard from '@/components/Dashboard/Timeline/WorkoutCard.vue'
|
||||||
import { SPORTS_STORE, WORKOUTS_STORE } from '@/store/constants'
|
import { WORKOUTS_STORE } from '@/store/constants'
|
||||||
import { ISport } from '@/types/sports'
|
import { ISport } from '@/types/sports'
|
||||||
import { IAuthUserProfile } from '@/types/user'
|
import { IAuthUserProfile } from '@/types/user'
|
||||||
import { IWorkout } from '@/types/workouts'
|
import { IWorkout } from '@/types/workouts'
|
||||||
@ -37,6 +37,10 @@
|
|||||||
WorkoutCard,
|
WorkoutCard,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
sports: {
|
||||||
|
type: Object as PropType<ISport[]>,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
user: {
|
user: {
|
||||||
type: Object as PropType<IAuthUserProfile>,
|
type: Object as PropType<IAuthUserProfile>,
|
||||||
required: true,
|
required: true,
|
||||||
@ -45,6 +49,7 @@
|
|||||||
setup() {
|
setup() {
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
onBeforeMount(() =>
|
onBeforeMount(() =>
|
||||||
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS, { page: 1 })
|
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_USER_WORKOUTS, { page: 1 })
|
||||||
)
|
)
|
||||||
@ -53,11 +58,7 @@
|
|||||||
() => store.getters[WORKOUTS_STORE.GETTERS.USER_WORKOUTS]
|
() => store.getters[WORKOUTS_STORE.GETTERS.USER_WORKOUTS]
|
||||||
)
|
)
|
||||||
|
|
||||||
const sports: ComputedRef<ISport[]> = computed(
|
return { workouts, t }
|
||||||
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
|
|
||||||
)
|
|
||||||
|
|
||||||
return { workouts, sports, t }
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<template #content>
|
<template #content>
|
||||||
<CalendarHeader :day="day" locale-options="enGB" />
|
<CalendarHeader :day="day" locale-options="enGB" />
|
||||||
<CalendarDays :start-date="calendarDates.start" locale-options="enGB" />
|
<CalendarDays :start-date="calendarDates.start" locale-options="enGB" />
|
||||||
<CalendaCells
|
<CalendarCells
|
||||||
:currentDay="day"
|
:currentDay="day"
|
||||||
:end-date="calendarDates.end"
|
:end-date="calendarDates.end"
|
||||||
:sports="sports"
|
:sports="sports"
|
||||||
@ -21,18 +21,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
import {
|
import {
|
||||||
|
ComputedRef,
|
||||||
PropType,
|
PropType,
|
||||||
|
computed,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
onBeforeMount,
|
onBeforeMount,
|
||||||
ComputedRef,
|
|
||||||
computed,
|
|
||||||
} from 'vue'
|
} from 'vue'
|
||||||
|
|
||||||
import Card from '@/components/Common/Card.vue'
|
import Card from '@/components/Common/Card.vue'
|
||||||
import CalendaCells from '@/components/Dashboard/UserCalendar/CalendarCells.vue'
|
import CalendarCells from '@/components/Dashboard/UserCalendar/CalendarCells.vue'
|
||||||
import CalendarDays from '@/components/Dashboard/UserCalendar/CalendarDays.vue'
|
import CalendarDays from '@/components/Dashboard/UserCalendar/CalendarDays.vue'
|
||||||
import CalendarHeader from '@/components/Dashboard/UserCalendar/CalendarHeader.vue'
|
import CalendarHeader from '@/components/Dashboard/UserCalendar/CalendarHeader.vue'
|
||||||
import { SPORTS_STORE, WORKOUTS_STORE } from '@/store/constants'
|
import { WORKOUTS_STORE } from '@/store/constants'
|
||||||
|
import { ISport } from '@/types/sports'
|
||||||
import { IAuthUserProfile } from '@/types/user'
|
import { IAuthUserProfile } from '@/types/user'
|
||||||
import { IWorkout, IWorkoutsPayload } from '@/types/workouts'
|
import { IWorkout, IWorkoutsPayload } from '@/types/workouts'
|
||||||
import { useStore } from '@/use/useStore'
|
import { useStore } from '@/use/useStore'
|
||||||
@ -41,12 +42,16 @@
|
|||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'UserCalendar',
|
name: 'UserCalendar',
|
||||||
components: {
|
components: {
|
||||||
CalendaCells,
|
CalendarCells,
|
||||||
CalendarDays,
|
CalendarDays,
|
||||||
CalendarHeader,
|
CalendarHeader,
|
||||||
Card,
|
Card,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
sports: {
|
||||||
|
type: Object as PropType<ISport[]>,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
user: {
|
user: {
|
||||||
type: Object as PropType<IAuthUserProfile>,
|
type: Object as PropType<IAuthUserProfile>,
|
||||||
required: true,
|
required: true,
|
||||||
@ -54,6 +59,11 @@
|
|||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
|
onBeforeMount(() =>
|
||||||
|
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS, apiParams)
|
||||||
|
)
|
||||||
|
|
||||||
const dateFormat = 'yyyy-MM-dd'
|
const dateFormat = 'yyyy-MM-dd'
|
||||||
const day = new Date()
|
const day = new Date()
|
||||||
const calendarDates = getCalendarStartAndEnd(day, props.user.weekm)
|
const calendarDates = getCalendarStartAndEnd(day, props.user.weekm)
|
||||||
@ -66,13 +76,8 @@
|
|||||||
const calendarWorkouts: ComputedRef<IWorkout[]> = computed(
|
const calendarWorkouts: ComputedRef<IWorkout[]> = computed(
|
||||||
() => store.getters[WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS]
|
() => store.getters[WORKOUTS_STORE.GETTERS.CALENDAR_WORKOUTS]
|
||||||
)
|
)
|
||||||
const sports = computed(() => store.getters[SPORTS_STORE.GETTERS.SPORTS])
|
|
||||||
|
|
||||||
onBeforeMount(() =>
|
return { day, calendarDates, calendarWorkouts }
|
||||||
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_CALENDAR_WORKOUTS, apiParams)
|
|
||||||
)
|
|
||||||
|
|
||||||
return { day, calendarDates, calendarWorkouts, sports }
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { startOfMonth, endOfMonth, format } from 'date-fns'
|
import { endOfMonth, format, startOfMonth } from 'date-fns'
|
||||||
import {
|
import {
|
||||||
ComputedRef,
|
ComputedRef,
|
||||||
PropType,
|
PropType,
|
||||||
@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
import Card from '@/components/Common/Card.vue'
|
import Card from '@/components/Common/Card.vue'
|
||||||
import Chart from '@/components/Common/StatsChart/index.vue'
|
import Chart from '@/components/Common/StatsChart/index.vue'
|
||||||
import { STATS_STORE, SPORTS_STORE, USER_STORE } from '@/store/constants'
|
import { STATS_STORE } from '@/store/constants'
|
||||||
import { ISport } from '@/types/sports'
|
import { ISport } from '@/types/sports'
|
||||||
import { IStatisticsDateParams, TStatisticsFromApi } from '@/types/statistics'
|
import { IStatisticsDateParams, TStatisticsFromApi } from '@/types/statistics'
|
||||||
import { IAuthUserProfile } from '@/types/user'
|
import { IAuthUserProfile } from '@/types/user'
|
||||||
@ -77,6 +77,10 @@
|
|||||||
Chart,
|
Chart,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
sports: {
|
||||||
|
type: Object as PropType<ISport[]>,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
user: {
|
user: {
|
||||||
type: Object as PropType<IAuthUserProfile>,
|
type: Object as PropType<IAuthUserProfile>,
|
||||||
required: true,
|
required: true,
|
||||||
@ -84,9 +88,13 @@
|
|||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
const date = new Date()
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
onBeforeMount(() => getStatistics())
|
||||||
|
|
||||||
|
const date = new Date()
|
||||||
const dateFormat = 'yyyy-MM-dd'
|
const dateFormat = 'yyyy-MM-dd'
|
||||||
|
let displayedData = ref('total_distance')
|
||||||
const chartParams: IStatisticsDateParams = {
|
const chartParams: IStatisticsDateParams = {
|
||||||
duration: 'week',
|
duration: 'week',
|
||||||
start: startOfMonth(date),
|
start: startOfMonth(date),
|
||||||
@ -100,18 +108,10 @@
|
|||||||
const statistics: ComputedRef<TStatisticsFromApi> = computed(
|
const statistics: ComputedRef<TStatisticsFromApi> = computed(
|
||||||
() => store.getters[STATS_STORE.GETTERS.USER_STATS]
|
() => store.getters[STATS_STORE.GETTERS.USER_STATS]
|
||||||
)
|
)
|
||||||
const sports: ComputedRef<ISport[]> = computed(
|
|
||||||
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
|
|
||||||
)
|
|
||||||
const authUser: ComputedRef<IAuthUserProfile> = computed(
|
|
||||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
|
||||||
)
|
|
||||||
let displayedData = ref('total_distance')
|
|
||||||
|
|
||||||
function updateDisplayData(event: Event & { target: HTMLInputElement }) {
|
function updateDisplayData(event: Event & { target: HTMLInputElement }) {
|
||||||
displayedData.value = event.target.name
|
displayedData.value = event.target.name
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStatistics() {
|
function getStatistics() {
|
||||||
store.dispatch(STATS_STORE.ACTIONS.GET_USER_STATS, {
|
store.dispatch(STATS_STORE.ACTIONS.GET_USER_STATS, {
|
||||||
username: props.user.username,
|
username: props.user.username,
|
||||||
@ -120,16 +120,13 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeMount(() => getStatistics())
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
weekStartingMonday: computed<boolean>(() => props.user.weekm),
|
||||||
chartParams,
|
chartParams,
|
||||||
displayedData,
|
displayedData,
|
||||||
sports,
|
|
||||||
statistics,
|
statistics,
|
||||||
t,
|
t,
|
||||||
updateDisplayData,
|
updateDisplayData,
|
||||||
weekStartingMonday: computed<boolean>(() => authUser.value.weekm),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -23,9 +23,8 @@
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
import RecordsCard from '@/components/Dashboard/UserRecords/RecordsCard.vue'
|
import RecordsCard from '@/components/Dashboard/UserRecords/RecordsCard.vue'
|
||||||
import { SPORTS_STORE } from '@/store/constants'
|
import { ISport } from '@/types/sports'
|
||||||
import { IAuthUserProfile } from '@/types/user'
|
import { IAuthUserProfile } from '@/types/user'
|
||||||
import { useStore } from '@/use/useStore'
|
|
||||||
import { getRecordsBySports } from '@/utils/records'
|
import { getRecordsBySports } from '@/utils/records'
|
||||||
import { translateSports } from '@/utils/sports'
|
import { translateSports } from '@/utils/sports'
|
||||||
|
|
||||||
@ -35,18 +34,21 @@
|
|||||||
RecordsCard,
|
RecordsCard,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
sports: {
|
||||||
|
type: Object as PropType<ISport[]>,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
user: {
|
user: {
|
||||||
type: Object as PropType<IAuthUserProfile>,
|
type: Object as PropType<IAuthUserProfile>,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
const store = useStore()
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const recordsBySport = computed(() =>
|
const recordsBySport = computed(() =>
|
||||||
getRecordsBySports(
|
getRecordsBySports(
|
||||||
props.user.records,
|
props.user.records,
|
||||||
translateSports(store.getters[SPORTS_STORE.GETTERS.SPORTS], t),
|
translateSports(props.sports, t),
|
||||||
props.user.timezone
|
props.user.timezone
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="dashboard" v-if="authUser.username">
|
<div id="dashboard" v-if="authUser.username && sports.length > 0">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<UserStatsCards :user="authUser" />
|
<UserStatsCards :user="authUser" />
|
||||||
</div>
|
</div>
|
||||||
<div class="container dashboard-container">
|
<div class="container dashboard-container">
|
||||||
<div class="left-container dashboard-sub-container">
|
<div class="left-container dashboard-sub-container">
|
||||||
<UserMonthStats :user="authUser" />
|
<UserMonthStats :sports="sports" :user="authUser" />
|
||||||
<UserRecords :user="authUser" />
|
<UserRecords :sports="sports" :user="authUser" />
|
||||||
</div>
|
</div>
|
||||||
<div class="right-container dashboard-sub-container">
|
<div class="right-container dashboard-sub-container">
|
||||||
<UserCalendar :user="authUser" />
|
<UserCalendar :sports="sports" :user="authUser" />
|
||||||
<Timeline :user="authUser" />
|
<Timeline :sports="sports" :user="authUser" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -24,7 +24,8 @@
|
|||||||
import UserMonthStats from '@/components/Dashboard/UserMonthStats.vue'
|
import UserMonthStats from '@/components/Dashboard/UserMonthStats.vue'
|
||||||
import UserRecords from '@/components/Dashboard/UserRecords/index.vue'
|
import UserRecords from '@/components/Dashboard/UserRecords/index.vue'
|
||||||
import UserStatsCards from '@/components/Dashboard/UserStatsCards/index.vue'
|
import UserStatsCards from '@/components/Dashboard/UserStatsCards/index.vue'
|
||||||
import { USER_STORE } from '@/store/constants'
|
import { SPORTS_STORE, USER_STORE } from '@/store/constants'
|
||||||
|
import { ISport } from '@/types/sports'
|
||||||
import { IAuthUserProfile } from '@/types/user'
|
import { IAuthUserProfile } from '@/types/user'
|
||||||
import { useStore } from '@/use/useStore'
|
import { useStore } from '@/use/useStore'
|
||||||
|
|
||||||
@ -42,7 +43,10 @@
|
|||||||
const authUser: ComputedRef<IAuthUserProfile> = computed(
|
const authUser: ComputedRef<IAuthUserProfile> = computed(
|
||||||
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
() => store.getters[USER_STORE.GETTERS.AUTH_USER_PROFILE]
|
||||||
)
|
)
|
||||||
return { authUser }
|
const sports: ComputedRef<ISport[]> = computed(
|
||||||
|
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
|
||||||
|
)
|
||||||
|
return { authUser, sports }
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user