2020-02-18 08:57:00 +01:00
|
|
|
<template>
|
|
|
|
<router-link
|
2022-07-12 10:55:28 +02:00
|
|
|
class="flex gap-1 w-full items-center p-2 border-b-stone-200 border-b"
|
2021-11-07 14:59:20 +01:00
|
|
|
dir="auto"
|
2020-11-30 10:24:11 +01:00
|
|
|
:to="{
|
|
|
|
name: RouteName.DISCUSSION,
|
|
|
|
params: { slug: discussion.slug, id: discussion.id },
|
|
|
|
}"
|
2020-02-18 08:57:00 +01:00
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="">
|
2020-08-14 11:32:23 +02:00
|
|
|
<figure
|
2022-07-12 10:55:28 +02:00
|
|
|
class=""
|
2020-11-30 10:24:11 +01:00
|
|
|
v-if="
|
2022-07-12 10:55:28 +02:00
|
|
|
discussion.lastComment?.actor && discussion.lastComment.actor.avatar
|
2020-11-30 10:24:11 +01:00
|
|
|
"
|
2020-08-14 11:32:23 +02:00
|
|
|
>
|
2020-11-30 10:24:11 +01:00
|
|
|
<img
|
2022-07-12 10:55:28 +02:00
|
|
|
class="rounded-xl"
|
2020-11-30 10:24:11 +01:00
|
|
|
:src="discussion.lastComment.actor.avatar.url"
|
2022-07-12 10:55:28 +02:00
|
|
|
alt=""
|
|
|
|
width="32"
|
|
|
|
height="32"
|
2020-11-30 10:24:11 +01:00
|
|
|
/>
|
2020-02-18 08:57:00 +01:00
|
|
|
</figure>
|
2022-07-12 10:55:28 +02:00
|
|
|
<account-circle :size="32" v-else />
|
2020-02-18 08:57:00 +01:00
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="flex-1">
|
|
|
|
<div class="flex items-center">
|
|
|
|
<p class="text-violet-3 dark:text-white text-lg font-semibold flex-1">
|
|
|
|
{{ discussion.title }}
|
|
|
|
</p>
|
|
|
|
<span class="" :title="formatDateTimeString(actualDate)">
|
|
|
|
{{ distanceToNow }}</span
|
2020-08-14 11:32:23 +02:00
|
|
|
>
|
|
|
|
</div>
|
2021-06-30 15:30:44 +02:00
|
|
|
<div
|
2022-07-12 10:55:28 +02:00
|
|
|
class="line-clamp-2"
|
2021-11-07 14:59:20 +01:00
|
|
|
dir="auto"
|
2022-07-12 10:55:28 +02:00
|
|
|
v-if="!discussion.lastComment?.deletedAt"
|
2021-06-30 15:30:44 +02:00
|
|
|
>
|
2020-08-14 11:32:23 +02:00
|
|
|
{{ htmlTextEllipsis }}
|
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div v-else class="">
|
|
|
|
{{ t("[This comment has been deleted]") }}
|
2020-11-30 10:24:11 +01:00
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
</div>
|
|
|
|
</router-link>
|
|
|
|
</template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
2020-10-13 20:39:59 +02:00
|
|
|
import { formatDistanceToNowStrict } from "date-fns";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { IDiscussion } from "@/types/discussions";
|
|
|
|
import RouteName from "@/router/name";
|
|
|
|
import { computed, inject } from "vue";
|
|
|
|
import { formatDateTimeString } from "@/filters/datetime";
|
|
|
|
import type { Locale } from "date-fns";
|
|
|
|
import AccountCircle from "vue-material-design-icons/AccountCircle.vue";
|
|
|
|
import { useI18n } from "vue-i18n";
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
discussion: IDiscussion;
|
|
|
|
}>();
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const dateFnsLocale = inject<Locale>("dateFnsLocale");
|
|
|
|
const { t } = useI18n({ useScope: "global" });
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const distanceToNow = computed(() => {
|
|
|
|
return (
|
|
|
|
formatDistanceToNowStrict(new Date(actualDate.value), {
|
|
|
|
locale: dateFnsLocale,
|
|
|
|
}) ?? t("Right now")
|
|
|
|
);
|
|
|
|
});
|
2020-10-13 20:39:59 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const htmlTextEllipsis = computed((): string => {
|
|
|
|
const element = document.createElement("div");
|
|
|
|
if (props.discussion.lastComment && props.discussion.lastComment.text) {
|
|
|
|
element.innerHTML = props.discussion.lastComment.text
|
|
|
|
.replace(/<br\s*\/?>/gi, " ")
|
|
|
|
.replace(/<p>/gi, " ");
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return element.innerText;
|
|
|
|
});
|
2020-08-27 11:53:24 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const actualDate = computed((): string => {
|
|
|
|
if (
|
|
|
|
props.discussion.updatedAt === props.discussion.insertedAt &&
|
|
|
|
props.discussion.lastComment?.publishedAt
|
|
|
|
) {
|
|
|
|
return props.discussion.lastComment.publishedAt;
|
2020-08-27 11:53:24 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return props.discussion.updatedAt;
|
|
|
|
});
|
2020-02-18 08:57:00 +01:00
|
|
|
</script>
|