This commit is contained in:
2018-03-29 12:14:46 +02:00
parent 91dce1895f
commit ee1460aef7
4 changed files with 46 additions and 34 deletions

View File

@ -1,5 +1,14 @@
import { Diff } from "./Diff"
export class NotificationManager {
unseen: number
icon: HTMLElement
counter: HTMLElement
constructor() {
this.icon = document.getElementById("notification-icon")
this.counter = document.getElementById("notification-count")
}
async update() {
let response = await fetch("/api/count/notifications/unseen", {
@ -17,17 +26,16 @@ export class NotificationManager {
}
render() {
let notificationIcon = document.getElementById("notification-icon")
let notificationCount = document.getElementById("notification-count")
Diff.mutations.queue(() => {
this.counter.innerText = this.unseen.toString()
notificationCount.innerText = this.unseen.toString()
if(this.unseen === 0) {
notificationCount.classList.add("hidden")
notificationIcon.classList.remove("hidden")
} else {
notificationIcon.classList.add("hidden")
notificationCount.classList.remove("hidden")
}
if(this.unseen === 0) {
this.counter.classList.add("hidden")
this.icon.classList.remove("hidden")
} else {
this.icon.classList.add("hidden")
this.counter.classList.remove("hidden")
}
})
}
}