Editors can now lock threads

This commit is contained in:
2018-04-25 18:59:23 +02:00
parent 7d70f3b0b5
commit 3ebd4b0856
11 changed files with 75 additions and 36 deletions

View File

@ -8,7 +8,7 @@ export async function addAnimeToCollection(arn: AnimeNotifier, button: HTMLButto
let apiEndpoint = arn.findAPIEndpoint(button)
try {
await arn.post(apiEndpoint + "/add/" + animeId, "")
await arn.post(apiEndpoint + "/add/" + animeId)
arn.reloadContent()
// Show status message
@ -31,7 +31,7 @@ export function removeAnimeFromCollection(arn: AnimeNotifier, button: HTMLElemen
let {animeId, nick} = button.dataset
let apiEndpoint = arn.findAPIEndpoint(button)
arn.post(apiEndpoint + "/remove/" + animeId, "")
arn.post(apiEndpoint + "/remove/" + animeId)
.then(() => arn.app.load(`/+${nick}/animelist/` + (document.getElementById("Status") as HTMLSelectElement).value))
.catch(err => arn.statusMessage.showError(err))
}

View File

@ -2,7 +2,7 @@ import AnimeNotifier from "../AnimeNotifier"
// Follow user
export function followUser(arn: AnimeNotifier, elem: HTMLElement) {
return arn.post(elem.dataset.api, "")
return arn.post(elem.dataset.api)
.then(() => arn.reloadContent())
.then(() => arn.statusMessage.showInfo("You are now following " + document.getElementById("nick").innerText + "."))
.catch(err => arn.statusMessage.showError(err))
@ -10,7 +10,7 @@ export function followUser(arn: AnimeNotifier, elem: HTMLElement) {
// Unfollow user
export function unfollowUser(arn: AnimeNotifier, elem: HTMLElement) {
return arn.post(elem.dataset.api, "")
return arn.post(elem.dataset.api)
.then(() => arn.reloadContent())
.then(() => arn.statusMessage.showInfo("You stopped following " + document.getElementById("nick").innerText + "."))
.catch(err => arn.statusMessage.showError(err))

View File

@ -51,7 +51,7 @@ export function deletePost(arn: AnimeNotifier, element: HTMLElement) {
let endpoint = arn.findAPIEndpoint(element)
arn.post(endpoint + "/delete", "")
arn.post(endpoint + "/delete")
.then(() => arn.reloadContent())
.catch(err => arn.statusMessage.showError(err))
}
@ -93,4 +93,29 @@ export function createThread(arn: AnimeNotifier) {
arn.post("/api/new/thread", thread)
.then(() => arn.app.load("/forum/" + thread.tags[0]))
.catch(err => arn.statusMessage.showError(err))
}
// Lock thread
export function lockThread(arn: AnimeNotifier, element: HTMLButtonElement) {
setThreadLock(arn, element, true)
}
// Unlock thread
export function unlockThread(arn: AnimeNotifier, element: HTMLButtonElement) {
setThreadLock(arn, element, false)
}
// Set thread locked state
function setThreadLock(arn: AnimeNotifier, element: HTMLButtonElement, state: boolean) {
let verb = state ? "lock" : "unlock"
if(!confirm(`Are you sure you want to ${verb} this Thread?`)) {
return
}
let endpoint = arn.findAPIEndpoint(element)
arn.post(`${endpoint}/${verb}`)
.then(() => arn.reloadContent())
.catch(err => arn.statusMessage.showError(err))
}

View File

@ -4,7 +4,7 @@ import AnimeNotifier from "../AnimeNotifier"
export function newObject(arn: AnimeNotifier, button: HTMLButtonElement) {
let dataType = button.dataset.type
arn.post(`/api/new/${dataType}`, "")
arn.post(`/api/new/${dataType}`)
.then(response => response.json())
.then(obj => arn.app.load(`/${dataType}/${obj.id}/edit`))
.catch(err => arn.statusMessage.showError(err))
@ -28,7 +28,7 @@ export function deleteObject(arn: AnimeNotifier, button: HTMLButtonElement) {
let endpoint = arn.findAPIEndpoint(button)
arn.post(endpoint + "/delete", "")
arn.post(endpoint + "/delete")
.then(() => arn.app.load(returnPath))
.catch(err => arn.statusMessage.showError(err))
}

View File

@ -4,7 +4,7 @@ import AnimeNotifier from "../AnimeNotifier"
export function publish(arn: AnimeNotifier, button: HTMLButtonElement) {
let endpoint = arn.findAPIEndpoint(button)
arn.post(endpoint + "/publish", "")
arn.post(endpoint + "/publish")
.then(() => arn.app.load(arn.app.currentPath.replace("/edit", "")))
.catch(err => arn.statusMessage.showError(err))
}
@ -13,7 +13,7 @@ export function publish(arn: AnimeNotifier, button: HTMLButtonElement) {
export function unpublish(arn: AnimeNotifier, button: HTMLButtonElement) {
let endpoint = arn.findAPIEndpoint(button)
arn.post(endpoint + "/unpublish", "")
arn.post(endpoint + "/unpublish")
.then(() => arn.reloadContent())
.catch(err => arn.statusMessage.showError(err))
}

View File

@ -122,7 +122,7 @@ export function arrayRemove(arn: AnimeNotifier, element: HTMLElement) {
let index = element.dataset.index
let apiEndpoint = arn.findAPIEndpoint(element)
arn.post(apiEndpoint + "/field/" + field + "/remove/" + index, "")
arn.post(apiEndpoint + "/field/" + field + "/remove/" + index)
.then(() => arn.reloadContent())
.catch(err => arn.statusMessage.showError(err))
}