Piped/src/components/CommentItem.vue

110 lines
4.2 KiB
Vue
Raw Normal View History

2021-07-21 10:19:51 +00:00
<template>
<div class="comment mt-1.5 flex">
<img
:src="comment.thumbnail"
class="comment-avatar h-12 w-12 rounded-full"
2021-11-01 20:23:04 +00:00
height="48"
width="48"
loading="lazy"
alt="Avatar"
/>
2021-07-21 10:19:51 +00:00
2021-12-27 14:46:36 +00:00
<div class="comment-content pl-2">
<div class="comment-header">
<div v-if="comment.pinned" class="comment-pinned">
2021-12-27 22:33:55 +00:00
<font-awesome-icon icon="thumbtack" />
<span
v-t="{
path: 'comment.pinned_by',
args: { author: uploader },
}"
2023-07-27 11:46:05 +00:00
class="ml-1.5"
/>
</div>
2021-07-21 10:19:51 +00:00
<div class="comment-author">
<router-link class="link font-bold" :to="comment.commentorUrl">{{ comment.author }}</router-link>
2023-07-27 11:46:05 +00:00
<font-awesome-icon v-if="comment.verified" class="ml-1.5" icon="check" />
</div>
<div class="comment-meta mb-1.5 text-sm" v-text="comment.commentedTime" />
</div>
2023-07-27 11:46:05 +00:00
<!-- eslint-disable-next-line vue/no-v-html -->
2023-09-11 17:13:05 +00:00
<CollapsableText :text="comment.commentText" :visible-limit="500" />
<div class="comment-footer my-1 flex items-center gap-3">
2023-05-09 10:25:01 +00:00
<div class="i-fa6-solid:thumbs-up" />
<span v-text="numberFormat(comment.likeCount)" />
<font-awesome-icon v-if="comment.hearted" icon="heart" />
<img v-if="comment.creatorReplied" :src="uploaderAvatarUrl" class="w-5 h-5 rounded-full" />
</div>
<template v-if="comment.repliesPage && (!loadingReplies || !showingReplies)">
2023-07-27 11:46:05 +00:00
<div class="cursor-pointer" @click="loadReplies">
2022-10-17 16:13:43 +00:00
<a v-text="`${$t('actions.reply_count', comment.replyCount)}`" />
<font-awesome-icon class="ml-1.5" icon="level-down-alt" />
2021-11-01 20:23:04 +00:00
</div>
</template>
<template v-if="showingReplies">
2023-07-27 11:46:05 +00:00
<div class="cursor-pointer" @click="hideReplies">
<a v-t="'actions.hide_replies'" />
<font-awesome-icon class="ml-1.5" icon="level-up-alt" />
</div>
</template>
2021-12-27 14:46:36 +00:00
<div v-show="showingReplies" v-if="replies" class="replies">
<div v-for="reply in replies" :key="reply.commentId" class="w-full">
<CommentItem :comment="reply" :uploader="uploader" :video-id="videoId" />
2021-11-01 20:23:04 +00:00
</div>
2023-07-27 11:46:05 +00:00
<div v-if="nextpage" class="cursor-pointer" @click="loadReplies">
<a v-t="'actions.load_more_replies'" />
<font-awesome-icon class="ml-1.5" icon="level-down-alt" />
2021-11-01 20:23:04 +00:00
</div>
</div>
2021-07-21 10:19:51 +00:00
</div>
</div>
</template>
<script>
2023-09-11 17:13:05 +00:00
import CollapsableText from "./CollapsableText.vue";
2023-07-22 16:22:57 +00:00
export default {
2023-09-11 17:13:05 +00:00
components: { CollapsableText },
2021-07-21 10:19:51 +00:00
props: {
comment: {
type: Object,
default: () => {
return {};
},
},
uploader: { type: String, default: null },
uploaderAvatarUrl: { type: String, default: null },
2021-11-01 20:23:04 +00:00
videoId: { type: String, default: null },
},
data() {
return {
loadingReplies: false,
showingReplies: false,
2021-11-01 20:23:04 +00:00
replies: [],
nextpage: null,
};
},
methods: {
async loadReplies() {
console.log(this.uploaderAvatarUrl);
if (!this.showingReplies && this.loadingReplies) {
this.showingReplies = true;
return;
}
this.loadingReplies = true;
this.showingReplies = true;
2021-11-01 20:23:04 +00:00
this.fetchJson(this.apiUrl() + "/nextpage/comments/" + this.videoId, {
nextpage: this.nextpage || this.comment.repliesPage,
}).then(json => {
this.replies = this.replies.concat(json.comments);
this.nextpage = json.nextpage;
});
},
async hideReplies() {
this.showingReplies = false;
},
},
};
</script>