From 21a75483fe704aea21d131423f0398d04ec8b820 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 22 May 2018 20:44:27 +0100 Subject: [PATCH] Fixes anchored post links spamming the browser history. --- public/css/nimforum.scss | 2 +- src/frontend/postlist.nim | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/public/css/nimforum.scss b/public/css/nimforum.scss index 28b4d3c..ad1d712 100644 --- a/public/css/nimforum.scss +++ b/public/css/nimforum.scss @@ -266,7 +266,7 @@ $threads-meta-color: #545d70; border-top: 1px solid $border-color; padding-top: $control-padding-y-lg; - &:target .post-main { + &:target .post-main, &.highlight .post-main { animation: highlight 2000ms ease-out; } } diff --git a/src/frontend/postlist.nim b/src/frontend/postlist.nim index 2ee46c3..0e998c0 100644 --- a/src/frontend/postlist.nim +++ b/src/frontend/postlist.nim @@ -71,8 +71,7 @@ when defined(js): () => ( # Would have used scrollIntoView but then the `:target` selector # isn't activated. - window.location.hash = ""; - window.location.hash = "#" & $postId.get() + getVNodeById($postId.get()).dom.scrollIntoView() ), 100 ) @@ -214,11 +213,13 @@ when defined(js): italic(class="fas fa-reply") text " Reply" - proc genPost(post: Post, thread: Thread, currentUser: Option[User]): VNode = + proc genPost( + post: Post, thread: Thread, currentUser: Option[User], highlight: bool + ): VNode = let postCopy = post # TODO: Another workaround here, closure capture :( result = buildHtml(): - tdiv(class="post", id = $post.id): + tdiv(class=class({"highlight": highlight}, "post"), id = $post.id): tdiv(class="post-icon"): render(post.author, "post-avatar") tdiv(class="post-main"): @@ -345,7 +346,8 @@ when defined(js): genTimePassed(prevPost.get(), some(post), false) if post.moreBefore.len > 0: genLoadMore(post, i) - genPost(post, list.thread, currentUser) + let highlight = postId.isSome() and postId.get() == post.id + genPost(post, list.thread, currentUser, highlight) prevPost = some(post) if prevPost.isSome: