Added notification count badge
This commit is contained in:
@ -4,6 +4,7 @@ import { MutationQueue } from "./MutationQueue"
|
||||
import { StatusMessage } from "./StatusMessage"
|
||||
import { PushManager } from "./PushManager"
|
||||
import { TouchController } from "./TouchController"
|
||||
import { NotificationManager } from "./NotificationManager"
|
||||
import { Analytics } from "./Analytics"
|
||||
import { SideBar } from "./SideBar"
|
||||
import { InfiniteScroller } from "./InfiniteScroller"
|
||||
@ -24,6 +25,7 @@ export class AnimeNotifier {
|
||||
visibilityObserver: IntersectionObserver
|
||||
pushManager: PushManager
|
||||
serviceWorkerManager: ServiceWorkerManager
|
||||
notificationManager: NotificationManager
|
||||
touchController: TouchController
|
||||
sideBar: SideBar
|
||||
infiniteScroller: InfiniteScroller
|
||||
@ -131,6 +133,9 @@ export class AnimeNotifier {
|
||||
// Push manager
|
||||
this.pushManager = new PushManager()
|
||||
|
||||
// Notification manager
|
||||
this.notificationManager = new NotificationManager()
|
||||
|
||||
// Analytics
|
||||
this.analytics = new Analytics()
|
||||
|
||||
@ -186,6 +191,11 @@ export class AnimeNotifier {
|
||||
this.statusMessage.showError("You are viewing an offline version of the site now.")
|
||||
}
|
||||
|
||||
// Notification manager
|
||||
if(this.user) {
|
||||
this.notificationManager.update()
|
||||
}
|
||||
|
||||
// Download popular anime titles for the search
|
||||
// let response = await fetch("/api/popular/anime/titles/500")
|
||||
// let titles = await response.json()
|
||||
|
31
scripts/NotificationManager.ts
Normal file
31
scripts/NotificationManager.ts
Normal file
@ -0,0 +1,31 @@
|
||||
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)
|
||||
this.unseen = 2
|
||||
this.render()
|
||||
}
|
||||
|
||||
render() {
|
||||
console.log("notification count", this.unseen)
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ export class ServiceWorkerManager {
|
||||
message.url = window.location.href
|
||||
}
|
||||
|
||||
console.log("checking for updates:", message.url)
|
||||
// console.log("checking for updates:", message.url)
|
||||
|
||||
this.postMessage(message)
|
||||
}
|
||||
|
Reference in New Issue
Block a user