aboutsummaryrefslogtreecommitdiff
path: root/src/components/Thread.astro
blob: 6fae3de1cfb2faadce88c2ea7b431febcb0ea567 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
import type Thread from '../models/Thread';
import Post from './Post.astro';
import Image from './Image.astro';

export interface Props {
  thread: Thread;
  board: string;
  comments: boolean;
}

const { thread, board, comments = false } = Astro.props;

let replies: string[] = [];
const listReplies = (id: string, getReplies: boolean = false): any => {
  if(getReplies) return replies;

  replies = [];
  thread.comments.forEach(comment => {
    if(comment.commentText.includes(id))
      replies.push(comment.id);
  })

  if(replies.length <= 0) return false;
  return true;
}
---

{(thread.id != "rules") && ( <>
  <Post id={thread.id} date={thread.creationDate} creator={thread.threadCreator} box="threadbox" board={(!comments) ? board : ''}>

    {comments && (listReplies(thread.id) && (
      <span class="small-mono">
        {listReplies(thread.id, true).map((id) => ( <>
          <a href=`/board/${board}/${thread.id}#${id}` onmouseover=`onMouseOver('${id}')` onmouseleave=`onMouseLeave('${id}')`>>>{id}</a>&#65279;
        </> ))}
      </span> <hr>
    ))}


    <h3>{thread.threadName}</h3>
    <Image image={thread.imageId} fileType={thread.fileType} />
    <p set:html={thread.threadText} />

    {comments && ( <>
      {thread.comments.map((comment) => ( <>
        <Post id={comment.id} date={comment.creationDate} creator={comment.commentCreator} box="commentbox">

          {listReplies(comment.id) && (
            <span class="small-mono">
              {listReplies(comment.id, true).map((id) => ( <>
                <a href=`/board/${board}/${thread.id}#${id}` onmouseover=`onMouseOver('${id}')` onmouseleave=`onMouseLeave('${id}')`>>>{id}</a>&#65279;
              </> ))}
            </span> <hr>
          )}

          <Image image={comment.imageId} fileType={comment.fileType} />
          <p set:html={comment.commentText} />

        </Post>
      </> ))}
    </> )}

  </Post>
</> )}

{comments && ( <>
  <script is:inline>
    function onMouseOver(id) {
      document.getElementById(id).classList.add('targeted');
    }
    function onMouseLeave(id) {
      document.getElementById(id).classList.remove('targeted');
    }
  </script>

  <style is:inline>
    .small-mono {
      display:inline-block; line-height: 2ch; font-size: 0.8rem; font-family: monospace;
    }
  </style>
</> )}