Added null checks
This commit is contained in:
parent
707233a422
commit
d16197340d
@ -27,7 +27,7 @@ export default class AnimeNotifier {
|
|||||||
visibilityObserver: IntersectionObserver
|
visibilityObserver: IntersectionObserver
|
||||||
pushManager: PushManager
|
pushManager: PushManager
|
||||||
serviceWorkerManager: ServiceWorkerManager
|
serviceWorkerManager: ServiceWorkerManager
|
||||||
notificationManager: NotificationManager
|
notificationManager: NotificationManager | undefined
|
||||||
touchController: TouchController
|
touchController: TouchController
|
||||||
audioPlayer: AudioPlayer
|
audioPlayer: AudioPlayer
|
||||||
videoPlayer: VideoPlayer
|
videoPlayer: VideoPlayer
|
||||||
@ -126,8 +126,8 @@ export default class AnimeNotifier {
|
|||||||
|
|
||||||
// Status message
|
// Status message
|
||||||
this.statusMessage = new StatusMessage(
|
this.statusMessage = new StatusMessage(
|
||||||
document.getElementById("status-message"),
|
document.getElementById("status-message") as HTMLElement,
|
||||||
document.getElementById("status-message-text")
|
document.getElementById("status-message-text") as HTMLElement
|
||||||
)
|
)
|
||||||
|
|
||||||
this.app.onError = (error: Error) => {
|
this.app.onError = (error: Error) => {
|
||||||
@ -138,7 +138,12 @@ export default class AnimeNotifier {
|
|||||||
this.pushManager = new PushManager()
|
this.pushManager = new PushManager()
|
||||||
|
|
||||||
// Notification manager
|
// Notification manager
|
||||||
this.notificationManager = new NotificationManager()
|
if(this.user) {
|
||||||
|
this.notificationManager = new NotificationManager(
|
||||||
|
document.getElementById("notification-icon") as HTMLElement,
|
||||||
|
document.getElementById("notification-count") as HTMLElement
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Audio player
|
// Audio player
|
||||||
this.audioPlayer = new AudioPlayer(this)
|
this.audioPlayer = new AudioPlayer(this)
|
||||||
@ -248,7 +253,7 @@ export default class AnimeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notification manager
|
// Notification manager
|
||||||
if(this.user) {
|
if(this.notificationManager) {
|
||||||
this.notificationManager.update()
|
this.notificationManager.update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ export default class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scrollToTop() {
|
scrollToTop() {
|
||||||
let parent : HTMLElement | null = this.content
|
let parent: any = this.content
|
||||||
|
|
||||||
Diff.mutations.queue(() => {
|
Diff.mutations.queue(() => {
|
||||||
while(parent = parent.parentElement) {
|
while(parent = parent.parentElement) {
|
||||||
|
@ -6,7 +6,7 @@ export default class AudioPlayer {
|
|||||||
|
|
||||||
// Web audio
|
// Web audio
|
||||||
audioContext: AudioContext
|
audioContext: AudioContext
|
||||||
audioNode: AudioBufferSourceNode
|
audioNode: AudioBufferSourceNode | null
|
||||||
gainNode: GainNode
|
gainNode: GainNode
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
@ -30,7 +30,7 @@ export default class AudioPlayer {
|
|||||||
|
|
||||||
constructor(arn: AnimeNotifier) {
|
constructor(arn: AnimeNotifier) {
|
||||||
this.arn = arn
|
this.arn = arn
|
||||||
this.audioPlayer = document.getElementById("audio-player")
|
this.audioPlayer = document.getElementById("audio-player") as HTMLElement
|
||||||
this.audioPlayerPlay = document.getElementById("audio-player-play") as HTMLButtonElement
|
this.audioPlayerPlay = document.getElementById("audio-player-play") as HTMLButtonElement
|
||||||
this.audioPlayerPause = document.getElementById("audio-player-pause") as HTMLButtonElement
|
this.audioPlayerPause = document.getElementById("audio-player-pause") as HTMLButtonElement
|
||||||
this.trackLink = document.getElementById("audio-player-track-title") as HTMLLinkElement
|
this.trackLink = document.getElementById("audio-player-track-title") as HTMLLinkElement
|
||||||
|
@ -103,7 +103,7 @@ export function displayAiringDate(element: HTMLElement, now: Date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function displayDate(element: HTMLElement, now: Date) {
|
export function displayDate(element: HTMLElement, now: Date) {
|
||||||
if(element.dataset.date === "") {
|
if(!element.dataset.date) {
|
||||||
element.textContent = ""
|
element.textContent = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ export default class NotificationManager {
|
|||||||
icon: HTMLElement
|
icon: HTMLElement
|
||||||
counter: HTMLElement
|
counter: HTMLElement
|
||||||
|
|
||||||
constructor() {
|
constructor(icon: HTMLElement, counter: HTMLElement) {
|
||||||
this.icon = document.getElementById("notification-icon")
|
this.icon = icon
|
||||||
this.counter = document.getElementById("notification-count")
|
this.counter = counter
|
||||||
}
|
}
|
||||||
|
|
||||||
async update() {
|
async update() {
|
||||||
|
@ -91,6 +91,10 @@ export default class ServerEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notificationCount(e: ServerEvent) {
|
notificationCount(e: ServerEvent) {
|
||||||
|
if(!this.arn.notificationManager) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.arn.notificationManager.setCounter(parseInt(e.data))
|
this.arn.notificationManager.setCounter(parseInt(e.data))
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -77,7 +77,10 @@ export default class ServiceWorkerManager {
|
|||||||
|
|
||||||
switch(message.type) {
|
switch(message.type) {
|
||||||
case "new notification":
|
case "new notification":
|
||||||
this.arn.notificationManager.update()
|
if(this.arn.notificationManager) {
|
||||||
|
this.arn.notificationManager.update()
|
||||||
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
// case "new content":
|
// case "new content":
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
|
// swapElements assumes that both elements have valid parent nodes.
|
||||||
export function swapElements(a: Node, b: Node) {
|
export function swapElements(a: Node, b: Node) {
|
||||||
let parent = b.parentNode
|
let bParent = b.parentNode as Node
|
||||||
let bNext = b.nextSibling
|
let bNext = b.nextSibling
|
||||||
|
|
||||||
// Special case for when a is the next sibling of b
|
// Special case for when a is the next sibling of b
|
||||||
if(bNext === a) {
|
if(bNext === a) {
|
||||||
// Just put a before b
|
// Just put a before b
|
||||||
parent.insertBefore(a, b)
|
bParent.insertBefore(a, b)
|
||||||
} else {
|
} else {
|
||||||
// Insert b right before a
|
// Insert b right before a
|
||||||
a.parentNode.insertBefore(b, a)
|
(a.parentNode as Node).insertBefore(b, a)
|
||||||
|
|
||||||
// Now insert a where b was
|
// Now insert a where b was
|
||||||
if(bNext) {
|
if(bNext) {
|
||||||
// If there was an element after b, then insert a right before that
|
// If there was an element after b, then insert a right before that
|
||||||
parent.insertBefore(a, bNext)
|
bParent.insertBefore(a, bNext)
|
||||||
} else {
|
} else {
|
||||||
// Otherwise just append it as the last child
|
// Otherwise just append it as the last child
|
||||||
parent.appendChild(a)
|
bParent.appendChild(a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user