Piped/src/components/Comment.vue

112 lines
4.1 KiB
Vue
Raw Normal View History

2021-07-21 10:19:51 +00:00
<template>
2021-12-27 14:46:26 +00:00
<div class="comment flex">
<img
:src="comment.thumbnail"
2021-12-27 14:46:26 +00:00
class="comment-avatar rounded-full uk-margin-right"
2021-11-01 20:23:04 +00:00
height="48"
width="48"
2021-10-28 17:55:20 +00:00
style="width: 48px; height: 48px"
loading="lazy"
alt="Avatar"
/>
2021-07-21 10:19:51 +00:00
<div class="comment-content">
<div class="comment-header">
<div v-if="comment.pinned" class="comment-pinned uk-text-meta">
<font-awesome-icon icon="thumbtack"></font-awesome-icon>&nbsp; {{ $t("comment.pinned_by") }}
{{ uploader }}
</div>
2021-07-21 10:19:51 +00:00
<div class="comment-author">
2021-12-27 14:46:26 +00:00
<router-link class="font-bold uk-text-small" :to="comment.commentorUrl">
{{ comment.author }} </router-link
>&thinsp;<font-awesome-icon v-if="comment.verified" icon="check"></font-awesome-icon>
</div>
<div class="comment-meta uk-text-meta uk-margin-small-bottom">
{{ comment.commentedTime }}
</div>
</div>
<div class="comment-body" style="white-space: pre-wrap">
{{ comment.commentText }}
</div>
<div class="comment-footer uk-margin-small-top uk-text-meta">
2021-10-28 17:55:20 +00:00
<font-awesome-icon icon="thumbs-up" style="margin-right: 4px"></font-awesome-icon>
<span>{{ numberFormat(comment.likeCount) }}</span>
&nbsp;
<font-awesome-icon v-if="comment.hearted" icon="heart"></font-awesome-icon>
</div>
<template v-if="comment.repliesPage && (!loadingReplies || !showingReplies)">
2021-11-01 20:23:04 +00:00
<div @click="loadReplies">
<a class="uk-link-text" v-t="'actions.show_replies'" />
2021-11-01 20:23:04 +00:00
&nbsp;
<font-awesome-icon icon="level-down-alt" />
2021-11-01 20:23:04 +00:00
</div>
</template>
<template v-if="showingReplies">
<div @click="hideReplies">
<a class="uk-link-text" v-t="'actions.hide_replies'" />
&nbsp;
<font-awesome-icon icon="level-up-alt" />
</div>
</template>
<div v-show="showingReplies" v-if="replies" class="replies uk-width-4-5@xl uk-width-3-4@s uk-width-1">
2021-11-01 20:23:04 +00:00
<div
v-for="reply in replies"
:key="reply.commentId"
class="uk-tile-default uk-align-left uk-width-expand"
>
<Comment :comment="reply" :uploader="uploader" :video-id="videoId" />
</div>
<div v-if="nextpage" @click="loadReplies">
<a class="uk-link-text" v-t="'actions.load_more_replies'" />
2021-11-01 20:23:04 +00:00
&nbsp;
<font-awesome-icon 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>
export default {
2021-07-21 10:19:51 +00:00
props: {
comment: {
type: Object,
default: () => {
return {};
},
},
uploader: { 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() {
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>