Implemented adding and removing anime
This commit is contained in:
48
scripts/actions.ts
Normal file
48
scripts/actions.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { Application } from "./Application"
|
||||
import { AnimeNotifier } from "./AnimeNotifier"
|
||||
|
||||
// Add anime to collection
|
||||
export function addAnimeToCollection(arn: AnimeNotifier, button: HTMLElement) {
|
||||
button.innerText = "Adding..."
|
||||
arn.loading(true)
|
||||
|
||||
let {animeId, userId, userNick} = button.dataset
|
||||
|
||||
fetch("/api/animelist/" + userId + "/add", {
|
||||
method: "POST",
|
||||
body: animeId
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(body => {
|
||||
if(body !== "ok") {
|
||||
throw body
|
||||
}
|
||||
|
||||
return arn.app.load("/+" + userNick + "/animelist/" + animeId, true)
|
||||
})
|
||||
.catch(console.error)
|
||||
.then(() => arn.loading(false))
|
||||
}
|
||||
|
||||
// Remove anime from collection
|
||||
export function removeAnimeFromCollection(arn: AnimeNotifier, button: HTMLElement) {
|
||||
button.innerText = "Removing..."
|
||||
arn.loading(true)
|
||||
|
||||
let {animeId, userId, userNick} = button.dataset
|
||||
|
||||
fetch("/api/animelist/" + userId + "/remove", {
|
||||
method: "POST",
|
||||
body: animeId
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(body => {
|
||||
if(body !== "ok") {
|
||||
throw body
|
||||
}
|
||||
|
||||
return arn.app.load("/+" + userNick + "/animelist", true)
|
||||
})
|
||||
.catch(console.error)
|
||||
.then(() => arn.loading(false))
|
||||
}
|
Reference in New Issue
Block a user