1
1
<template >
2
2
<div class =" MainPage" >
3
3
<div v-if =" classData.lessonsOnCurrentDate.length" >
4
- <period-card :class-data =" classData" />
4
+ <period-card
5
+ v-for =" (lessons, time, index) in lessonsGroupByPeriod"
6
+ :key =" index"
7
+ :period =" index"
8
+ :time =" time"
9
+ :class-data =" lessons"
10
+ />
5
11
</div >
6
12
<div v-else-if =" today" class =" Classes-Outer" >
7
13
<h1 class =" Classes-Title" >
@@ -22,14 +28,20 @@ import dayjs from 'dayjs'
22
28
import isToday from ' date-fns/isToday'
23
29
import { vxm } from ' @/store'
24
30
import PeriodCard from ' @/components/PeriodCard.vue'
31
+ import { classData } from ' @/types/store/classData'
32
+ import LessonWithId = classData .LessonWithId
25
33
34
+ type LessonsGroupedBy = {
35
+ [key : string ]: LessonWithId []
36
+ }
26
37
type Data = {
27
38
classData: typeof vxm .classData
28
39
}
29
40
30
41
type Computed = {
31
42
today: boolean
32
43
dateTitle: string
44
+ lessonsGroupByPeriod: LessonsGroupedBy
33
45
}
34
46
35
47
export default Vue .extend <Data , unknown , Computed , unknown >({
@@ -46,6 +58,16 @@ export default Vue.extend<Data, unknown, Computed, unknown>({
46
58
},
47
59
dateTitle() {
48
60
return dayjs (vxm .app .currentDate ).format (' M/D' )
61
+ },
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' )
49
71
}
50
72
}
51
73
})
0 commit comments