33 lines
749 B
TypeScript
Raw Normal View History

2018-02-28 15:26:49 +00:00
export class NotificationManager {
unseen: number
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() {
let notificationIcon = document.getElementById("notification-icon")
let notificationCount = document.getElementById("notification-count")
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")
}
}
}