|
1 | 1 | <template>
|
2 | 2 | <div class="MainPage">
|
3 | 3 | <div v-if="classData.lessonsOnCurrentDate.length">
|
4 |
| - <period-card-editable :class-data="classData" @clickEditButton="doEdit" /> |
| 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 | + :editable="true" |
| 11 | + @clickEditButton="doEdit" |
| 12 | + /> |
5 | 13 | <ul class="Classes-List">
|
6 | 14 | <li>おうちで時間割について</li>
|
7 | 15 | <li>お問い合わせ</li>
|
@@ -44,20 +52,31 @@ import Vue from 'vue'
|
44 | 52 | import dayjs from 'dayjs'
|
45 | 53 | import isToday from 'date-fns/isToday'
|
46 | 54 | import { vxm } from '@/store'
|
47 |
| -import PeriodCardEditable from '@/components/PeriodCardEditable.vue' |
| 55 | +import PeriodCard from '@/components/PeriodCard.vue' |
48 | 56 | import SimpleBottomSheet from '@/components/SimpleBottomSheet.vue'
|
49 | 57 | import EditingScreen from '@/components/EditingScreen.vue'
|
50 |
| -import { classData } from '~/types/store/classData' |
| 58 | +import { classData } from '@/types/store/classData' |
| 59 | +import LessonWithId = classData.LessonWithId |
| 60 | +
|
| 61 | +type LessonsGroupedBy = { |
| 62 | + [key: string]: LessonWithId[] |
| 63 | +} |
51 | 64 |
|
52 | 65 | type DataType = {
|
53 | 66 | classData: typeof vxm.classData
|
54 | 67 | editingMode: boolean
|
55 | 68 | editPageValue: object
|
56 | 69 | }
|
57 | 70 |
|
| 71 | +type Computed = { |
| 72 | + today: boolean |
| 73 | + dateTitle: string |
| 74 | + lessonsGroupByPeriod: LessonsGroupedBy |
| 75 | +} |
| 76 | +
|
58 | 77 | export default Vue.extend({
|
59 | 78 | components: {
|
60 |
| - PeriodCardEditable, |
| 79 | + PeriodCard, |
61 | 80 | SimpleBottomSheet,
|
62 | 81 | EditingScreen
|
63 | 82 | },
|
@@ -100,6 +119,16 @@ export default Vue.extend({
|
100 | 119 | },
|
101 | 120 | dateTitle() {
|
102 | 121 | return dayjs(vxm.app.currentDate).format('M/D')
|
| 122 | + }, |
| 123 | + lessonsGroupByPeriod() { |
| 124 | + const groupBy = (targets: LessonWithId[], key: keyof LessonWithId) => |
| 125 | + targets.reduce((acc: LessonsGroupedBy, currentLesson: LessonWithId) => { |
| 126 | + const valueToGroup = currentLesson[key].toString() |
| 127 | + acc[valueToGroup] = acc[valueToGroup] || [] |
| 128 | + acc[valueToGroup].push(currentLesson) |
| 129 | + return acc |
| 130 | + }, {}) |
| 131 | + return groupBy(vxm.classData.lessonsOnCurrentDate, 'startTime') |
103 | 132 | }
|
104 | 133 | },
|
105 | 134 | methods: {
|
|
0 commit comments