Skip to content

Commit 6827189

Browse files
setup messages
1 parent 7fd8723 commit 6827189

File tree

6 files changed

+96
-15
lines changed

6 files changed

+96
-15
lines changed

src/App.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<template>
2-
<div>
2+
<v-app id="keep-learning-app">
33
<component v-if="initDone" :is="layout"/>
4-
<v-app v-else>
5-
<v-progress-linear indeterminate></v-progress-linear>
6-
</v-app>
7-
</div>
4+
<v-progress-linear
5+
v-else
6+
indeterminate
7+
></v-progress-linear>
8+
</v-app>
89
</template>
910

1011
<script lang="ts">

src/layouts/LayoutDefault.vue

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<v-app id="keep-learning-app">
2+
<div>
33
<v-app-bar
44
app
55
color="primary"
@@ -45,6 +45,23 @@
4545
</slot>
4646
</v-main>
4747

48+
<v-snackbar
49+
:value="messageShow"
50+
@input="setMessage"
51+
>
52+
{{ messageText }}
53+
<template #action="{ attrs }">
54+
<v-btn
55+
color="pink"
56+
text
57+
v-bind="attrs"
58+
@click="hideMessage"
59+
>
60+
Close
61+
</v-btn>
62+
</template>
63+
</v-snackbar>
64+
4865
<!-- TODO: is this needed?
4966
<v-bottom-navigation
5067
app
@@ -58,19 +75,29 @@
5875
<v-spacer></v-spacer>
5976
</v-bottom-navigation>
6077
-->
61-
</v-app>
78+
</div>
6279
</template>
6380

6481
<script lang="ts">
6582
import { User } from '@/interfaces/user'
6683
import { Vue, Component } from 'vue-property-decorator'
67-
import { mapGetters } from 'vuex'
84+
import { mapGetters, mapMutations, mapState } from 'vuex'
6885
import KLAvatar from '@/components/KLAvatar.vue'
6986
7087
@Component({
7188
computed: {
7289
...mapGetters({
7390
user: 'account/loggedInUser'
91+
}),
92+
...mapState('message', {
93+
messageShow: 'show',
94+
messageText: 'text'
95+
})
96+
},
97+
methods: {
98+
...mapMutations('message', {
99+
showMessage: 'SHOW_MESSAGE',
100+
hideMessage: 'HIDE_MESSAGE'
74101
})
75102
},
76103
components: {
@@ -79,6 +106,19 @@ import KLAvatar from '@/components/KLAvatar.vue'
79106
})
80107
export default class LayoutDefault extends Vue {
81108
user!: User
109+
110+
messageShow!: boolean
111+
messageText!: string
112+
showMessage!: CallableFunction
113+
hideMessage!: CallableFunction
114+
115+
setMessage (show: boolean): void {
116+
if (show) {
117+
this.showMessage()
118+
} else {
119+
this.hideMessage()
120+
}
121+
}
82122
}
83123
</script>
84124

src/layouts/LayoutNoAppbar.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<template>
2-
<v-app>
3-
<v-main>
4-
<router-view/>
5-
</v-main>
6-
</v-app>
2+
<v-main>
3+
<router-view/>
4+
</v-main>
75
</template>
86

97
<script lang="ts">

src/store/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Vuex from 'vuex'
33
import { account } from './account'
44
import { classroom } from './classroom'
55
import { readingExercise } from './reading-exercises'
6+
import { message } from './message'
67

78
Vue.use(Vuex)
89

@@ -20,6 +21,7 @@ export default new Vuex.Store({
2021
modules: {
2122
account,
2223
classroom,
23-
readingExercise
24+
readingExercise,
25+
message
2426
}
2527
})

src/store/message.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Module } from 'vuex'
2+
import { RootState } from './index'
3+
4+
declare interface MessageState {
5+
show: boolean;
6+
text: string;
7+
color: string;
8+
}
9+
10+
export const message: Module<MessageState, RootState> = {
11+
namespaced: true,
12+
13+
state: {
14+
show: false,
15+
text: '',
16+
color: 'success'
17+
},
18+
19+
mutations: {
20+
SHOW_MESSAGE (state, text) {
21+
state.text = text
22+
state.show = true
23+
},
24+
25+
HIDE_MESSAGE (state) {
26+
state.show = false
27+
}
28+
}
29+
}

src/views/classroom/ClassroomStudents.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ import { VForm } from '@/interfaces/vuetify'
136136
import { snakeCaseToCamelCase, unexpectedExc } from '@/utils'
137137
import { assertErrCode, status } from '@/utils/status-codes'
138138
import { Vue, Component } from 'vue-property-decorator'
139-
import { mapState } from 'vuex'
139+
import { mapMutations, mapState } from 'vuex'
140140
import KLDialogConfirm from '@/components/KLDialogConfirm.vue'
141141
import { Api } from '@/api'
142142
@@ -146,6 +146,11 @@ import { Api } from '@/api'
146146
classroom: 'currentClassroom'
147147
})
148148
},
149+
methods: {
150+
...mapMutations('message', {
151+
showMessage: 'SHOW_MESSAGE'
152+
})
153+
},
149154
components: {
150155
KLDialogConfirm
151156
}
@@ -185,6 +190,7 @@ export default class ClassroomStudents extends Vue {
185190
*/
186191
showAddStudent = false
187192
loadingAddStudent = false
193+
showMessage!: CallableFunction
188194
189195
name = ''
190196
email = ''
@@ -206,6 +212,7 @@ export default class ClassroomStudents extends Vue {
206212
this.$store.dispatch('classroom/addStudents', [payload])
207213
.then(() => {
208214
(this.$refs.addStudentForm as VForm).reset()
215+
this.showMessage('Student added.')
209216
})
210217
.catch(err => {
211218
if (assertErrCode(err, status.HTTP_400_BAD_REQUEST)) {
@@ -249,6 +256,7 @@ export default class ClassroomStudents extends Vue {
249256
this.$store.dispatch('classroom/removeStudents', [payload])
250257
.then(() => {
251258
this.removeConfirm = false
259+
this.showMessage('Student removed.')
252260
})
253261
.catch(unexpectedExc)
254262
.finally(() => {
@@ -263,6 +271,9 @@ export default class ClassroomStudents extends Vue {
263271
Api.classroom.resendPasswordEmail(this.classroom.pk, {
264272
email: student.email
265273
})
274+
.then(() => {
275+
this.showMessage('Email sent.')
276+
})
266277
.catch(unexpectedExc)
267278
}
268279
}

0 commit comments

Comments
 (0)