Skip to content

Commit

Permalink
fix: toggle collapse the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish committed Mar 8, 2024
1 parent 109dd44 commit be98c76
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
13 changes: 8 additions & 5 deletions packages/ui/src/post/Action.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import type { Post } from '@types'
defineProps<{
post: Post
}>()
defineEmits<{
toggleComment: []
}>()
</script>

<template>
Expand All @@ -13,15 +17,14 @@ defineProps<{
<span>{{ post.reposts_count }}</span>
</span>

<a
:href="`${post.detail_url}#comment`"
target="_blank"
title="打开原微博评论"
<span
title="展开微博评论"
class="text-gray"
@click="() => $emit('toggleComment')"
>
<span class="i-tabler-message icon" />
<span>{{ post.comments_count }}</span>
</a>
</span>

<span>
<span class="i-tabler-heart icon" />
Expand Down
54 changes: 26 additions & 28 deletions packages/ui/src/post/Comments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,36 @@ defineProps<{
</script>

<template>
<div class="comments flex flex-col pl-2">
<article
v-for="comment in comments"
:key="comment.id"
class="flex flex-col gap-2 rounded-2 bg-white p-3 pl-10 dark:bg-dark"
>
<div class="flex">
<post-profile
:user="comment.user"
class="ml-[-2.5rem] mr-4!"
/>
<div
v-for="comment in comments"
:key="comment.id"
class="comments flex flex-col gap-2 rounded-2 bg-white p-3 pl-10 dark:bg-dark"
>
<div class="flex">
<post-profile
:user="comment.user"
class="ml-[-2.5rem] mr-4!"
/>

<div class="flex items-center gap-3 text-3 text-gray">
<post-meta
:meta="comment"
class="justify-start!"
/>
<span class="hidden sm:inline-block">
评论 {{ comment.comments_count }} |
点赞 {{ comment.like_count }}
</span>
</div>
<div class="flex items-center gap-3 text-3 text-gray">
<post-meta
:meta="comment"
class="justify-start!"
/>
<span class="hidden sm:inline-block">
评论 {{ comment.comments_count }} |
点赞 {{ comment.like_count }}
</span>
</div>
</div>

<post-text :text="comment.text" />
<post-text :text="comment.text" />

<main-image
v-if="comment.img && !comment.img.includes('sinaurl')"
:src="comment.img"
class="max-h-10rem"
/>
</article>
<main-image
v-if="comment.img && !comment.img.includes('sinaurl')"
:src="comment.img"
class="h-10rem"
/>
</div>
</template>

Expand Down
28 changes: 24 additions & 4 deletions packages/ui/src/post/Item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ import type { Post } from '@types'
defineProps<{
post: Post
}>()
const openComment = ref(false)
const articleRef = ref<HTMLElement | null>(null)
watchEffect(() => {
if (!articleRef.value)
return
const comments = articleRef.value.querySelector<HTMLDivElement>('.n-collapse-item__content-wrapper')
comments?.style.setProperty('display', openComment.value ? 'block' : 'none')
})
</script>

<template>
<article
:id="post.mblogid"
ref="articleRef"
class="post"
>
<div class="flex justify-between">
Expand Down Expand Up @@ -37,12 +49,20 @@ defineProps<{
<post-action
class="justify-start!"
:post="post"
@toggle-comment="openComment = !openComment"
/>

<post-comments
v-if="post.comments_count > 0"
:comments="post.comments"
/>
<n-collapse
:default-expanded-names="['comments']"
display-directive="show"
>
<template #arrow>
<span />
</template>
<n-collapse-item name="comments">
<post-comments :comments="post.comments" />
</n-collapse-item>
</n-collapse>
</article>
</template>

Expand Down

0 comments on commit be98c76

Please sign in to comment.