Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | 114x 111x 6x 6x 111x 6x 6x 8x 4x 5x 2x 1x 11x 1x 1x 1x 1x 1x 6x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 70x 71x 70x 71x 2x 72x 71x 12x 12x 3x 3x 2x 2x 2x 1x 4x 4x 2x 2x 2x 2x 2x 1x 2x 3x 3x 3x 2x 1x 3x 3x 3x 2x 2x 1x | <template>
<li class="comment-node" :data-comment-id="comment.id">
<div v-if="comment.deleted" class="comment-tombstone text-muted fst-italic">
{{ t('comment.deleted') }}
</div>
<div v-else class="comment-row d-flex gap-2">
<router-link
v-if="comment.authorId"
:to="{ name: 'user-profile', params: { userId: comment.authorId } }"
class="comment-avatar"
>
<UserAvatar :picture-key="comment.authorProfilePicture" :size="32" />
</router-link>
<div class="comment-main flex-grow-1">
<div class="comment-meta small">
<router-link
v-if="comment.authorId"
:to="{ name: 'user-profile', params: { userId: comment.authorId } }"
class="fw-semibold text-decoration-none"
>
{{ comment.authorName || t('comment.unknownAuthor') }}
</router-link>
<span v-if="comment.authorNickname" class="text-muted ms-1">
@{{ comment.authorNickname }}
</span>
<time
class="text-muted ms-2"
:datetime="comment.createdAt"
:title="formatDateTime(comment.createdAt)"
>
{{ formatRelative(comment.createdAt) }}
</time>
<!-- A pack's comments stay across versions: say which one this was about -->
<span
v-if="comment.packVersion"
class="badge bg-light text-muted border ms-2 comment-pack-version"
>
{{ t('store.versionLabel').replace('{version}', String(comment.packVersion)) }}
</span>
</div>
<p class="comment-text mb-1">{{ comment.body }}</p>
<div class="comment-actions small">
<button
v-if="comment.status === 'approved' && !commentsStore.blocked"
type="button"
class="btn btn-link btn-sm p-0 me-3"
@click="replying = !replying"
>
<font-awesome-icon icon="fa-solid fa-reply" class="me-1" />
{{ t('comment.reply') }}
</button>
<button
v-if="canDelete"
type="button"
class="btn btn-link btn-sm p-0 text-danger me-3"
@click="confirmingDelete = true"
>
<font-awesome-icon icon="fa-solid fa-trash" class="me-1" />
{{ t('comment.delete') }}
</button>
<button
v-if="canBlock"
type="button"
class="btn btn-link btn-sm p-0 text-danger me-3"
@click="confirmingBlock = true"
>
<font-awesome-icon icon="fa-solid fa-ban" class="me-1" />
{{ t('comment.blockAuthor') }}
</button>
<button
v-if="canReport"
type="button"
class="btn btn-link btn-sm p-0 text-muted comment-report"
@click="reporting = true"
>
<font-awesome-icon icon="fa-solid fa-flag" class="me-1" />
{{ t('report.action') }}
</button>
</div>
</div>
</div>
<div v-if="replying" class="comment-reply-composer mt-2">
<CommentComposer
:label="t('comment.replyComposerLabel')"
:placeholder="t('comment.replyPlaceholder')"
:submit-label="t('comment.postReply')"
:on-submit="submitReply"
:draft-key="replyDraftKey"
cancelable
autofocus
@cancel="replying = false"
/>
</div>
<div v-if="comment.replyCount > 0" class="comment-replies-block mt-1">
<button v-if="!expanded" type="button" class="btn btn-link btn-sm p-0" @click="expand">
{{ viewRepliesLabel }}
</button>
<template v-else>
<ul
class="comment-replies list-unstyled mb-1"
:class="{ 'comment-replies-indented': level < MAX_INDENTED_LEVEL }"
>
<CommentNode
v-for="reply in replies.comments"
:key="reply.id"
:comment="reply"
:level="level + 1"
:can-manage="canManage"
@count-change="$emit('count-change', $event)"
/>
</ul>
<button
v-if="replies.nextToken"
type="button"
class="btn btn-link btn-sm p-0 me-3"
:disabled="replies.loading"
@click="loadMoreReplies"
>
{{ t('common.loadMore') }}
</button>
<button type="button" class="btn btn-link btn-sm p-0" @click="expanded = false">
{{ t('comment.hideReplies') }}
</button>
</template>
</div>
<ConfirmModal
:is-open="confirmingDelete"
:title="t('comment.deleteTitle')"
:message="t('comment.deleteConfirm')"
:confirm-label="t('comment.delete')"
variant="danger"
@confirm="doDelete"
@cancel="confirmingDelete = false"
/>
<ConfirmModal
:is-open="confirmingBlock"
:title="t('comment.blockTitle')"
:message="
t(commentsStore.packId ? 'store.commentBlockConfirm' : 'comment.blockConfirm').replace(
'{name}',
authorLabel
)
"
:confirm-label="t('comment.blockAuthor')"
variant="warning"
@confirm="doBlock"
@cancel="confirmingBlock = false"
/>
<ReportModal :target="reporting ? reportTarget : null" @close="reporting = false" />
</li>
</template>
<script setup lang="ts">
// @implements UC-COMMENT-003.1, UC-COMMENT-004.1, UC-COMMENT-005.1, UC-COMMENT-006.1, UC-COMMENT-007.1, UC-STORE-009.1, UC-REPORT-001.1
import { computed, ref } from 'vue'
import CommentComposer from '@/components/CommentComposer.vue'
import ConfirmModal from '@/components/ConfirmModal.vue'
import ReportModal from '@/components/ReportModal.vue'
import UserAvatar from '@/components/UserAvatar.vue'
import { useUILanguage } from '@/composables/useUILanguage'
import { useDateFormat } from '@/composables/useDateFormat'
import { useAuthStore } from '@/stores/auth'
import { useCommentsStore, type Comment } from '@/stores/comments'
import { useToastStore } from '@/stores/toast'
import { getErrorMessage } from '@/utils/errors'
import { commentDraftKey, packCommentDraftKey, readCommentDraft } from '@/utils/commentDraft'
import type { ReportTarget } from '@/services/contentReports'
// Replies keep nesting to any depth, but past this level they stop being
// pushed further right so a long thread stays readable on a small screen.
const MAX_INDENTED_LEVEL = 2
const props = withDefaults(
defineProps<{
comment: Comment
level: number
// The user manages this entity's comments: may delete anybody's and block authors
canManage?: boolean
}>(),
{ canManage: false }
)
const emit = defineEmits<{
// Change to the item's comment counter caused by something done in this thread
'count-change': [delta: number]
}>()
const { t } = useUILanguage()
const { formatRelative, formatDateTime } = useDateFormat()
const authStore = useAuthStore()
const commentsStore = useCommentsStore()
const toastStore = useToastStore()
const replyDraftKey = props.comment.packId
? packCommentDraftKey(props.comment.packId, props.comment.id)
: commentDraftKey(props.comment.entityId!, props.comment.itemId!, props.comment.id)
// A reply left half-written (panel closed, page reloaded) opens again with its text
const replying = ref(!!readCommentDraft(replyDraftKey))
const expanded = ref(false)
const confirmingDelete = ref(false)
const confirmingBlock = ref(false)
const reporting = ref(false)
const replies = computed(() => commentsStore.listFor(props.comment.id))
const isOwnComment = computed(() => props.comment.authorId === authStore.userId)
const canDelete = computed(() => !props.comment.deleted && (isOwnComment.value || props.canManage))
// Nobody blocks themselves, and a tombstone has no author left to block.
const canBlock = computed(
() => props.canManage && !props.comment.deleted && !!props.comment.authorId && !isOwnComment.value
)
// Only what others can see is reported: an approved comment by somebody else
const canReport = computed(
() =>
props.comment.status === 'approved' &&
!props.comment.deleted &&
!!props.comment.authorId &&
!isOwnComment.value
)
const reportTarget = computed<ReportTarget>(() =>
props.comment.packId
? { type: 'comment', commentId: props.comment.id, packId: props.comment.packId }
: {
type: 'comment',
commentId: props.comment.id,
entityId: props.comment.entityId!,
itemId: props.comment.itemId!
}
)
const authorLabel = computed(() => props.comment.authorName || t('comment.unknownAuthor'))
const viewRepliesLabel = computed(() =>
(props.comment.replyCount === 1 ? t('comment.viewReply') : t('comment.viewReplies')).replace(
'{count}',
String(props.comment.replyCount)
)
)
async function expand() {
expanded.value = true
if (replies.value.loaded) return
try {
await commentsStore.fetchList(props.comment.id)
} catch (err) {
toastStore.error(getErrorMessage(err, t('comment.loadError'), t))
}
}
async function loadMoreReplies() {
try {
await commentsStore.fetchList(props.comment.id, true)
} catch (err) {
toastStore.error(getErrorMessage(err, t('comment.loadError'), t))
}
}
async function submitReply(body: string): Promise<boolean> {
try {
const { countDelta } = await commentsStore.createComment(body, props.comment.id)
emit('count-change', countDelta)
replying.value = false
Eif (!expanded.value) await expand()
return true
} catch (err: any) {
// The panel's quota alert explains this one, with a way to fix it
if (err.response?.data?.error !== 'MODERATION_QUOTA_REQUIRED') {
toastStore.error(getErrorMessage(err, t('comment.postError'), t))
}
return false
}
}
async function doBlock() {
confirmingBlock.value = false
try {
await commentsStore.blockAuthor(props.comment.authorId!)
toastStore.success(
t(commentsStore.packId ? 'store.commentBlockSuccess' : 'comment.blockSuccess').replace(
'{name}',
authorLabel.value
)
)
} catch (err) {
toastStore.error(getErrorMessage(err, t('comment.blockError'), t))
}
}
async function doDelete() {
confirmingDelete.value = false
try {
// Reported from the callback: once removed, this node is unmounted and could no longer emit
await commentsStore.deleteComment(props.comment, (countDelta) =>
emit('count-change', countDelta)
)
toastStore.success(t('comment.deleteSuccess'))
} catch (err) {
toastStore.error(getErrorMessage(err, t('comment.deleteError'), t))
}
}
</script>
<style scoped>
.comment-node {
padding: 0.5rem 0;
border-bottom: 1px solid var(--bw-border, rgba(0, 0, 0, 0.08));
}
.comment-node:last-child {
border-bottom: 0;
}
.comment-text {
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.comment-replies-indented {
margin-left: 1rem;
padding-left: 0.75rem;
border-left: 2px solid var(--bw-border, rgba(0, 0, 0, 0.12));
}
.comment-reply-composer {
margin-left: 2.5rem;
}
</style>
|