Added final null checks

This commit is contained in:
2019-04-22 15:59:08 +09:00
parent 70a62f06e5
commit 480ba3a370
8 changed files with 145 additions and 93 deletions

View File

@ -3,21 +3,28 @@ import Diff from "scripts/Diff"
// Follow user
export async function followUser(arn: AnimeNotifier, element: HTMLElement) {
try {
await arn.post(element.dataset.api)
await arn.reloadContent()
arn.statusMessage.showInfo("You are now following " + document.getElementById("nick").textContent + ".")
} catch(err) {
arn.statusMessage.showError(err)
}
return updateFollow(arn, element, "You are now following")
}
// Unfollow user
export async function unfollowUser(arn: AnimeNotifier, element: HTMLElement) {
return updateFollow(arn, element, "You stopped following")
}
// Update follow
async function updateFollow(arn: AnimeNotifier, element: HTMLElement, message: string) {
let api = element.dataset.api
let nick = document.getElementById("nick")
if(!api || !nick || !nick.textContent) {
console.error("Missing data-api or invalid nick:", element)
return
}
try {
await arn.post(element.dataset.api)
await arn.post(api)
await arn.reloadContent()
arn.statusMessage.showInfo("You stopped following " + document.getElementById("nick").textContent + ".")
arn.statusMessage.showInfo(`${message} ${nick.textContent}.`)
} catch(err) {
arn.statusMessage.showError(err)
}