Skip to content

Commit 3f4ab3b

Browse files
fixbug layout not updated
1 parent 978a9a5 commit 3f4ab3b

File tree

7 files changed

+78
-266
lines changed

7 files changed

+78
-266
lines changed

src/App.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { unexpectedExc } from './utils'
2626
})
2727
export default class App extends Vue {
2828
user!: User
29-
isAuthenticatedUser = false
3029
loading = false
3130
initDone = false
3231
@@ -37,9 +36,6 @@ export default class App extends Vue {
3736
setUserInfo (): void {
3837
this.loading = true
3938
this.$store.dispatch('account/getInfo')
40-
.then(() => {
41-
this.isAuthenticatedUser = true
42-
})
4339
.catch(unexpectedExc)
4440
.finally(() => {
4541
this.loading = false
@@ -51,7 +47,7 @@ export default class App extends Vue {
5147
const meta = this.$route.meta
5248
5349
if (meta !== undefined) {
54-
if (this.isAuthenticatedUser) {
50+
if (this.user !== undefined) {
5551
if (
5652
this.user.user_type === 'teacher' &&
5753
meta.teacherLayout !== undefined

src/plugins/axios.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ function handleResponseError (error) {
9191
if (isUnauthorized(error)) {
9292
/* eslint-disable brace-style */
9393

94-
if (noToken()) {
94+
if (isLoginRoute()) {
95+
return Promise.reject(error)
96+
}
97+
98+
else if (noToken()) {
9599
goToLogin()
96100
return Promise.reject() // Will not display unexpected error message to user
97101
}
@@ -114,10 +118,6 @@ function handleResponseError (error) {
114118
return Promise.reject(error)
115119
}
116120

117-
else if (isLoginRoute()) {
118-
return Promise.reject(error)
119-
}
120-
121121
else {
122122
const response = tryAgainAfterRefreshingToken(error)
123123
return Promise.resolve(response)

src/views/auth/Login.vue

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,24 @@ import { Vue, Component, Emit } from 'vue-property-decorator'
6060
import { LoginReq } from '@/interfaces/api/account'
6161
import { unexpectedExc } from '@/utils'
6262
import { assertErrCode, status } from '@/utils/status-codes'
63+
import { mapState } from 'vuex'
6364
64-
@Component
65+
@Component({
66+
computed: {
67+
...mapState('account', [
68+
'isTeacher'
69+
])
70+
}
71+
})
6572
export default class Login extends Vue {
6673
email = ''
6774
password = ''
6875
showPassword = false
6976
loading = false
7077
errorMsg = ''
78+
isTeacher!: boolean
7179
72-
login (): void {
80+
async login (): Promise<void> {
7381
this.errorMsg = ''
7482
if (this.loading) return
7583
this.loading = true
@@ -79,21 +87,47 @@ export default class Login extends Vue {
7987
password: this.password
8088
}
8189
82-
this.$store.dispatch('account/login', payload)
83-
.then(() => {
84-
// TODO: implement ?next
90+
try {
91+
await this.$store.dispatch('account/login', payload)
92+
await this.$store.dispatch('account/getInfo')
93+
// TODO: implement ?next
94+
if (this.isTeacher) {
8595
this.$router.push({ name: 'Home' })
86-
})
87-
.catch(error => {
88-
if (assertErrCode(error, status.HTTP_401_UNAUTHORIZED)) {
89-
this.errorMsg = error.response.data.detail
90-
} else {
91-
unexpectedExc(error)
92-
}
93-
})
94-
.finally(() => {
95-
this.loading = false
96-
})
96+
} else {
97+
this.$router.push({ name: 'ClassroomList' })
98+
}
99+
} catch (error) {
100+
if (assertErrCode(error, status.HTTP_401_UNAUTHORIZED)) {
101+
this.errorMsg = error.response.data.detail
102+
} else {
103+
unexpectedExc(error)
104+
}
105+
} finally {
106+
this.loading = false
107+
}
108+
109+
// this.$store.dispatch('account/login', payload)
110+
// .then(() => {
111+
// this.$store.dispatch('account/getInfo')
112+
// .then(() => {
113+
// // TODO: implement ?next
114+
// if (this.isTeacher) {
115+
// this.$router.push({ name: 'Home' })
116+
// } else {
117+
// this.$router.push({ name: 'ClassroomList' })
118+
// }
119+
// })
120+
// })
121+
// .catch(error => {
122+
// if (assertErrCode(error, status.HTTP_401_UNAUTHORIZED)) {
123+
// this.errorMsg = error.response.data.detail
124+
// } else {
125+
// unexpectedExc(error)
126+
// }
127+
// })
128+
// .finally(() => {
129+
// this.loading = false
130+
// })
97131
}
98132
99133
@Emit('change-page')

src/views/classroom/ClassroomExercisesReadingStudent.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default class ClassroomExercisesReadingStudent extends Vue {
4848
classroom!: Classroom
4949
5050
get exercises (): ClassroomReadingExercise[] {
51+
if (this.classroom === undefined) return []
5152
return this.classroom.reading_exercises
5253
}
5354
}

src/views/classroom/ClassroomList.vue

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@
4141
v-for="classroom of classrooms"
4242
:key="classroom.pk"
4343
link
44-
:to="{
45-
name: 'ClassroomOverview',
46-
params: {
47-
pk: classroom.pk
48-
}
49-
}"
44+
:to="getClassroomLink(classroom)"
5045
>
5146
<v-list-item-content v-text="classroom.name" />
5247
</v-list-item>
@@ -60,6 +55,7 @@
6055
import { Classroom } from '@/interfaces/classroom'
6156
import { unexpectedExc } from '@/utils'
6257
import { Vue, Component } from 'vue-property-decorator'
58+
import { Location } from 'vue-router'
6359
import { mapGetters, mapState } from 'vuex'
6460
6561
@Component({
@@ -95,6 +91,24 @@ export default class ClassroomList extends Vue {
9591
this.listClassroom()
9692
}
9793
94+
getClassroomLink (classroom: Classroom): Location {
95+
if (this.isTeacher) {
96+
return {
97+
name: 'ClassroomOverview',
98+
params: {
99+
pk: classroom.pk.toString()
100+
}
101+
}
102+
} else {
103+
return {
104+
name: 'ClassroomExercisesReading',
105+
params: {
106+
pk: classroom.pk.toString()
107+
}
108+
}
109+
}
110+
}
111+
98112
/**
99113
* List
100114
*/

0 commit comments

Comments
 (0)