diff --git a/src/twit2blogpkg/server.nim b/src/twit2blogpkg/server.nim index 751f8de..a8bfed4 100644 --- a/src/twit2blogpkg/server.nim +++ b/src/twit2blogpkg/server.nim @@ -1,4 +1,4 @@ -import strutils, options, sugar, sequtils, asyncdispatch, threadpool, db_sqlite +import strutils, options, sugar, sequtils, asyncdispatch, threadpool, db_sqlite, json import twitter import templates import jester @@ -53,6 +53,25 @@ proc insertThread(thread : TwitterThread) = thread.tweets) router twitblog: + get "/": + # Lists all authors + let authors = allAuthors.toSeq + let title = "Authors" + resp authors.mainPage + + post "/thread": + let params = request.formData + if not ("tweetID" in params and "author" in params): + resp "nope" + + let tweetID = params["tweetID"].body + let author = params["author"].body + + let thread = threadExists(tweetID, author) + + chan.send(ThreadRequest(tweetID: tweetID, author: author)) + resp checkBack() + get "/thread/@author/status/@tweetID": let tweetID = @"tweetID" let author = @"author" @@ -61,19 +80,13 @@ router twitblog: if thread.isSome: # Lists all the tweets in a thread let tweets = thread.get.tweets.split("\n") - resp renderThread(author, thread.get.tweets.split("\n")) + resp tweetThread(author, thread.get.tweets.split("\n")) else: # Send it off to the rendering thread for processing # Let them know to check back later chan.send(ThreadRequest(tweetID: tweetID, author: author)) resp checkBack() - get "/": - # Lists all authors - let authors = allAuthors.toSeq - let title = "Authors" - resp authors.listAuthors - get "/author/@author/threads": # Lists all threads by an author let author = @"author" diff --git a/src/twit2blogpkg/templates.nim b/src/twit2blogpkg/templates.nim index 959dfa9..ce49f2c 100644 --- a/src/twit2blogpkg/templates.nim +++ b/src/twit2blogpkg/templates.nim @@ -1,11 +1,11 @@ import strformat import karax / [karaxdsl, vdom] -proc renderThread*(author : string, - tweets : seq[string]): string = +proc tweetThread*(author : string, + tweets : seq[string]): string = let title = fmt"Thread by {author}" - let vnode = buildHtml(tdiv(class = "mt-3")): + let vnode = buildHtml(tdiv): h4: text title ul: li: a(href="/"): text "Main Page" @@ -16,26 +16,40 @@ proc renderThread*(author : string, result = $vnode proc checkBack*() : string = - let vnode = buildHtml(tdiv(class = "mt-3")): + let vnode = buildHtml(tdiv): h4: text "Check back later please" result = $vnode -proc listAuthors*(authors : seq[string]) : string = - let title = "Authors" - let vnode = buildHtml(tdiv(class = "mt-3")): - h4: text title - ul: - for author in authors: - li: a(href = fmt"/author/{author}/threads"): text author - result = $vnode - proc listThreads*(author : string, threads : seq[string]) : string = let title = fmt"Threads for {author}" - let vnode = buildHtml(tdiv(class = "mt-3")): + let vnode = buildHtml(tdiv): a(href="/"): text "Main Page" h4: text title ul: for thread in threads: li: a(href = fmt"/thread/{author}/status/{thread}"): text thread result = $vnode + + +## Main page +proc listAuthors*(authors : seq[string]) : VNode = + let title = "Authors" + let vnode = buildHtml(tdiv): + h4: text title + ul: + for author in authors: + li: a(href = fmt"/author/{author}/threads"): text author + result = vnode + +proc submitThread() : VNode = + let vnode = buildHtml(tdiv): + form(action = "/thread", `method`="POST", class="submit-thread"): + text "blah" + result = vnode + +proc mainPage*(authors : seq[string]) : string = + let vnode = buildHtml(tdiv): + listAuthors(authors) + submitThread() + result = $vnode