From a71d40987e11d4dc947995f56779ee0e83bcf4d0 Mon Sep 17 00:00:00 2001 From: marzban-dev Date: Wed, 16 Apr 2025 22:13:05 +0330 Subject: [PATCH] Make comments collapsable --- .../components/product/ProductComments.vue | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/frontend/components/product/ProductComments.vue b/frontend/components/product/ProductComments.vue index ebb75f5..a7f6627 100644 --- a/frontend/components/product/ProductComments.vue +++ b/frontend/components/product/ProductComments.vue @@ -15,16 +15,17 @@ const page = ref(1); const { token } = useAuth(); const userComment = ref(""); +const showMoreComments = ref(false); + const { data: comments, refetch: refetchComments } = useGetComments(id, page); -const { mutateAsync: createComment, isPending: isCreateCommentPending } = - useCreateComment(id); +const { mutateAsync: createComment, isPending: isCreateCommentPending } = useCreateComment(id); // methods const submitComment = async () => { if (userComment.value.length > 3) { await createComment({ - content: userComment.value + content: userComment.value, }); userComment.value = ""; @@ -32,6 +33,16 @@ const submitComment = async () => { await refetchComments(); } }; + +// computed + +const limitedComments = computed(() => { + if (showMoreComments.value) { + return comments.value!.results; + } + + return comments.value!.results.slice(0, 3); +});