From: Lanius Trolling Date: Mon, 13 Feb 2023 20:03:43 +0000 (-0500) Subject: Fix flaws in first commit X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=bc54132a7d3454827f8b0965d47e47982b49aa71;p=factbooks Fix flaws in first commit --- diff --git a/src/main/kotlin/info/mechyrdia/Factbooks.kt b/src/main/kotlin/info/mechyrdia/Factbooks.kt index 4faddf4..de4ff2e 100644 --- a/src/main/kotlin/info/mechyrdia/Factbooks.kt +++ b/src/main/kotlin/info/mechyrdia/Factbooks.kt @@ -156,6 +156,10 @@ fun Application.factbooks() { call.respondHtml(HttpStatusCode.OK, call.commentHelpPage()) } + get("/comment/recent") { + call.respondHtml(HttpStatusCode.OK, call.recentCommentsPage()) + } + post("/comment/new/{path...}") { call.newCommentRoute() } diff --git a/src/main/kotlin/info/mechyrdia/data/view_comments.kt b/src/main/kotlin/info/mechyrdia/data/view_comments.kt index 78c7044..320eb0f 100644 --- a/src/main/kotlin/info/mechyrdia/data/view_comments.kt +++ b/src/main/kotlin/info/mechyrdia/data/view_comments.kt @@ -131,7 +131,7 @@ fun FlowContent.commentBox(comment: CommentRenderData, loggedInAs: Id Unit { + val currNation = currentNation() + + val limit = request.queryParameters["limit"]?.toIntOrNull() ?: redirect("/comment/recent?limit=10") + + val validLimits = listOf(10, 20, 50, 80, 100) + + if (limit !in validLimits) + redirect( + "/comment/recent?" + listOf( + "limit" to "10", + "error" to "Invalid limit $limit, must be one of ${validLimits.joinToString()}" + ).formUrlEncode() + ) + + val comments = CommentRenderData(Comment.Table.sorted(descending(Comment::submittedAt)).take(limit).toList()) + + return page("Recent Comments", standardNavBar()) { + section { + h1 { +"Recent Comments" } + + p { + +"Number of comments to view: " + for ((i, validLimit) in validLimits.withIndex()) { + if (i != 0) + +Entities.nbsp + + if (limit == validLimit) + +"$validLimit" + else + a(href="/comment/recent?limit=$validLimit") { + +"$validLimit" + } + } + } + + for (comment in comments) + commentBox(comment, currNation?.id, viewingUserPage = true) + } + } +} + suspend fun ApplicationCall.newCommentRoute(): Nothing { val pagePathParts = parameters.getAll("path")!! val pagePath = pagePathParts.joinToString("/") @@ -111,7 +157,7 @@ suspend fun ApplicationCall.deleteCommentRoute(): Nothing { Comment.Table.del(commentId) - redirect("/lore/${comment.submittedIn}") + redirect("/lore/${comment.submittedIn}#comments") } suspend fun ApplicationCall.commentHelpPage(): HTML.() -> Unit = page("Commenting Help", standardNavBar()) { diff --git a/src/main/kotlin/info/mechyrdia/lore/view_nav.kt b/src/main/kotlin/info/mechyrdia/lore/view_nav.kt index 7ea5db1..a666b29 100644 --- a/src/main/kotlin/info/mechyrdia/lore/view_nav.kt +++ b/src/main/kotlin/info/mechyrdia/lore/view_nav.kt @@ -47,7 +47,10 @@ suspend fun ApplicationCall.standardNavBar(path: List? = null) = listOf( )) + listOf( NavHead("Useful Links"), NavLink("/comment/help", "Commenting Help"), + NavLink("/comment/recent", "Recent Comments"), + NavHead("See Also"), NavLink("https://nationstates.net/$OWNER_NATION", "Mechyrdia on NationStates"), + NavLink("https://laniustrolling.dev/", "The Man Behind Mechyrdia"), ) sealed class NavItem { diff --git a/src/main/resources/static/init.js b/src/main/resources/static/init.js index ed9a1fe..124f980 100644 --- a/src/main/resources/static/init.js +++ b/src/main/resources/static/init.js @@ -111,7 +111,7 @@ if (input.value !== inText) return; - output.innerHTML = outText; + output.innerHTML = "

Preview:

" + outText; } const commentInputBoxes = document.getElementsByClassName("comment-input"); diff --git a/src/main/resources/static/style.css b/src/main/resources/static/style.css index 25c7bfa..a32e308 100644 --- a/src/main/resources/static/style.css +++ b/src/main/resources/static/style.css @@ -673,12 +673,18 @@ iframe { border-color: var(--iframe-border); } +#error-popup { + z-index: 998; +} + #error-popup > .bg { position: fixed; width: 100vw; height: 100vh; + left: 0; + top: 0; + background-color: rgba(0, 0, 0, 40%); - z-index: 998; } #error-popup > .msg { @@ -719,6 +725,13 @@ textarea.lang-tylan { font-family: 'Noto Sans Gothic', sans-serif; } +.comment-input { + border: 0.25em solid var(--comment-stroke); + background-color: var(--comment-fill); + padding: 0.75em; + margin: 1em 0; +} + .comment-box { border: 0.25em solid var(--comment-stroke); background-color: var(--comment-fill); @@ -758,6 +771,7 @@ textarea.lang-tylan { } .comment-box > .comment { + margin-top: 0.125em; border-top: 0.25em solid var(--comment-stroke); padding-top: 0.5em; }