Skip to content

Commit dbd0a14

Browse files
committed
lessonsGroupByPeriodを整理、storeのmoduleから呼び出すように修正
1 parent 041a7ce commit dbd0a14

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

src/pages/classes/index.vue

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div class="MainPage">
3-
<div v-if="classData.lessonsOnCurrentDate.length">
3+
<div v-if="Object.keys(classData.lessonsGroupByPeriod).length">
44
<period-section
5-
v-for="(lessons, time, index) in lessonsGroupByPeriod"
5+
v-for="(lessons, time, index) in classData.lessonsGroupByPeriod"
66
:key="index"
77
:period="index"
88
:time="time"
@@ -28,23 +28,17 @@ import dayjs from 'dayjs'
2828
import isToday from 'date-fns/isToday'
2929
import { vxm } from '@/store'
3030
import PeriodSection from '@/components/PeriodSection.vue'
31-
import classData from '@/types/store/classData'
32-
import LessonWithId = classData.LessonWithId
3331
34-
type LessonsGroupedBy = {
35-
[key: string]: LessonWithId[]
36-
}
3732
type Data = {
3833
classData: typeof vxm.classData
3934
}
4035
4136
type Computed = {
4237
today: boolean
4338
dateTitle: string
44-
lessonsGroupByPeriod: LessonsGroupedBy
4539
}
4640
47-
export default Vue.extend<Data, unknown, Computed, unknown>({
41+
export default Vue.extend({
4842
components: { PeriodSection },
4943
layout: 'classes',
5044
data() {
@@ -53,23 +47,24 @@ export default Vue.extend<Data, unknown, Computed, unknown>({
5347
}
5448
},
5549
computed: {
50+
currentDate() {
51+
return vxm.app.currentDate
52+
},
5653
today() {
5754
return isToday(vxm.app.currentDate)
5855
},
5956
dateTitle() {
6057
return dayjs(vxm.app.currentDate).format('M/D')
6158
},
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+
currentDate() {
62+
this.classData.getLessonsByCurrentDate()
7163
},
7264
},
65+
mounted() {
66+
this.classData.getLessonsByCurrentDate()
67+
},
7368
})
7469
</script>
7570

src/pages/edit/index.vue

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div class="MainPage">
3-
<div v-if="classData.lessonsOnCurrentDate.length">
3+
<div v-if="Object.keys(classData.lessonsGroupByPeriod).length > 0">
44
<period-section
5-
v-for="(lessons, time, index) in lessonsGroupByPeriod"
5+
v-for="(lessons, time, index) in classData.lessonsGroupByPeriod"
66
:key="index"
77
:period="index"
88
:time="time"
@@ -136,11 +136,6 @@ import EditLessonScreenBottomSheet from '@/components/EditLessonScreenBottomShee
136136
import EditLessonScreen from '@/components/EditLessonScreen.vue'
137137
import EditingVisibilityDialog from '@/components/EditingVisibilityDialog.vue'
138138
import classData from '@/types/store/classData'
139-
import LessonWithId = classData.LessonWithId
140-
141-
type LessonsGroupedBy = {
142-
[key: string]: LessonWithId[]
143-
}
144139
145140
type DataType = {
146141
classData: typeof vxm.classData
@@ -153,7 +148,6 @@ type DataType = {
153148
type Computed = {
154149
today: boolean
155150
dateTitle: string
156-
lessonsGroupByPeriod: LessonsGroupedBy
157151
}
158152
159153
const editPageValueDefault = {
@@ -193,23 +187,24 @@ export default Vue.extend({
193187
}
194188
},
195189
computed: {
190+
currentDate() {
191+
return vxm.app.currentDate
192+
},
196193
today() {
197194
return isToday(vxm.app.currentDate)
198195
},
199196
dateTitle() {
200197
return dayjs(vxm.app.currentDate).format('M/D')
201198
},
202-
lessonsGroupByPeriod() {
203-
const groupBy = (targets: LessonWithId[], key: keyof LessonWithId) =>
204-
targets.reduce((acc: LessonsGroupedBy, currentLesson: LessonWithId) => {
205-
const valueToGroup = currentLesson[key].toString()
206-
acc[valueToGroup] = acc[valueToGroup] || []
207-
acc[valueToGroup].push(currentLesson)
208-
return acc
209-
}, {})
210-
return groupBy(vxm.classData.lessonsOnCurrentDate, 'startTime')
199+
},
200+
watch: {
201+
currentDate() {
202+
this.classData.getLessonsByCurrentDate()
211203
},
212204
},
205+
mounted() {
206+
this.classData.getLessonsByCurrentDate()
207+
},
213208
methods: {
214209
onCollapseEditLessonScreen(): void {
215210
this.toggleScreen()

0 commit comments

Comments
 (0)