41 lines
836 B
TypeScript
Raw Normal View History

2018-03-29 10:14:46 +00:00
import { Diff } from "./Diff"
2018-02-28 15:26:49 +00:00
export class NotificationManager {
unseen: number
2018-03-29 10:14:46 +00:00
icon: HTMLElement
counter: HTMLElement
constructor() {
this.icon = document.getElementById("notification-icon")
this.counter = document.getElementById("notification-count")
}
2018-02-28 15:26:49 +00:00
async update() {
let response = await fetch("/api/count/notifications/unseen", {
credentials: "same-origin"
})
let body = await response.text()
this.unseen = parseInt(body)
2018-02-28 23:06:03 +00:00
if(this.unseen > 99) {
this.unseen = 99
}
2018-02-28 15:26:49 +00:00
this.render()
}
render() {
2018-03-29 10:14:46 +00:00
Diff.mutations.queue(() => {
this.counter.innerText = this.unseen.toString()
2018-02-28 15:26:49 +00:00
2018-03-29 10:14:46 +00:00
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")
}
})
2018-02-28 15:26:49 +00:00
}
}