From db28721126347c330bef1c3f402fc3ee776357dc Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 26 Jun 2017 23:04:15 +0200 Subject: [PATCH] Can now reply to threads --- pages/threads/threads.pixy | 2 +- scripts/AnimeNotifier.ts | 4 ++-- scripts/actions.ts | 26 +++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/pages/threads/threads.pixy b/pages/threads/threads.pixy index d2dc6514..0ebee69b 100644 --- a/pages/threads/threads.pixy +++ b/pages/threads/threads.pixy @@ -1,7 +1,7 @@ component Thread(thread *arn.Thread, posts []*arn.Post, user *arn.User) h2.thread-title= thread.Title - .thread + #thread.thread(data-id=thread.ID) .posts Postable(thread.ToPostable(), thread.Author().ID) diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index d0fc6907..fdc2f926 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -153,7 +153,7 @@ export class AnimeNotifier { } } - diffURL(url: string) { + load(url: string) { let request = fetch("/_" + url, { credentials: "same-origin" }) @@ -165,7 +165,7 @@ export class AnimeNotifier { this.unmountMountables() this.loading(true) - delay(300).then(() => { + return delay(300).then(() => { request .then(html => this.app.setContent(html, true)) .then(() => this.app.markActiveLinks()) diff --git a/scripts/actions.ts b/scripts/actions.ts index 5fc88c11..3d9bdd1b 100644 --- a/scripts/actions.ts +++ b/scripts/actions.ts @@ -60,15 +60,35 @@ export function save(arn: AnimeNotifier, input: HTMLInputElement | HTMLTextAreaE // Diff export function diff(arn: AnimeNotifier, element: HTMLElement) { let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href") - arn.diffURL(url) + arn.load(url) } // Forum reply export function forumReply(arn: AnimeNotifier) { let textarea = arn.app.find("new-reply") as HTMLTextAreaElement + let thread = arn.app.find("thread") - console.log(textarea.value) - arn.diffURL(arn.app.currentPath) + let post = { + 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