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); +});