1
1
<template >
2
2
<div class =" MainPage" >
3
- <div v-if =" classData.lessonsOnCurrentDate .length" >
3
+ <div v-if =" Object.keys( classData.lessonsGroupByPeriod) .length" >
4
4
<period-section
5
- v-for =" (lessons, time, index) in lessonsGroupByPeriod"
5
+ v-for =" (lessons, time, index) in classData. lessonsGroupByPeriod"
6
6
:key =" index"
7
7
:period =" index"
8
8
:time =" time"
@@ -28,23 +28,17 @@ import dayjs from 'dayjs'
28
28
import isToday from ' date-fns/isToday'
29
29
import { vxm } from ' @/store'
30
30
import PeriodSection from ' @/components/PeriodSection.vue'
31
- import classData from ' @/types/store/classData'
32
- import LessonWithId = classData .LessonWithId
33
31
34
- type LessonsGroupedBy = {
35
- [key : string ]: LessonWithId []
36
- }
37
32
type Data = {
38
33
classData: typeof vxm .classData
39
34
}
40
35
41
36
type Computed = {
42
37
today: boolean
43
38
dateTitle: string
44
- lessonsGroupByPeriod: LessonsGroupedBy
45
39
}
46
40
47
- export default Vue .extend < Data , unknown , Computed , unknown > ({
41
+ export default Vue .extend ({
48
42
components: { PeriodSection },
49
43
layout: ' classes' ,
50
44
data() {
@@ -53,23 +47,24 @@ export default Vue.extend<Data, unknown, Computed, unknown>({
53
47
}
54
48
},
55
49
computed: {
50
+ currentDate() {
51
+ return vxm .app .currentDate
52
+ },
56
53
today() {
57
54
return isToday (vxm .app .currentDate )
58
55
},
59
56
dateTitle() {
60
57
return dayjs (vxm .app .currentDate ).format (' M/D' )
61
58
},
62
- lessonsGroupByPeriod() {
63
- const groupBy = (targets : LessonWithId [], key : keyof LessonWithId ) =>
64
- targets .reduce ((acc : LessonsGroupedBy , currentLesson : LessonWithId ) => {
65
- const valueToGroup = currentLesson [key ].toString ()
66
- acc [valueToGroup ] = acc [valueToGroup ] || []
67
- acc [valueToGroup ].push (currentLesson )
68
- return acc
69
- }, {})
70
- return groupBy (this .classData .lessonsOnCurrentDate , ' startTime' )
59
+ },
60
+ watch: {
61
+ async currentDate() {
62
+ await this .classData .getLessonsByCurrentDate ()
71
63
},
72
64
},
65
+ async mounted() {
66
+ await this .classData .getLessonsByCurrentDate ()
67
+ },
73
68
})
74
69
</script >
75
70
0 commit comments