Can now reply to threads

This commit is contained in:
Eduard Urbach 2017-06-26 23:04:15 +02:00
parent fad6f7657a
commit db28721126
3 changed files with 26 additions and 6 deletions

View File

@ -1,7 +1,7 @@
component Thread(thread *arn.Thread, posts []*arn.Post, user *arn.User) component Thread(thread *arn.Thread, posts []*arn.Post, user *arn.User)
h2.thread-title= thread.Title h2.thread-title= thread.Title
.thread #thread.thread(data-id=thread.ID)
.posts .posts
Postable(thread.ToPostable(), thread.Author().ID) Postable(thread.ToPostable(), thread.Author().ID)

View File

@ -153,7 +153,7 @@ export class AnimeNotifier {
} }
} }
diffURL(url: string) { load(url: string) {
let request = fetch("/_" + url, { let request = fetch("/_" + url, {
credentials: "same-origin" credentials: "same-origin"
}) })
@ -165,7 +165,7 @@ export class AnimeNotifier {
this.unmountMountables() this.unmountMountables()
this.loading(true) this.loading(true)
delay(300).then(() => { return delay(300).then(() => {
request request
.then(html => this.app.setContent(html, true)) .then(html => this.app.setContent(html, true))
.then(() => this.app.markActiveLinks()) .then(() => this.app.markActiveLinks())

View File

@ -60,15 +60,35 @@ export function save(arn: AnimeNotifier, input: HTMLInputElement | HTMLTextAreaE
// Diff // Diff
export function diff(arn: AnimeNotifier, element: HTMLElement) { export function diff(arn: AnimeNotifier, element: HTMLElement) {
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href") let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
arn.diffURL(url) arn.load(url)
} }
// Forum reply // Forum reply
export function forumReply(arn: AnimeNotifier) { export function forumReply(arn: AnimeNotifier) {
let textarea = arn.app.find("new-reply") as HTMLTextAreaElement let textarea = arn.app.find("new-reply") as HTMLTextAreaElement
let thread = arn.app.find("thread")
console.log(textarea.value) let post = {
arn.diffURL(arn.app.currentPath) text: textarea.value,
threadId: thread.dataset.id,
tags: []
}
fetch("/api/post/new", {
method: "POST",
body: JSON.stringify(post),
credentials: "same-origin"
})
.then(response => response.text())
.then(body => {
if(body !== "ok") {
throw body
}
textarea.value = ""
})
.then(() => arn.reloadContent())
.catch(console.error)
} }
// Search // Search