Commit 525f5f3c authored by Matthieu Fesselier's avatar Matthieu Fesselier

update: render badge on read

parent cf86465c
Pipeline #4127 passed with stage
in 27 seconds
...@@ -4,6 +4,11 @@ const base_url = import.meta.url.replace(/\/[^\/]*$/, ''); ...@@ -4,6 +4,11 @@ const base_url = import.meta.url.replace(/\/[^\/]*$/, '');
Helpers.importCSS(`${base_url}/css/badge.css`) Helpers.importCSS(`${base_url}/css/badge.css`)
class SIBBadge extends SIBTemplateElement { class SIBBadge extends SIBTemplateElement {
constructor() {
super()
window.addEventListener('notificationsUpdated', () => this.render());
}
static get propsDefinition() { static get propsDefinition() {
return { return {
dataSrc: 'data-src', dataSrc: 'data-src',
......
...@@ -22,10 +22,15 @@ class SIBNotifications extends SIBTemplateElement { ...@@ -22,10 +22,15 @@ class SIBNotifications extends SIBTemplateElement {
// On click events, ... // On click events, ...
this.addEventListener("click", event => { this.addEventListener("click", event => {
// unread button -> mark as read // unread button -> dispatch read event
let unreadButton = event.target.closest('button[data-unread=unread]') let unreadButton = event.target.closest('button[data-unread=unread]')
if (unreadButton) { if (unreadButton) {
this._onClickUnreadButton(unreadButton) window.dispatchEvent(new CustomEvent('read', {
detail: {
resource: unreadButton.closest('sib-display').resource // get resource from sib display
}
}));
unreadButton.disabled = true
return return
} }
...@@ -74,11 +79,14 @@ class SIBNotifications extends SIBTemplateElement { ...@@ -74,11 +79,14 @@ class SIBNotifications extends SIBTemplateElement {
_onReadResource(resourceId) { _onReadResource(resourceId) {
const edits = this._getNotificationsList() const edits = this._getNotificationsList()
.filter((notification) => notification.unread && .filter((notification) => notification.unread &&
(notification.object['@id'] === resourceId || notification['@id'] === resourceId)) (notification.object['@id'] === resourceId || notification['@id'] === resourceId)) // compare id with objects id or notifications id
.map((notification) => store.patch(notification['@id'], { unread: false })) .map((notification) => store.patch(notification['@id'], { unread: false }))
Promise.all(edits) Promise.all(edits)
.then(() => this.render()) .then(() => {
this.render();
window.dispatchEvent(new CustomEvent('notificationsUpdated'));
})
.catch((error) => this._printError(error)); .catch((error) => this._printError(error));
} }
...@@ -94,10 +102,6 @@ class SIBNotifications extends SIBTemplateElement { ...@@ -94,10 +102,6 @@ class SIBNotifications extends SIBTemplateElement {
this.querySelector('details').removeAttribute("open") this.querySelector('details').removeAttribute("open")
}) })
} }
_onClickUnreadButton(target) {
this._onReadResource(target.closest('sib-display').resource['@id'])
target.disabled = true
}
_updateUnread() { _updateUnread() {
let unread = Number(document.querySelector('#badge-unread').innerText) let unread = Number(document.querySelector('#badge-unread').innerText)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment