File tree Expand file tree Collapse file tree 3 files changed +24
-27
lines changed Expand file tree Collapse file tree 3 files changed +24
-27
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import { mapGetters } from 'vuex'
23
23
import StudyCard from ' @/components/StudyCard'
24
24
export default {
25
25
components: { StudyCard },
26
+ middleware: ' checkClassData' ,
26
27
computed: {
27
28
... mapGetters (' modules/class' , [' Lessons' ]),
28
29
},
Original file line number Diff line number Diff line change 4
4
<div class =" Logo" >
5
5
<Logo style =" height : 80vw ; max-height : 350px ; width : 100% ;" />
6
6
</div >
7
+ {{ errorMessages }}
7
8
<div class =" LoginForm" >
8
9
<v-form ref =" form" v-model =" valid" >
9
10
<v-text-field
@@ -45,7 +46,6 @@ export default {
45
46
error: false ,
46
47
errorMessages: ' ' ,
47
48
valid: true ,
48
- exists: false ,
49
49
nameRules: [
50
50
(v ) => !! v || ' クラスIDは必須です' ,
51
51
(v ) => (v && v .length === 6 ) || ' クラスIDは6文字のひらがなです' ,
@@ -56,32 +56,24 @@ export default {
56
56
... mapActions (' modules/class' , [' loadClassData' ]),
57
57
checkInClass () {
58
58
this .loading = true
59
- this .checkExistsClassData (this .classId )
60
- if (this .exists ) {
61
- this .loadClassData (this .classId )
62
- this .$router .push (' classes' )
63
- } else {
64
- this .loading = false
65
- this .error = true
66
- this .errorMessages = ' クラスIDが間違っています'
67
- }
59
+ this .checkExistsClassData (this .classId ).then ((value ) => {
60
+ if (value) {
61
+ this .loadClassData (this .classId )
62
+ this .$router .push (' /classes' )
63
+ } else {
64
+ this .loading = false
65
+ this .error = true
66
+ this .errorMessages = ' クラスIDが間違っています'
67
+ }
68
+ })
68
69
},
69
- checkExistsClassData (classid ) {
70
- if (classid !== ' ' || classid !== null || classid !== ' ' ) {
71
- firebase
72
- .firestore ()
73
- .collection (' classData' )
74
- .doc (classid)
75
- .get ()
76
- .then (() => {
77
- this .exists = true
78
- })
79
- .catch (() => {
80
- this .exists = false
81
- })
82
- } else {
83
- this .exists = false
84
- }
70
+ async checkExistsClassData (classid ) {
71
+ const check = await firebase
72
+ .firestore ()
73
+ .collection (' classData' )
74
+ .doc (classid)
75
+ .get ()
76
+ return check .exists
85
77
},
86
78
},
87
79
}
Original file line number Diff line number Diff line change @@ -20,6 +20,9 @@ export const getters = {
20
20
Lessons ( state ) {
21
21
return state . classData . Lessons
22
22
} ,
23
+ isLoadedClassData : ( state ) => {
24
+ return state . classId !== ''
25
+ } ,
23
26
}
24
27
25
28
export const mutations = {
@@ -41,6 +44,7 @@ export const actions = {
41
44
const classDa = await classDataSnapshot . data ( )
42
45
await dispatch ( 'setClassData' , classDa )
43
46
await dispatch ( 'setClassId' , classId )
47
+ await dispatch ( 'isLoadedClassData' )
44
48
} ,
45
49
setClassData ( { commit } , classData ) {
46
50
commit ( 'setClassData' , classData )
@@ -49,6 +53,6 @@ export const actions = {
49
53
commit ( 'setClassId' , classId )
50
54
} ,
51
55
isLoadedClassData : ( state ) => {
52
- return ! ! state . classData
56
+ return state . classData !== { }
53
57
} ,
54
58
}
You can’t perform that action at this time.
0 commit comments