Fix notifications not being able to be dismissed (#270)

* Change undefined check to null check

* Make notification index and action index more clear

Fixes #178
This commit is contained in:
venashial 2021-06-21 19:32:17 +00:00 committed by GitHub
parent be0e18d4b0
commit a58811b1bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@
</div> </div>
<div v-if="notifications.length !== 0"> <div v-if="notifications.length !== 0">
<div <div
v-for="notification in notifications" v-for="(notification, notificationIndex) in notifications"
:key="notification.id" :key="notification.id"
class="notification columns" class="notification columns"
> >
@ -31,15 +31,17 @@
</div> </div>
<div v-if="notification.actions.length > 0" class="actions"> <div v-if="notification.actions.length > 0" class="actions">
<button <button
v-for="(action, index) in notification.actions" v-for="(action, actionIndex) in notification.actions"
:key="index" :key="actionIndex"
@click="performAction(notification, index)" @click="performAction(notification, notificationIndex, actionIndex)"
> >
{{ action.title }} {{ action.title }}
</button> </button>
</div> </div>
<div v-else class="actions"> <div v-else class="actions">
<button @click="performAction(notification, null)">Dismiss</button> <button @click="performAction(notification, notificationIndex, null)">
Dismiss
</button>
</div> </div>
</div> </div>
</div> </div>
@ -71,14 +73,16 @@ export default {
} }
}, },
methods: { methods: {
async performAction(notification, index) { async performAction(notification, notificationIndex, actionIndex) {
this.$nuxt.$loading.start() this.$nuxt.$loading.start()
try { try {
if (typeof index !== 'undefined') { if (actionIndex !== null) {
const config = { const config = {
method: notification.actions[index].action_route[0].toLowerCase(), method: notification.actions[
url: `${notification.actions[index].action_route[1]}`, actionIndex
].action_route[0].toLowerCase(),
url: `${notification.actions[actionIndex].action_route[1]}`,
headers: { headers: {
Authorization: this.$auth.token, Authorization: this.$auth.token,
}, },
@ -92,7 +96,7 @@ export default {
this.$auth.headers this.$auth.headers
) )
this.notifications.splice(index, 1) this.notifications.splice(notificationIndex, 1)
this.$store.dispatch('user/fetchNotifications', { force: true }) this.$store.dispatch('user/fetchNotifications', { force: true })
} catch (err) { } catch (err) {
this.$notify({ this.$notify({