Skip to content

Commit 31338ce

Browse files
authored
Merge pull request #394 from kaizumaki/aws-migration
graphqlによりstoreを大幅に改修
2 parents f5fd546 + 50c5ab5 commit 31338ce

File tree

14 files changed

+171
-125
lines changed

14 files changed

+171
-125
lines changed

src/components/EditLessonScreen.vue

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -231,27 +231,26 @@ export default Vue.extend({
231231
this.changeLesson()
232232
}
233233
},
234-
changeLesson() {
235-
const lessonData: classData.Lesson = this.buildLessonData()
236-
vxm.classData
237-
.changeLesson({ editData: lessonData, id: this.lessonData.lessonId })
238-
.then(() => {
239-
this.$emit('collapse')
240-
})
241-
.catch(() => {
242-
this.error = true
234+
async changeLesson() {
235+
try {
236+
const lessonData: classData.Lesson = await this.buildLessonData()
237+
await vxm.classData.changeLesson({
238+
editData: lessonData,
239+
id: this.lessonData.lessonId,
243240
})
241+
await this.$emit('collapse')
242+
} catch {
243+
this.error = true
244+
}
244245
},
245-
registerLesson() {
246-
const lessonData: classData.Lesson = this.buildLessonData()
247-
vxm.classData
248-
.registerLesson(lessonData)
249-
.then(() => {
250-
this.$emit('collapse')
251-
})
252-
.catch(() => {
253-
this.error = true
254-
})
246+
async registerLesson() {
247+
try {
248+
const lessonData: classData.Lesson = await this.buildLessonData()
249+
await vxm.classData.registerLesson(lessonData)
250+
await this.$emit('collapse')
251+
} catch {
252+
this.error = true
253+
}
255254
},
256255
buildLessonData(): classData.Lesson {
257256
const startTimeStr: string =

src/components/PeriodSection.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default Vue.extend({
4545
},
4646
classData: {
4747
type: Array as () => classData.LessonWithId[],
48-
default: () => [],
48+
default: [],
4949
},
5050
editable: {
5151
type: Boolean,

src/layouts/classes.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ export default Vue.extend({
138138
this.loading = false
139139
},
140140
methods: {
141-
clickLogout() {
142-
vxm.classData.unloadClassData().then(() => {
143-
this.$router.push('/')
144-
})
141+
async clickLogout() {
142+
await vxm.user.logout()
143+
await vxm.app.resetDate()
144+
await this.$router.push('/')
145145
},
146146
},
147147
})

src/layouts/protected.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,6 @@ export default Vue.extend({
140140
this.loading = false
141141
},
142142
methods: {
143-
signout() {
144-
vxm.user.logout()
145-
this.$router.push('/')
146-
},
147-
148143
unloadClassData() {
149144
vxm.classData.unloadClassData()
150145
},

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+
async currentDate() {
62+
await this.classData.getLessonsByCurrentDate()
7163
},
7264
},
65+
async mounted() {
66+
await 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"
@@ -138,11 +138,6 @@ import EditLessonScreenBottomSheet from '@/components/EditLessonScreenBottomShee
138138
import EditLessonScreen from '@/components/EditLessonScreen.vue'
139139
import EditingVisibilityDialog from '@/components/EditingVisibilityDialog.vue'
140140
import classData from '@/types/store/classData'
141-
import LessonWithId = classData.LessonWithId
142-
143-
type LessonsGroupedBy = {
144-
[key: string]: LessonWithId[]
145-
}
146141
147142
type DataType = {
148143
classData: typeof vxm.classData
@@ -155,7 +150,6 @@ type DataType = {
155150
type Computed = {
156151
today: boolean
157152
dateTitle: string
158-
lessonsGroupByPeriod: LessonsGroupedBy
159153
}
160154
161155
type editPageValueType = {
@@ -214,23 +208,24 @@ export default Vue.extend({
214208
}
215209
},
216210
computed: {
211+
currentDate() {
212+
return vxm.app.currentDate
213+
},
217214
today() {
218215
return isToday(vxm.app.currentDate)
219216
},
220217
dateTitle() {
221218
return dayjs(vxm.app.currentDate).format('M/D')
222219
},
223-
lessonsGroupByPeriod() {
224-
const groupBy = (targets: LessonWithId[], key: keyof LessonWithId) =>
225-
targets.reduce((acc: LessonsGroupedBy, currentLesson: LessonWithId) => {
226-
const valueToGroup = currentLesson[key].toString()
227-
acc[valueToGroup] = acc[valueToGroup] || []
228-
acc[valueToGroup].push(currentLesson)
229-
return acc
230-
}, {})
231-
return groupBy(vxm.classData.lessonsOnCurrentDate, 'startTime')
220+
},
221+
watch: {
222+
async currentDate() {
223+
await this.classData.getLessonsByCurrentDate()
232224
},
233225
},
226+
async mounted() {
227+
await this.classData.getLessonsByCurrentDate()
228+
},
234229
methods: {
235230
onCollapseEditLessonScreen(): void {
236231
this.toggleScreen()

src/pages/index.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,17 @@ export default Vue.extend({
144144
methods: {
145145
async loginToClass() {
146146
this.loading = true
147-
148147
try {
148+
await vxm.user.setAuthModeIsAPIKEY(true)
149149
const result = (await API.graphql({
150150
query: getClass,
151151
variables: { id: this.classId },
152152
authMode: GRAPHQL_AUTH_MODE.API_KEY,
153153
})) as GraphQLResult<GetClassQuery>
154-
155154
const className = result?.data?.getClass?.className as string
156-
const lessons = result.data?.getClass?.lessons?.items as any[]
157-
158155
await vxm.classData.setClassData({
159156
classId: this.classId,
160157
className,
161-
lessons,
162158
})
163159
await this.$router.push('/classes')
164160
} catch {

src/pages/lesson/index.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,14 @@ export default Vue.extend({
237237
: dayjs(this.lesson.endTime).format('H:mm(M/D)')
238238
},
239239
},
240-
mounted() {
241-
this.$nextTick(function () {
242-
const data:
243-
| LessonWithId
244-
| undefined = vxm.classData.lessonsOnCurrentDate.find(
240+
async mounted() {
241+
const lessonList = vxm.user.isLoginWithAPIKEY
242+
? await vxm.classData.lessonsOnCurrentDateAuthModeAPIKEY(
243+
vxm.app.currentDate
244+
)
245+
: await vxm.classData.lessonsOnCurrentDate(vxm.app.currentDate)
246+
await this.$nextTick(function () {
247+
const data: LessonWithId | undefined = lessonList.find(
245248
(e) => this.$route.query.lessonId === e.id
246249
) as LessonWithId | undefined
247250
this.lesson = data ?? this.dummyLesson

src/pages/user/editUserData.vue

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,16 @@ export default Vue.extend<Data, Methods, Computed, unknown>({
217217
// })
218218
}
219219
}
220-
this.$router.push('/edit')
220+
await this.$router.push('/edit')
221221
},
222222
async doLogout(): Promise<void> {
223-
await Auth.signOut()
224-
.then(() => {
225-
vxm.user.logout()
226-
this.$router.push('/')
227-
})
228-
.catch(() => {
229-
this.error = true
230-
})
223+
try {
224+
await vxm.user.logout()
225+
await vxm.app.resetDate()
226+
await this.$router.push('/')
227+
} catch {
228+
this.error = true
229+
}
231230
},
232231
},
233232
})

src/pages/user/logout.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import Vue from 'vue'
1616
import BaseBottomSheetLayer from '@/components/BaseBottomSheetLayer.vue'
1717
import { Auth } from 'aws-amplify'
18+
import { vxm } from '@/store'
1819
1920
export default Vue.extend({
2021
components: { BaseBottomSheetLayer },
@@ -31,14 +32,14 @@ export default Vue.extend({
3132
methods: {
3233
async doLogout(): Promise<void> {
3334
this.loading = true
34-
await Auth.signOut()
35-
.then(() => {
36-
this.$router.push('/')
37-
})
38-
.catch(() => {
39-
this.loading = false
40-
this.error = true
41-
})
35+
try {
36+
await Auth.signOut()
37+
await vxm.app.resetDate()
38+
await this.$router.push('/')
39+
} catch {
40+
this.loading = false
41+
this.error = true
42+
}
4243
},
4344
},
4445
})

0 commit comments

Comments
 (0)