From 2dcddd9408c32cde150c7a707cbbc01914592514 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 26 Nov 2024 23:55:05 +0000 Subject: add next/prev links to comments --- src/mixins/comment.pug | 25 +++++++++++++++++++------ src/mixins/post.pug | 2 +- src/public/styles.css | 11 ++++++++++- src/views/comments.pug | 11 +++++++++-- src/views/single_comment_thread.pug | 10 ++++++++-- 5 files changed, 47 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/mixins/comment.pug b/src/mixins/comment.pug index f6d7b5e..a7bf9d9 100644 --- a/src/mixins/comment.pug +++ b/src/mixins/comment.pug @@ -1,9 +1,15 @@ include ../utils -mixin infoContainer(data) +mixin infoContainer(data, next_id, prev_id) div.comment-info-container | #{fmtnum(data.ups)} ↑ - |  ·  + | ·  + if next_id + a(href=`#${next_id}`).nav-link next + |  ·  + if prev_id + a(href=`#${prev_id}`).nav-link prev + |  ·  span(class=`${data.is_submitter ? 'op' : ''}`) | u/#{data.author} #{data.is_submitter ? '(op)' : ''} |  ·  @@ -17,7 +23,7 @@ mixin infoContainer(data) return data.replies && data.replies.data && data.replies.data.children && data.replies.data.children.length > 0; } -mixin comment(com, isfirst, parent_id) +mixin comment(com, isfirst, parent_id, next_id, prev_id) - var data = com.data - var hasReplyData = hasReplies(data) @@ -29,10 +35,17 @@ mixin comment(com, isfirst, parent_id) div(class=`comment ${isfirst ? 'first' : ''}`) details(id=`${data.id}` open="") summary.expand-comments - +infoContainer(data) + +infoContainer(data, next_id, prev_id) div.comment-body != data.body_html if hasReplyData div.replies - each reply in data.replies.data.children - +comment(reply, false, parent_id) + - var total = data.replies.data.children.length + each reply, index in data.replies.data.children + - var next_idx = index + 1 + - var prev_idx = index - 1 + - var next_com = next_idx < total ? data.replies.data.children[next_idx] : null + - var prev_com = prev_idx >= 0 ? data.replies.data.children[prev_idx] : null + - var next_id = next_com ? next_com.data.id : null + - var prev_id = prev_com ? prev_com.data.id : null + +comment(reply, false, parent_id, next_id, prev_id) diff --git a/src/mixins/post.pug b/src/mixins/post.pug index 4287801..027e42f 100644 --- a/src/mixins/post.pug +++ b/src/mixins/post.pug @@ -13,7 +13,7 @@ mixin post(p) | #{fmtnum(p.ups)} ↑ span.post-author |  ·  - by u/#{p.author} + | u/#{p.author} |  ·  | #{timeDifference(Date.now(), p.created * 1000)} |  ·  diff --git a/src/public/styles.css b/src/public/styles.css index 090205e..3114173 100644 --- a/src/public/styles.css +++ b/src/public/styles.css @@ -33,6 +33,10 @@ :root { font-family: InterVariable, sans-serif; } } +html { + scroll-behavior: smooth; +} + body { overflow-x: hidden; background-color: var(--bg-color); @@ -50,7 +54,8 @@ main { .info-container a, .comment-info-container a, .sort-opts a, -.more a { +.more a +{ text-decoration: none; } @@ -565,3 +570,7 @@ form input[type="submit"]:hover { .about { padding-bottom: 20px; } + +a.nav-link { + color: var(--text-color-muted); +} diff --git a/src/views/comments.pug b/src/views/comments.pug index 844dfcc..bbd7855 100644 --- a/src/views/comments.pug +++ b/src/views/comments.pug @@ -59,5 +59,12 @@ html hr div.comments-container - each child in comments - +comment(child, true, post.id) + - var total = comments.length + each child, index in comments + - var next_idx = index + 1 + - var prev_idx = index - 1 + - var next_com = next_idx < total ? comments[next_idx] : null + - var prev_com = prev_idx >= 0 ? comments[prev_idx] : null + - var next_id = next_com ? next_com.data.id : null + - var prev_id = prev_com ? prev_com.data.id : null + +comment(child, true, post.id, next_id, prev_id) diff --git a/src/views/single_comment_thread.pug b/src/views/single_comment_thread.pug index 1f37e9f..b12da6f 100644 --- a/src/views/single_comment_thread.pug +++ b/src/views/single_comment_thread.pug @@ -16,6 +16,12 @@ html div p nothing to see here, this thread was shadow-banned? else - each comment in comments - +comment(comment, true, parent_id) + each comment, index in comments + - var next_idx = index + 1 + - var prev_idx = index - 1 + - var next_com = next_idx < total ? comments[next_idx] : null + - var prev_com = prev_idx >= 0 ? comments[prev_idx] : null + - var next_id = next_com ? next_com.data.id : null + - var prev_id = prev_com ? prev_com.data.id : null + +comment(comment, true, parent_id, next_idx, prev_idx) -- cgit v1.2.3