forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlueskyCommentThread.vue
More file actions
72 lines (64 loc) · 1.97 KB
/
BlueskyCommentThread.vue
File metadata and controls
72 lines (64 loc) · 1.97 KB
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
<script setup lang="ts">
import type { Comment } from '#shared/types/blog-post'
const props = defineProps<{
comment: Comment
}>()
interface FlatReply {
comment: Comment
replyingTo?: string
}
function flattenReplies(comment: Comment): FlatReply[] {
const result: FlatReply[] = []
function walk(replies: Comment[], parentName: string, isDirectReply: boolean) {
for (const reply of replies) {
result.push({
comment: reply,
replyingTo: isDirectReply ? undefined : parentName,
})
if (reply.replies.length > 0) {
walk(reply.replies, reply.author.displayName || reply.author.handle, false)
}
}
}
walk(comment.replies, comment.author.displayName || comment.author.handle, true)
return result
}
const flatReplies = computed(() => flattenReplies(props.comment))
const totalReplyCount = computed(() => flatReplies.value.length)
const showReplies = ref(false)
</script>
<template>
<div>
<!-- Top-level comment -->
<BlueskyComment :comment="comment" />
<!-- Replies section -->
<div v-if="totalReplyCount > 0" class="ms-13 mt-2">
<!-- Toggle button -->
<button
v-if="!showReplies"
class="text-sm text-accent font-medium hover:underline cursor-pointer"
@click="showReplies = true"
>
{{ $t('blog.atproto.view_replies', { count: totalReplyCount }, totalReplyCount) }}
</button>
<!-- Expanded replies -->
<template v-else>
<button
class="text-sm text-accent font-medium hover:underline mb-3 cursor-pointer"
@click="showReplies = false"
>
{{ $t('blog.atproto.hide_replies') }}
</button>
<div class="flex flex-col gap-4">
<BlueskyComment
v-for="reply in flatReplies"
:key="reply.comment.uri"
:comment="reply.comment"
:replying-to="reply.replyingTo"
is-reply
/>
</div>
</template>
</div>
</div>
</template>