notification: fix widget toggle read status

This commit is contained in:
Julien Fastré 2021-12-29 23:09:26 +01:00
parent 9ddfd194be
commit 1576507f7e
2 changed files with 24 additions and 29 deletions

View File

@ -1,38 +1,35 @@
import {createApp} from "vue"; import {createApp} from "vue";
import NotificationReadToggle from "ChillMainAssets/vuejs/_components/Notification/NotificationReadToggle.vue"; import NotificationReadToggle from "ChillMainAssets/vuejs/_components/Notification/NotificationReadToggle.vue";
const App = {
template: '<notification-read-toggle ' +
':notificationId="notificationId" ' +
':isRead="isRead"' +
'@markRead="onMarkRead" @markUnread="onMarkUnread"' +
'></notification-read-toggle>',
components: {
NotificationReadToggle,
},
methods: {
onMarkRead() {
this.isRead = true;
},
onMarkUnread() {
this.isRead = false;
},
}
}
window.addEventListener('DOMContentLoaded', function (e) { window.addEventListener('DOMContentLoaded', function (e) {
document.querySelectorAll('.notification_toggle_read_status') document.querySelectorAll('.notification_toggle_read_status')
.forEach(function (app) { .forEach(function (el) {
console.log('app', app); console.log('app', el);
const myApp = Object.assign(App, { const App = {
template: '<notification-read-toggle ' +
':notificationId="notificationId" ' +
':isRead="isRead"' +
'@markRead="onMarkRead" @markUnread="onMarkUnread"' +
'></notification-read-toggle>',
components: {
NotificationReadToggle,
},
data() { data() {
return { return {
notificationId: +app.dataset.notificationId, notificationId: +el.dataset.notificationId,
isRead: 1 === +app.dataset.notificationCurrentIsRead, isRead: 1 === +el.dataset.notificationCurrentIsRead,
} }
},
methods: {
onMarkRead() {
this.isRead = false;
},
onMarkUnread() {
this.isRead = true;
},
} }
}) }
createApp(myApp).mount(app); createApp(App).mount(el);
}); });
}) })

View File

@ -23,14 +23,12 @@ export default {
methods: { methods: {
markAsUnread() { markAsUnread() {
makeFetch('POST', `/api/1.0/main/notification/${this.notificationId}/mark/unread`, []).then(response => { makeFetch('POST', `/api/1.0/main/notification/${this.notificationId}/mark/unread`, []).then(response => {
console.log('marked as unread', this.notificationId);
this.$emit('markRead', { notificationId: this.notificationId }); this.$emit('markRead', { notificationId: this.notificationId });
}) })
}, },
markAsRead() { markAsRead() {
makeFetch('POST', `/api/1.0/main/notification/${this.notificationId}/mark/read`, []).then(response => { makeFetch('POST', `/api/1.0/main/notification/${this.notificationId}/mark/read`, []).then(response => {
console.log('marked as read', this.notificationId); this.$emit('markUnread', { notificationId: this.notificationId });
this.$emit('markRead', { notificationId: this.notificationId });
}) })
}, },
}, },