2020-02-18 08:57:00 +01:00
|
|
|
<template>
|
|
|
|
<article class="comment">
|
|
|
|
<div class="avatar">
|
|
|
|
<figure class="image is-48x48" v-if="comment.actor.avatar">
|
|
|
|
<img class="is-rounded" :src="comment.actor.avatar.url" alt="" />
|
|
|
|
</figure>
|
2020-08-19 09:01:34 +02:00
|
|
|
<b-icon v-else size="is-large" icon="account-circle" />
|
2020-02-18 08:57:00 +01:00
|
|
|
</div>
|
|
|
|
<div class="body">
|
|
|
|
<div class="meta">
|
2020-08-14 11:32:23 +02:00
|
|
|
<span class="first-line name" v-if="!comment.deletedAt">
|
|
|
|
<strong>{{ comment.actor.name }}</strong>
|
|
|
|
<small>@{{ usernameWithDomain(comment.actor) }}</small>
|
|
|
|
</span>
|
2020-08-19 09:01:34 +02:00
|
|
|
<span v-else class="name comment-link has-text-grey">
|
|
|
|
{{ $t("[deleted]") }}
|
|
|
|
</span>
|
2020-11-30 10:24:11 +01:00
|
|
|
<span
|
|
|
|
class="icons"
|
|
|
|
v-if="!comment.deletedAt && comment.actor.id === currentActor.id"
|
|
|
|
>
|
2020-08-14 11:32:23 +02:00
|
|
|
<b-dropdown aria-role="list">
|
|
|
|
<b-icon slot="trigger" role="button" icon="dots-horizontal" />
|
|
|
|
|
|
|
|
<b-dropdown-item
|
|
|
|
v-if="comment.actor.id === currentActor.id"
|
|
|
|
@click="toggleEditMode"
|
|
|
|
aria-role="menuitem"
|
|
|
|
>
|
|
|
|
<b-icon icon="pencil"></b-icon>
|
|
|
|
{{ $t("Edit") }}
|
|
|
|
</b-dropdown-item>
|
|
|
|
<b-dropdown-item
|
|
|
|
v-if="comment.actor.id === currentActor.id"
|
|
|
|
@click="$emit('delete-comment', comment)"
|
|
|
|
aria-role="menuitem"
|
|
|
|
>
|
|
|
|
<b-icon icon="delete"></b-icon>
|
|
|
|
{{ $t("Delete") }}
|
|
|
|
</b-dropdown-item>
|
2020-08-19 09:01:34 +02:00
|
|
|
<!-- <b-dropdown-item aria-role="listitem" @click="isReportModalActive = true">
|
2020-08-14 11:32:23 +02:00
|
|
|
<b-icon icon="flag" />
|
|
|
|
{{ $t("Report") }}
|
2020-08-19 09:01:34 +02:00
|
|
|
</b-dropdown-item> -->
|
2020-08-14 11:32:23 +02:00
|
|
|
</b-dropdown>
|
|
|
|
</span>
|
2020-02-18 08:57:00 +01:00
|
|
|
<div class="post-infos">
|
2020-08-19 09:01:34 +02:00
|
|
|
<span :title="comment.insertedAt | formatDateTimeString">
|
2020-10-13 20:39:59 +02:00
|
|
|
{{
|
2020-11-30 10:24:11 +01:00
|
|
|
formatDistanceToNow(new Date(comment.updatedAt), {
|
|
|
|
locale: $dateFnsLocale,
|
|
|
|
}) || $t("Right now")
|
2020-10-13 20:39:59 +02:00
|
|
|
}}</span
|
2020-07-09 17:24:28 +02:00
|
|
|
>
|
2020-02-18 08:57:00 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-19 09:01:34 +02:00
|
|
|
<div v-if="!editMode && !comment.deletedAt" class="text-wrapper">
|
|
|
|
<div class="description-content" v-html="comment.text"></div>
|
|
|
|
<p
|
2021-06-11 15:08:43 +02:00
|
|
|
v-if="
|
|
|
|
comment.insertedAt &&
|
|
|
|
comment.updatedAt &&
|
|
|
|
new Date(comment.insertedAt).getTime() !==
|
|
|
|
new Date(comment.updatedAt).getTime()
|
|
|
|
"
|
2020-08-19 09:01:34 +02:00
|
|
|
:title="comment.updatedAt | formatDateTimeString"
|
|
|
|
>
|
2020-10-13 20:39:59 +02:00
|
|
|
{{
|
|
|
|
$t("Edited {ago}", {
|
|
|
|
ago: formatDistanceToNow(new Date(comment.updatedAt), {
|
|
|
|
locale: $dateFnsLocale,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
}}
|
2020-08-19 09:01:34 +02:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div class="comment-deleted" v-else-if="!editMode">
|
|
|
|
{{ $t("[This comment has been deleted by it's author]") }}
|
|
|
|
</div>
|
2020-08-14 11:32:23 +02:00
|
|
|
<form v-else class="edition" @submit.prevent="updateComment">
|
|
|
|
<editor v-model="updatedComment" />
|
|
|
|
<div class="buttons">
|
|
|
|
<b-button
|
|
|
|
native-type="submit"
|
|
|
|
:disabled="['<p></p>', '', comment.text].includes(updatedComment)"
|
|
|
|
type="is-primary"
|
|
|
|
>{{ $t("Update") }}</b-button
|
|
|
|
>
|
2020-11-30 10:24:11 +01:00
|
|
|
<b-button native-type="button" @click="toggleEditMode">{{
|
|
|
|
$t("Cancel")
|
|
|
|
}}</b-button>
|
2020-08-14 11:32:23 +02:00
|
|
|
</div>
|
|
|
|
</form>
|
2020-02-18 08:57:00 +01:00
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
2020-10-13 20:39:59 +02:00
|
|
|
import { formatDistanceToNow } from "date-fns";
|
|
|
|
import { IComment } from "../../types/comment.model";
|
2020-08-14 11:32:23 +02:00
|
|
|
import { usernameWithDomain, IPerson } from "../../types/actor";
|
|
|
|
import { CURRENT_ACTOR_CLIENT } from "../../graphql/actor";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
apollo: {
|
|
|
|
currentActor: CURRENT_ACTOR_CLIENT,
|
|
|
|
},
|
|
|
|
components: {
|
2020-11-30 10:24:11 +01:00
|
|
|
editor: () =>
|
|
|
|
import(/* webpackChunkName: "editor" */ "@/components/Editor.vue"),
|
2020-08-14 11:32:23 +02:00
|
|
|
},
|
|
|
|
})
|
2020-07-09 17:24:28 +02:00
|
|
|
export default class DiscussionComment extends Vue {
|
2020-02-18 08:57:00 +01:00
|
|
|
@Prop({ required: true, type: Object }) comment!: IComment;
|
2020-08-14 11:32:23 +02:00
|
|
|
|
2020-08-31 12:40:30 +02:00
|
|
|
editMode = false;
|
|
|
|
|
|
|
|
updatedComment = "";
|
2020-08-14 11:32:23 +02:00
|
|
|
|
|
|
|
currentActor!: IPerson;
|
|
|
|
|
|
|
|
usernameWithDomain = usernameWithDomain;
|
|
|
|
|
2020-10-13 20:39:59 +02:00
|
|
|
formatDistanceToNow = formatDistanceToNow;
|
|
|
|
|
2020-08-19 09:01:34 +02:00
|
|
|
// isReportModalActive: boolean = false;
|
2020-08-14 11:32:23 +02:00
|
|
|
|
2020-10-13 20:39:59 +02:00
|
|
|
toggleEditMode(): void {
|
2020-08-14 11:32:23 +02:00
|
|
|
this.updatedComment = this.comment.text;
|
|
|
|
this.editMode = !this.editMode;
|
|
|
|
}
|
|
|
|
|
2020-10-13 20:39:59 +02:00
|
|
|
updateComment(): void {
|
2020-08-14 11:32:23 +02:00
|
|
|
this.comment.text = this.updatedComment;
|
|
|
|
this.$emit("update-comment", this.comment);
|
|
|
|
this.toggleEditMode();
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
article.comment {
|
|
|
|
display: flex;
|
|
|
|
border-top: 1px solid #e9e9e9;
|
|
|
|
|
|
|
|
div.body {
|
|
|
|
flex: 2;
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
padding-top: 1rem;
|
|
|
|
|
|
|
|
.meta {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: 0 1rem 0.3em;
|
|
|
|
|
|
|
|
.name {
|
|
|
|
margin-right: auto;
|
|
|
|
flex: 1 1 auto;
|
|
|
|
overflow: hidden;
|
|
|
|
|
2020-08-14 11:32:23 +02:00
|
|
|
strong {
|
|
|
|
display: block;
|
|
|
|
line-height: 1rem;
|
|
|
|
}
|
|
|
|
|
2020-08-19 09:01:34 +02:00
|
|
|
color: #3c376e;
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
2020-08-14 11:32:23 +02:00
|
|
|
|
|
|
|
.icons {
|
|
|
|
display: inline;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
|
2020-08-19 09:01:34 +02:00
|
|
|
.text-wrapper,
|
|
|
|
.comment-deleted {
|
|
|
|
padding: 0 1rem;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-08-19 09:01:34 +02:00
|
|
|
& > p {
|
|
|
|
font-size: 0.85rem;
|
|
|
|
font-style: italic;
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
|
2020-08-19 09:01:34 +02:00
|
|
|
div.description-content {
|
|
|
|
padding-bottom: 0.3rem;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-11-16 10:04:47 +01:00
|
|
|
::v-deep h1 {
|
2020-08-19 09:01:34 +02:00
|
|
|
font-size: 2rem;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-11-16 10:04:47 +01:00
|
|
|
::v-deep h2 {
|
2020-08-19 09:01:34 +02:00
|
|
|
font-size: 1.5rem;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-11-16 10:04:47 +01:00
|
|
|
::v-deep h3 {
|
2020-08-19 09:01:34 +02:00
|
|
|
font-size: 1.25rem;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-11-16 10:04:47 +01:00
|
|
|
::v-deep ul {
|
2020-08-19 09:01:34 +02:00
|
|
|
list-style-type: disc;
|
|
|
|
}
|
|
|
|
|
2020-11-16 10:04:47 +01:00
|
|
|
::v-deep li {
|
2020-08-19 09:01:34 +02:00
|
|
|
margin: 10px auto 10px 2rem;
|
|
|
|
}
|
|
|
|
|
2020-11-16 10:04:47 +01:00
|
|
|
::v-deep blockquote {
|
2020-08-19 09:01:34 +02:00
|
|
|
border-left: 0.2em solid #333;
|
|
|
|
display: block;
|
|
|
|
padding-left: 1em;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-11-16 10:04:47 +01:00
|
|
|
::v-deep p {
|
2020-08-19 09:01:34 +02:00
|
|
|
margin: 10px auto;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-08-19 09:01:34 +02:00
|
|
|
a {
|
|
|
|
display: inline-block;
|
|
|
|
padding: 0.3rem;
|
|
|
|
background: $secondary;
|
|
|
|
color: #111;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-08-19 09:01:34 +02:00
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
div.avatar {
|
|
|
|
padding-top: 1rem;
|
|
|
|
flex: 0;
|
|
|
|
}
|
2020-08-14 11:32:23 +02:00
|
|
|
|
|
|
|
.edition {
|
|
|
|
.button {
|
|
|
|
margin-top: 0.75rem;
|
|
|
|
}
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
</style>
|