Added button to add to collection on explore pages (closes #77)

This commit is contained in:
2017-11-28 23:40:53 +01:00
parent 47a6b1b60c
commit 84ffb2618f
4 changed files with 33 additions and 26 deletions

View File

@ -1,15 +1,23 @@
import { AnimeNotifier } from "../AnimeNotifier"
// Add anime to collection
export function addAnimeToCollection(arn: AnimeNotifier, button: HTMLElement) {
button.innerText = "Adding..."
export async function addAnimeToCollection(arn: AnimeNotifier, button: HTMLButtonElement) {
button.disabled = true
let {animeId} = button.dataset
let apiEndpoint = arn.findAPIEndpoint(button)
arn.post(apiEndpoint + "/add/" + animeId, "")
.then(() => arn.reloadContent())
.catch(err => arn.statusMessage.showError(err))
try {
await arn.post(apiEndpoint + "/add/" + animeId, "")
arn.reloadContent()
// Show status message
let response = await fetch("/api/anime/" + animeId)
let anime = await response.json()
arn.statusMessage.showInfo(`Added ${anime.title.canonical} to your collection.`)
} catch(err) {
arn.statusMessage.showError(err)
}
}
// Remove anime from collection