Skip to content

Commit f461e9b

Browse files
authored
Merge pull request #164 from kaizumaki/feature/issue-160-display-period
N時間目の表示を修正(period, startTime, endTimeの設定)
2 parents 7f74203 + 17a8ecf commit f461e9b

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

src/components/PeriodCard.vue

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@
22
<div class="PeriodCard">
33
<div class="PeriodCard-NumberBlock">
44
<div class="PeriodCard-Number">
5-
<span class="PeriodCard-Number-Num">1</span>
5+
<span class="PeriodCard-Number-Num">{{ period + 1 }}</span>
66
<span class="PeriodCard-Number-Text">時間目</span>
77
</div>
88
<div class="PeriodCard-Time">
9-
<span>00:00</span>
9+
<span>{{ formatDate(time) }}</span>
1010
<span>|</span>
11-
<span>00:00</span>
11+
<span>{{ formatDate(maxEndTime) }}</span>
1212
</div>
1313
</div>
1414
<v-row>
15-
<v-col
16-
v-for="(item, i) in classData.lessonsOnCurrentDate"
17-
:key="i"
18-
cols="12"
19-
md="6"
20-
>
15+
<v-col v-for="(item, i) in classData" :key="i" cols="12" md="6">
2116
<content-card :lesson="item" />
2217
</v-col>
2318
</v-row>
@@ -27,19 +22,36 @@
2722
<script lang="ts">
2823
import Vue from 'vue'
2924
import dayjs from 'dayjs'
25+
import minMax from 'dayjs/plugin/minMax'
3026
import ContentCard from '@/components/ContentCard.vue'
27+
import { classData } from '@/types/store/classData'
28+
dayjs.extend(minMax)
3129
3230
export default Vue.extend({
3331
components: { ContentCard },
3432
props: {
33+
period: {
34+
type: Number,
35+
default: 0
36+
},
37+
time: {
38+
type: String,
39+
default: ''
40+
},
3541
classData: {
36-
type: Object,
37-
default: () => {}
42+
type: Array as () => classData.LessonWithId[],
43+
default: () => []
44+
}
45+
},
46+
computed: {
47+
maxEndTime() {
48+
const endTimeArray = this.classData.map(value => dayjs(value.endTime))
49+
return dayjs.max(...endTimeArray)
3850
}
3951
},
4052
methods: {
4153
formatDate(date: Date): string {
42-
return dayjs(date).format('HH:MM')
54+
return dayjs(date).format('HH:mm')
4355
}
4456
}
4557
})

src/pages/classes/index.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<template>
22
<div class="MainPage">
33
<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+
/>
511
</div>
612
<div v-else-if="today" class="Classes-Outer">
713
<h1 class="Classes-Title">
@@ -22,14 +28,20 @@ import dayjs from 'dayjs'
2228
import isToday from 'date-fns/isToday'
2329
import { vxm } from '@/store'
2430
import PeriodCard from '@/components/PeriodCard.vue'
31+
import { classData } from '@/types/store/classData'
32+
import LessonWithId = classData.LessonWithId
2533
34+
type LessonsGroupedBy = {
35+
[key: string]: LessonWithId[]
36+
}
2637
type Data = {
2738
classData: typeof vxm.classData
2839
}
2940
3041
type Computed = {
3142
today: boolean
3243
dateTitle: string
44+
lessonsGroupByPeriod: LessonsGroupedBy
3345
}
3446
3547
export default Vue.extend<Data, unknown, Computed, unknown>({
@@ -46,6 +58,16 @@ export default Vue.extend<Data, unknown, Computed, unknown>({
4658
},
4759
dateTitle() {
4860
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')
4971
}
5072
}
5173
})

0 commit comments

Comments
 (0)