Simplify the logic for content with and without comments
This commit is contained in:
@@ -71,7 +71,7 @@
|
|||||||
<v-icon>mdi-thumb-down-outline</v-icon>
|
<v-icon>mdi-thumb-down-outline</v-icon>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
<v-btn
|
<v-btn
|
||||||
:class="{'comment-active': hasComments}"
|
:class="{'comment-active': hasMessages}"
|
||||||
variant="plain"
|
variant="plain"
|
||||||
icon
|
icon
|
||||||
@click="toggleComments">
|
@click="toggleComments">
|
||||||
@@ -82,12 +82,11 @@
|
|||||||
<donation-button :creator="creator" iconColorClass="text-black"></donation-button>
|
<donation-button :creator="creator" iconColorClass="text-black"></donation-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div :class="{'hidden': !commentsVisible}">
|
<div :class="{'hidden': !messagesVisible}">
|
||||||
<h2 class="font-sans font-semibold mt-2">Commentaires</h2>
|
<h2 class="font-sans font-semibold mt-2">Commentaires</h2>
|
||||||
<message-list
|
<message-list
|
||||||
:subject-id="props.content.id"
|
:subject-id="props.content.id"
|
||||||
:messages="messages"
|
:messages="messages"
|
||||||
@messages-found="handleMessagesFound"
|
|
||||||
></message-list>
|
></message-list>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -100,10 +99,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, ref, onBeforeMount } from 'vue';
|
import {computed, ref} from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import {time_ago} from "@/internal_time_ago.js";
|
||||||
import { useClient } from "@/plugins/api.js";
|
|
||||||
import { time_ago } from "@/internal_time_ago.js";
|
|
||||||
import MessageList from "@/views/messages/MessageList.vue";
|
import MessageList from "@/views/messages/MessageList.vue";
|
||||||
import PostMessage from "@/views/messages/PostMessage.vue";
|
import PostMessage from "@/views/messages/PostMessage.vue";
|
||||||
import YoutubePlayer from './YoutubePlayer.vue';
|
import YoutubePlayer from './YoutubePlayer.vue';
|
||||||
@@ -117,44 +114,20 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const route = useRoute();
|
|
||||||
const client = useClient();
|
|
||||||
const creatorAlias = ref(route.params.creator);
|
|
||||||
const creator = ref(null);
|
const creator = ref(null);
|
||||||
const loading = ref(true);
|
|
||||||
|
|
||||||
const hasUrls = computed(() => !!props.content.urls && props.content.urls.length > 0);
|
const hasUrls = computed(() => !!props.content.urls && props.content.urls.length > 0);
|
||||||
const commentsVisible = ref(false);
|
const messagesVisible = ref(false);
|
||||||
const messages = ref([]);
|
const messages = ref([]);
|
||||||
const hasComments = ref(false);
|
const hasMessages = computed(() => messages.value.length > 0)
|
||||||
|
|
||||||
onBeforeMount(async () => await fetchCreatorData(creatorAlias.value))
|
|
||||||
|
|
||||||
async function fetchCreatorData(creatorAlias) {
|
|
||||||
try {
|
|
||||||
loading.value = true;
|
|
||||||
const response = await client.get(`/api/creators/@${creatorAlias}`);
|
|
||||||
creator.value = response.data;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error fetching creator data: ${error}`);
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleMessagesFound(hasMessages) {
|
|
||||||
if (hasMessages) {
|
|
||||||
hasComments.value = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addMessage(newMessage) {
|
function addMessage(newMessage) {
|
||||||
messages.value.unshift(newMessage);
|
messages.value.unshift(newMessage);
|
||||||
commentsVisible.value = true;
|
messagesVisible.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleComments() {
|
function toggleComments() {
|
||||||
commentsVisible.value = !commentsVisible.value;
|
messagesVisible.value = !messagesVisible.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function likeContent() {
|
function likeContent() {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import { ref, onBeforeMount } from 'vue';
|
|||||||
import { useClient } from '@/plugins/api.js';
|
import { useClient } from '@/plugins/api.js';
|
||||||
import Message from "@/views/messages/Message.vue";
|
import Message from "@/views/messages/Message.vue";
|
||||||
|
|
||||||
const emit = defineEmits(['messages-found']);
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
subjectId: {
|
subjectId: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -71,10 +70,6 @@ async function load({ done, page_size = 10 }) {
|
|||||||
messages.value.push(...response.data.messages);
|
messages.value.push(...response.data.messages);
|
||||||
const [last_content] = response.data.messages.slice(-1);
|
const [last_content] = response.data.messages.slice(-1);
|
||||||
last_id = last_content.id;
|
last_id = last_content.id;
|
||||||
|
|
||||||
if (messageCount > 0) {
|
|
||||||
emit('messages-found', true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messageCount < page_size) {
|
if (messageCount < page_size) {
|
||||||
|
|||||||
Reference in New Issue
Block a user