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 | 12x 3x 1x 29x 1x 3x 1x 9x 3x 9x 9x 9x 9x 9x 9x 10x 10x 9x | <template>
<section
id="comentarios"
aria-labelledby="comentarios-titulo"
class="flex max-w-measure flex-col gap-8 border-t-2 border-inverted pt-6 print:hidden"
>
<div class="flex flex-wrap items-center justify-between gap-x-4 gap-y-2">
<h2 id="comentarios-titulo" class="font-serif text-h3 text-highlighted">
{{ $t("commentsSection.title", { count: comments?.count }, comments?.count ?? 0) }}
</h2>
<ListingSortSelect v-if="sortable" v-model="sort" :copy="sortCopy" />
</div>
<ol v-if="threads.length" class="flex flex-col gap-8">
<li v-for="thread in threads" :key="thread.id">
<CommentThread :thread :replyable="open" @reply="replyTo = $event" />
</li>
</ol>
<p v-else-if="comments && open" class="font-serif text-base text-toned">
{{ $t("commentsSection.empty") }}
</p>
<div v-if="open" class="flex flex-col gap-4">
<h3 class="font-serif text-card text-highlighted">
{{ $t("commentsSection.formTitle") }}
</h3>
<CommentForm :post-id="article.id" :reply-to @cancel-reply="replyTo = undefined" />
</div>
<p v-else class="font-sans text-meta text-muted">
{{ $t("commentsSection.closed") }}
</p>
</section>
</template>
<script setup lang="ts">
interface Props {
article: Pick<Article, "id">;
comments?: ArticleComments;
}
const props = defineProps<Props>();
const SORTABLE_FROM = 5;
const { t } = useI18n();
const replyTo = ref<ReaderComment>();
const sort = ref<"newest" | "oldest">("oldest");
const sortable = computed<boolean>(() => (props.comments?.threads.length ?? 0) >= SORTABLE_FROM);
const sortCopy = computed(() => ({
label: t("commentsSection.sort.label"),
newest: t("commentsSection.sort.newest"),
oldest: t("commentsSection.sort.oldest"),
}));
const threads = computed<CommentThread[]>(() => {
const oldestFirst = props.comments?.threads ?? [];
return sort.value === "newest" ? oldestFirst.toReversed() : oldestFirst;
});
const open = computed<boolean>(() => props.comments?.open !== false);
</script>
|