aboutsummaryrefslogtreecommitdiff
path: root/src/mixins/comment.pug
blob: a7bf9d9698851014134c682b487cf81f485c17d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
include ../utils

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)' : ''}
    |  · 
    if data.collapsed_reason_code == "DELETED"
      a(href=`https://undelete.pullpush.io${data.permalink}`) search on undelete
      |  · 
    | #{timeDifference(Date.now(), data.created * 1000)}

-
  function hasReplies(data) {
    return data.replies && data.replies.data && data.replies.data.children && data.replies.data.children.length > 0;
  }

mixin comment(com, isfirst, parent_id, next_id, prev_id)
  - var data = com.data
  - var hasReplyData = hasReplies(data)

  if com.kind == "more"
    div(class=`more ${isfirst ? 'first' : ''}`)
      a(href=`/comments/${parent_id}/comment/${data.id}`)
        | #{data.count} more #{fmttxt(data.count, 'comment')}
  else
    div(class=`comment ${isfirst ? 'first' : ''}`)
      details(id=`${data.id}` open="")
        summary.expand-comments
          +infoContainer(data, next_id, prev_id)
        div.comment-body
          != data.body_html
        if hasReplyData
          div.replies
            - 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)