Added null checks and async functions

This commit is contained in:
2019-04-22 15:02:51 +09:00
parent b1442858fe
commit 06daacbbf6
9 changed files with 158 additions and 75 deletions

View File

@ -1,19 +1,25 @@
import AnimeNotifier from "../AnimeNotifier"
// Publish
export function publish(arn: AnimeNotifier, button: HTMLButtonElement) {
export async function publish(arn: AnimeNotifier, button: HTMLButtonElement) {
let endpoint = arn.findAPIEndpoint(button)
arn.post(endpoint + "/publish")
.then(() => arn.app.load(arn.app.currentPath.replace("/edit", "")))
.catch(err => arn.statusMessage.showError(err))
try {
await arn.post(endpoint + "/publish")
await arn.app.load(arn.app.currentPath.replace("/edit", ""))
} catch(err) {
arn.statusMessage.showError(err)
}
}
// Unpublish
export function unpublish(arn: AnimeNotifier, button: HTMLButtonElement) {
export async function unpublish(arn: AnimeNotifier, button: HTMLButtonElement) {
let endpoint = arn.findAPIEndpoint(button)
arn.post(endpoint + "/unpublish")
.then(() => arn.reloadContent())
.catch(err => arn.statusMessage.showError(err))
try {
await arn.post(endpoint + "/unpublish")
await arn.reloadContent()
} catch(err) {
arn.statusMessage.showError(err)
}
}