Added user follows
This commit is contained in:
@ -3,6 +3,22 @@ import { AnimeNotifier } from "./AnimeNotifier"
|
||||
import { Diff } from "./Diff"
|
||||
import { findAll } from "./Utils"
|
||||
|
||||
// Follow user
|
||||
export function followUser(arn: AnimeNotifier, elem: HTMLElement) {
|
||||
return arn.post(elem.dataset.api, elem.dataset.viewUserId)
|
||||
.then(() => arn.reloadContent())
|
||||
.then(() => arn.statusMessage.showInfo("You are now following " + arn.app.find("nick").innerText + "."))
|
||||
.catch(err => arn.statusMessage.showError(err))
|
||||
}
|
||||
|
||||
// Unfollow user
|
||||
export function unfollowUser(arn: AnimeNotifier, elem: HTMLElement) {
|
||||
return arn.post(elem.dataset.api, elem.dataset.viewUserId)
|
||||
.then(() => arn.reloadContent())
|
||||
.then(() => arn.statusMessage.showInfo("You stopped following " + arn.app.find("nick").innerText + "."))
|
||||
.catch(err => arn.statusMessage.showError(err))
|
||||
}
|
||||
|
||||
// Toggle sidebar
|
||||
export function toggleSidebar(arn: AnimeNotifier) {
|
||||
arn.app.find("sidebar").classList.toggle("sidebar-visible")
|
||||
|
@ -580,18 +580,30 @@ export class AnimeNotifier {
|
||||
})
|
||||
}
|
||||
|
||||
post(url, obj) {
|
||||
post(url, body) {
|
||||
if(typeof body !== "string") {
|
||||
body = JSON.stringify(body)
|
||||
}
|
||||
|
||||
this.loading(true)
|
||||
|
||||
return fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(obj),
|
||||
body,
|
||||
credentials: "same-origin"
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(body => {
|
||||
this.loading(false)
|
||||
|
||||
if(body !== "ok") {
|
||||
throw body
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
this.loading(false)
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
scrollTo(target: HTMLElement) {
|
||||
|
@ -9,7 +9,7 @@ export class StatusMessage {
|
||||
this.text = text
|
||||
}
|
||||
|
||||
show(message: string, duration?: number) {
|
||||
show(message: string, duration: number) {
|
||||
let messageId = String(Date.now())
|
||||
|
||||
this.text.innerText = message
|
||||
@ -27,10 +27,15 @@ export class StatusMessage {
|
||||
}
|
||||
|
||||
showError(message: string, duration?: number) {
|
||||
this.show(message, duration)
|
||||
this.show(message, duration || 4000)
|
||||
this.container.classList.add("error-message")
|
||||
}
|
||||
|
||||
showInfo(message: string, duration?: number) {
|
||||
this.show(message, duration || 2000)
|
||||
this.container.classList.add("info-message")
|
||||
}
|
||||
|
||||
close() {
|
||||
this.container.classList.add("fade-out")
|
||||
}
|
||||
|
Reference in New Issue
Block a user