diff options
author | Akshay <[email protected]> | 2024-11-26 23:55:05 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2024-11-26 23:55:05 +0000 |
commit | 2dcddd9408c32cde150c7a707cbbc01914592514 (patch) | |
tree | 1094b0404b9d52a3a16fb8d743c8509cd1ffbcbe /src/mixins | |
parent | 0d4d90ba058ed3b7ee0d4054602096d16151303c (diff) |
add next/prev links to comments
Diffstat (limited to 'src/mixins')
-rw-r--r-- | src/mixins/comment.pug | 25 | ||||
-rw-r--r-- | src/mixins/post.pug | 2 |
2 files changed, 20 insertions, 7 deletions
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 @@ | |||
1 | include ../utils | 1 | include ../utils |
2 | 2 | ||
3 | mixin infoContainer(data) | 3 | mixin infoContainer(data, next_id, prev_id) |
4 | div.comment-info-container | 4 | div.comment-info-container |
5 | | #{fmtnum(data.ups)} ↑ | 5 | | #{fmtnum(data.ups)} ↑ |
6 | | · | 6 | | · |
7 | if next_id | ||
8 | a(href=`#${next_id}`).nav-link next | ||
9 | | · | ||
10 | if prev_id | ||
11 | a(href=`#${prev_id}`).nav-link prev | ||
12 | | · | ||
7 | span(class=`${data.is_submitter ? 'op' : ''}`) | 13 | span(class=`${data.is_submitter ? 'op' : ''}`) |
8 | | u/#{data.author} #{data.is_submitter ? '(op)' : ''} | 14 | | u/#{data.author} #{data.is_submitter ? '(op)' : ''} |
9 | | · | 15 | | · |
@@ -17,7 +23,7 @@ mixin infoContainer(data) | |||
17 | return data.replies && data.replies.data && data.replies.data.children && data.replies.data.children.length > 0; | 23 | return data.replies && data.replies.data && data.replies.data.children && data.replies.data.children.length > 0; |
18 | } | 24 | } |
19 | 25 | ||
20 | mixin comment(com, isfirst, parent_id) | 26 | mixin comment(com, isfirst, parent_id, next_id, prev_id) |
21 | - var data = com.data | 27 | - var data = com.data |
22 | - var hasReplyData = hasReplies(data) | 28 | - var hasReplyData = hasReplies(data) |
23 | 29 | ||
@@ -29,10 +35,17 @@ mixin comment(com, isfirst, parent_id) | |||
29 | div(class=`comment ${isfirst ? 'first' : ''}`) | 35 | div(class=`comment ${isfirst ? 'first' : ''}`) |
30 | details(id=`${data.id}` open="") | 36 | details(id=`${data.id}` open="") |
31 | summary.expand-comments | 37 | summary.expand-comments |
32 | +infoContainer(data) | 38 | +infoContainer(data, next_id, prev_id) |
33 | div.comment-body | 39 | div.comment-body |
34 | != data.body_html | 40 | != data.body_html |
35 | if hasReplyData | 41 | if hasReplyData |
36 | div.replies | 42 | div.replies |
37 | each reply in data.replies.data.children | 43 | - var total = data.replies.data.children.length |
38 | +comment(reply, false, parent_id) | 44 | each reply, index in data.replies.data.children |
45 | - var next_idx = index + 1 | ||
46 | - var prev_idx = index - 1 | ||
47 | - var next_com = next_idx < total ? data.replies.data.children[next_idx] : null | ||
48 | - var prev_com = prev_idx >= 0 ? data.replies.data.children[prev_idx] : null | ||
49 | - var next_id = next_com ? next_com.data.id : null | ||
50 | - var prev_id = prev_com ? prev_com.data.id : null | ||
51 | +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) | |||
13 | | #{fmtnum(p.ups)} ↑ | 13 | | #{fmtnum(p.ups)} ↑ |
14 | span.post-author | 14 | span.post-author |
15 | | · | 15 | | · |
16 | by u/#{p.author} | 16 | | u/#{p.author} |
17 | | · | 17 | | · |
18 | | #{timeDifference(Date.now(), p.created * 1000)} | 18 | | #{timeDifference(Date.now(), p.created * 1000)} |
19 | | · | 19 | | · |