Fix flaws in first commit
authorLanius Trolling <lanius@laniustrolling.dev>
Mon, 13 Feb 2023 20:03:43 +0000 (15:03 -0500)
committerLanius Trolling <lanius@laniustrolling.dev>
Mon, 13 Feb 2023 20:03:43 +0000 (15:03 -0500)
src/main/kotlin/info/mechyrdia/Factbooks.kt
src/main/kotlin/info/mechyrdia/data/view_comments.kt
src/main/kotlin/info/mechyrdia/data/views_comment.kt
src/main/kotlin/info/mechyrdia/lore/view_nav.kt
src/main/resources/static/init.js
src/main/resources/static/style.css

index 4faddf4958a3acd1b6ad3e3e8de0ddb3c4477f6c..de4ff2ee5d6ef0d5f108b50bd6a15e7b9f563bb9 100644 (file)
@@ -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()
                }
index 78c70441b5893d124f5fad7ab4145bd20af52846..320eb0fcb16445422ba31d1af9f2579afdeb1d4e 100644 (file)
@@ -131,7 +131,7 @@ fun FlowContent.commentBox(comment: CommentRenderData, loggedInAs: Id<NationData
                        }
                        installCsrfToken(createCsrfToken(formPath))
                        submitInput { value = "Edit Comment" }
-                       button(classes = "comment-cancel-edit") {
+                       button(classes = "comment-cancel-edit evil") {
                                +"Cancel Editing"
                        }
                }
index 9f0762d91b911e44e8d00a44ccb77b817d95133c..d2437c0405a87cc8cbdcf06b400d4f636e93403f 100644 (file)
@@ -6,11 +6,57 @@ import info.mechyrdia.auth.createCsrfToken
 import info.mechyrdia.auth.installCsrfToken
 import info.mechyrdia.auth.verifyCsrfToken
 import info.mechyrdia.lore.*
+import io.ktor.http.*
 import io.ktor.server.application.*
 import io.ktor.server.util.*
+import kotlinx.coroutines.flow.take
+import kotlinx.coroutines.flow.toList
 import kotlinx.html.*
+import org.litote.kmongo.descending
 import java.time.Instant
 
+suspend fun ApplicationCall.recentCommentsPage(): HTML.() -> 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()) {
index 7ea5db1a936f73e81518679db150d536d8a4b203..a666b294f3be9dca0456e9b9d7721710aebf7f6b 100644 (file)
@@ -47,7 +47,10 @@ suspend fun ApplicationCall.standardNavBar(path: List<String>? = 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 {
index ed9a1fe79e2d714e0540ec6a817fbf4f5b61ddd3..124f980bf4b5e0fc4a547027023d62ce2d5c3e7a 100644 (file)
                        if (input.value !== inText)
                                return;
 
-                       output.innerHTML = outText;
+                       output.innerHTML = "<h3>Preview:</h3>" + outText;
                }
 
                const commentInputBoxes = document.getElementsByClassName("comment-input");
index 25c7bfaa18b83f631467d7af972383f01d4a3cb7..a32e30812d326f86dd4f377ba018f62ce26f1a06 100644 (file)
@@ -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;
 }