0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-12-01 15:37:29 +00:00
VueTube/NUXT/components/Comments/mainCommentRenderer.vue

166 lines
4.8 KiB
Vue
Raw Normal View History

2022-04-19 14:03:46 +00:00
<template>
<dialog-base>
<template v-slot:header>
<v-toolbar-title>
<template v-for="text in commentData.headerText.runs">
<template v-if="text.bold">
<strong :key="text.text">{{ text.text }}</strong>
</template>
<template v-else>{{ text.text }}</template>
</template>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn icon @click="$emit('changeState', false)">
2022-04-19 14:03:46 +00:00
<v-icon>mdi-close</v-icon>
</v-btn>
</template>
2022-05-07 05:05:45 +00:00
<div
v-for="(comment, index) in comments"
:key="index"
class="commentElement"
>
<v-list-item class="px-0">
<component
:is="Object.keys(comment)[0]"
v-if="getComponents()[Object.keys(comment)[0]]"
:comment="comment[Object.keys(comment)[0]]"
2022-04-24 08:05:36 +00:00
@intersect="paginate"
2022-05-05 03:57:37 +00:00
@showReplies="openReply"
></component>
</v-list-item>
<v-divider v-if="getComponents()[Object.keys(comment)[0]]"></v-divider>
2022-05-07 05:05:45 +00:00
</div>
2022-05-05 03:57:37 +00:00
2022-12-27 16:44:51 +00:00
<div v-if="loading" class="loading">
<v-sheet
v-for="i in comments.length <= 0 ? 5 : 1"
:key="i"
color="background"
>
<v-skeleton-loader type="list-item-avatar-three-line" />
2022-04-19 14:03:46 +00:00
</v-sheet>
</div>
2022-05-05 03:57:37 +00:00
<template v-slot:reveal>
<main-comment-reply-renderer
v-if="showReply && replyData"
v-model="showReply"
:parentComment="replyData.parent"
:defaultContinuation="replyData.replyContinuation"
2022-05-05 05:32:02 +00:00
class="transition-fast-in-fast-out v-card--reveal"
style="height: 100%"
2022-12-27 16:44:51 +00:00
@closeComments="$emit('changeState', false)"
2022-05-05 03:57:37 +00:00
></main-comment-reply-renderer>
</template>
2022-04-19 14:03:46 +00:00
</dialog-base>
</template>
<script>
import dialogBase from "~/components/dialogBase.vue";
import commentThreadRenderer from "~/components/Comments/commentThreadRenderer.vue";
2022-12-27 16:44:51 +00:00
import commentsHeaderRenderer from "~/components/Comments/commentsHeaderRenderer.vue";
2022-05-05 03:57:37 +00:00
import mainCommentReplyRenderer from "~/components/Comments/mainCommentReplyRenderer.vue";
2022-12-27 16:44:51 +00:00
import continuationItemRenderer from "~/components/observer.vue";
2022-04-19 14:03:46 +00:00
import backType from "~/plugins/classes/backType";
2022-04-19 14:03:46 +00:00
export default {
components: {
dialogBase,
commentThreadRenderer,
2022-12-27 16:44:51 +00:00
commentsHeaderRenderer,
2022-05-05 03:57:37 +00:00
mainCommentReplyRenderer,
2022-12-27 16:44:51 +00:00
continuationItemRenderer,
2022-04-19 14:03:46 +00:00
},
2022-12-27 16:44:51 +00:00
model: {
prop: "showComments",
event: "changeState",
},
props: ["defaultContinuation", "commentData", "showComments"],
2022-04-19 14:03:46 +00:00
data: () => ({
loading: true,
comments: [],
continuation: null,
2022-05-05 03:57:37 +00:00
showReply: false,
replyData: {},
2022-04-19 14:03:46 +00:00
}),
mounted() {
if (!this.continuation) this.continuation = this.defaultContinuation;
2022-04-19 14:03:46 +00:00
this.paginate();
},
methods: {
getComponents() {
return this.$options.components;
},
paginate() {
if (this.continuation) {
this.loading = true;
const watcherIndex = this.comments.findIndex(
(comment) => comment.continuationItemRenderer
);
if (watcherIndex) this.comments.splice(watcherIndex, 1);
this.$youtube
.getContinuation(this.continuation, "next", "web")
.then((result) => {
let processed;
if (
result.data.onResponseReceivedEndpoints.find(
(endpoints) => endpoints.reloadContinuationItemsCommand
)
) {
processed = result.data.onResponseReceivedEndpoints.map(
(endpoints) =>
endpoints.reloadContinuationItemsCommand.continuationItems
);
} else {
processed = result.data.onResponseReceivedEndpoints.map(
(endpoints) =>
endpoints.appendContinuationItemsAction.continuationItems
);
}
processed = processed.flat(1);
this.comments = this.comments.concat(processed);
this.continuation = this.findContinuation(processed);
console.log("comments", this.comments);
if (this.comments) this.loading = false;
});
}
2022-04-19 14:03:46 +00:00
},
findContinuation(newResponses) {
const continuationItemParent = newResponses.find(
(item) => item.continuationItemRenderer
);
const newContinuation =
continuationItemParent?.continuationItemRenderer.continuationEndpoint
.continuationCommand.token;
return newContinuation;
},
2022-05-05 03:57:37 +00:00
openReply(event) {
this.showReply = true;
if (this.showReply) {
const dismissReply = new backType(
() => {
this.showReply = false;
},
() => {
return this.showReply;
}
);
this.$vuetube.addBackAction(dismissReply);
}
2022-05-05 03:57:37 +00:00
this.replyData = { parent: event, replyContinuation: null };
},
2022-04-19 14:03:46 +00:00
},
};
</script>