2018-04-02 05:34:16 +00:00
|
|
|
import AnimeNotifier from "../AnimeNotifier"
|
2017-10-17 09:27:15 +00:00
|
|
|
|
|
|
|
// Add anime to collection
|
2017-11-28 22:40:53 +00:00
|
|
|
export async function addAnimeToCollection(arn: AnimeNotifier, button: HTMLButtonElement) {
|
|
|
|
button.disabled = true
|
|
|
|
|
2017-10-17 09:27:15 +00:00
|
|
|
let {animeId} = button.dataset
|
|
|
|
let apiEndpoint = arn.findAPIEndpoint(button)
|
|
|
|
|
2017-11-28 22:40:53 +00:00
|
|
|
try {
|
2018-04-25 16:59:23 +00:00
|
|
|
await arn.post(apiEndpoint + "/add/" + animeId)
|
2017-11-28 22:40:53 +00:00
|
|
|
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)
|
|
|
|
}
|
2017-10-17 09:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove anime from collection
|
|
|
|
export function removeAnimeFromCollection(arn: AnimeNotifier, button: HTMLElement) {
|
2018-03-14 21:52:56 +00:00
|
|
|
if(!confirm("Are you sure you want to remove it from your collection?")) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-10-17 09:27:15 +00:00
|
|
|
button.innerText = "Removing..."
|
|
|
|
|
|
|
|
let {animeId, nick} = button.dataset
|
|
|
|
let apiEndpoint = arn.findAPIEndpoint(button)
|
|
|
|
|
2018-04-25 16:59:23 +00:00
|
|
|
arn.post(apiEndpoint + "/remove/" + animeId)
|
2018-04-02 05:44:11 +00:00
|
|
|
.then(() => arn.app.load(`/+${nick}/animelist/` + (document.getElementById("Status") as HTMLSelectElement).value))
|
2017-10-17 09:27:15 +00:00
|
|
|
.catch(err => arn.statusMessage.showError(err))
|
|
|
|
}
|