diff --git a/pages/index.go b/pages/index.go index c390567f..527f05c7 100644 --- a/pages/index.go +++ b/pages/index.go @@ -70,7 +70,7 @@ import ( "github.com/animenotifier/notify.moe/pages/statistics" "github.com/animenotifier/notify.moe/pages/support" "github.com/animenotifier/notify.moe/pages/terms" - "github.com/animenotifier/notify.moe/pages/threads" + "github.com/animenotifier/notify.moe/pages/thread" "github.com/animenotifier/notify.moe/pages/upload" "github.com/animenotifier/notify.moe/pages/user" "github.com/animenotifier/notify.moe/pages/users" @@ -101,7 +101,7 @@ func Configure(app *aero.Application) { // Forum l.Page("/forum", forum.Get) l.Page("/forum/:tag", forum.Get) - l.Page("/thread/:id", threads.Get) + l.Page("/thread/:id", thread.Get) l.Page("/post/:id", posts.Get) l.Page("/new/thread", newthread.Get) diff --git a/pages/threads/threads.go b/pages/thread/thread.go similarity index 97% rename from pages/threads/threads.go rename to pages/thread/thread.go index 435e1056..0774a98a 100644 --- a/pages/threads/threads.go +++ b/pages/thread/thread.go @@ -1,4 +1,4 @@ -package threads +package thread import ( "net/http" diff --git a/pages/thread/thread.pixy b/pages/thread/thread.pixy new file mode 100644 index 00000000..1b91cf1b --- /dev/null +++ b/pages/thread/thread.pixy @@ -0,0 +1,37 @@ +component Thread(thread *arn.Thread, posts []*arn.Post, user *arn.User) + h1.thread-title= thread.Title + + #thread.thread(data-id=thread.ID) + .posts + Postable(thread.ToPostable(), user, thread.Creator().ID) + + each post in posts + Postable(post.ToPostable(), user, thread.Creator().ID) + + //- Reply + if user != nil + if thread.Locked + footer.footer.mountable + p.text-center This topic is locked. + else + NewPostArea(user, "Reply") + + .buttons + if !thread.Locked + button.mountable.action(data-action="forumReply", data-trigger="click") + Icon("mail-reply") + span Reply + + if user.Role == "admin" || user.Role == "editor" + if thread.Locked + button.mountable.action(data-action="unlockThread", data-trigger="click", data-api="/api/thread/" + thread.ID) + Icon("unlock") + span Unlock + else + button.mountable.action(data-action="lockThread", data-trigger="click", data-api="/api/thread/" + thread.ID) + Icon("lock") + span Lock + + button.mountable.action(data-action="deleteObject", data-trigger="click", data-return-path="/forum", data-confirm-type="thread", data-api="/api/thread/" + thread.ID) + Icon("trash") + span Delete \ No newline at end of file diff --git a/pages/threads/threads.scarlet b/pages/thread/thread.scarlet similarity index 100% rename from pages/threads/threads.scarlet rename to pages/thread/thread.scarlet diff --git a/pages/threads/threads.pixy b/pages/threads/threads.pixy deleted file mode 100644 index 496d3854..00000000 --- a/pages/threads/threads.pixy +++ /dev/null @@ -1,23 +0,0 @@ -component Thread(thread *arn.Thread, posts []*arn.Post, user *arn.User) - h1.thread-title= thread.Title - - #thread.thread(data-id=thread.ID) - .posts - Postable(thread.ToPostable(), user, thread.Creator().ID) - - each post in posts - Postable(post.ToPostable(), user, thread.Creator().ID) - - // Reply - if user != nil - NewPostArea(user, "Reply") - - .buttons - button.action(data-action="forumReply", data-trigger="click") - Icon("mail-reply") - span Reply - - if user.Role == "admin" || user.Role == "editor" - button.action(data-action="deleteObject", data-trigger="click", data-return-path="/forum", data-confirm-type="thread", data-api="/api/thread/" + thread.ID) - Icon("trash") - span Delete \ No newline at end of file diff --git a/scripts/Actions/AnimeList.ts b/scripts/Actions/AnimeList.ts index 8c7baaa1..40751e75 100644 --- a/scripts/Actions/AnimeList.ts +++ b/scripts/Actions/AnimeList.ts @@ -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)) } \ No newline at end of file diff --git a/scripts/Actions/FollowUser.ts b/scripts/Actions/FollowUser.ts index 00861602..d6325654 100644 --- a/scripts/Actions/FollowUser.ts +++ b/scripts/Actions/FollowUser.ts @@ -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)) diff --git a/scripts/Actions/Forum.ts b/scripts/Actions/Forum.ts index a63e5033..959aafd5 100644 --- a/scripts/Actions/Forum.ts +++ b/scripts/Actions/Forum.ts @@ -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)) } \ No newline at end of file diff --git a/scripts/Actions/Object.ts b/scripts/Actions/Object.ts index 2fd83df1..6717d5eb 100644 --- a/scripts/Actions/Object.ts +++ b/scripts/Actions/Object.ts @@ -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)) } \ No newline at end of file diff --git a/scripts/Actions/Publish.ts b/scripts/Actions/Publish.ts index a1df337b..8c087c49 100644 --- a/scripts/Actions/Publish.ts +++ b/scripts/Actions/Publish.ts @@ -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)) } \ No newline at end of file diff --git a/scripts/Actions/Serialization.ts b/scripts/Actions/Serialization.ts index 4f100348..54674f44 100644 --- a/scripts/Actions/Serialization.ts +++ b/scripts/Actions/Serialization.ts @@ -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)) }