Skip to content

Commit e00abe9

Browse files
committed
feat: feeds add stat
1 parent e7cf95a commit e00abe9

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

src/views/feeds.tsx

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ export function Feeds() {
7373

7474
toLatest: () => {
7575
setLastKeys([])
76-
setLastKey(undefined)
76+
if (lastKey) setLastKey(undefined)
77+
else
78+
setLastKey(() => {
79+
fetchFeeds()
80+
return undefined
81+
})
7782
},
7883
}
7984

@@ -195,73 +200,79 @@ const UserInteract = ({
195200
)
196201

197202
const OriginalPost = ({ post }: { post: JikePostWithDetail }) => {
198-
const [liked, setLiked] = useState(post.detail.liked)
203+
const [detail, setDetail] = useState(post.detail)
199204
const markdown = useMemo(
200-
() => `${post.detail.content
205+
() => `${detail.content
201206
.replaceAll('\n', '\n\n')
202207
.replaceAll(/([!#()*+.[\\\]_`{}-])/g, `\\$1`)}
203208
204-
${post.detail.pictures
209+
${detail.pictures
205210
?.map((picture: Entity.Picture) => `![图片](${picture.middlePicUrl})`)
206211
.join('\n\n')}`,
207-
[post.detail.content, post.detail.pictures]
212+
[detail.content, detail.pictures]
208213
)
209214

210-
const onLike = async () => {
211-
try {
212-
await post.like()
213-
refreshLiked()
214-
return true
215-
} catch (err) {
216-
handleError(err)
217-
return false
218-
}
219-
}
220-
221-
const onUnlike = async () => {
215+
const onAction = (action: 'like' | 'unlike') => async () => {
222216
try {
223-
await post.unlike()
224-
refreshLiked()
217+
let { likeCount } = detail
218+
if (action === 'like') {
219+
await post.like()
220+
likeCount++
221+
} else {
222+
await post.unlike()
223+
likeCount--
224+
}
225+
setDetail({
226+
...detail,
227+
liked: action === 'like',
228+
likeCount,
229+
})
225230
return true
226231
} catch (err) {
227232
handleError(err)
228233
return false
229234
}
230235
}
231236

232-
const refreshLiked = () => setLiked(post.detail.liked)
233-
234237
return (
235238
<List.Item
236-
icon={pictureWithCircle(post.detail.user.avatarImage.thumbnailUrl)}
237-
title={post.detail.user.screenName}
238-
subtitle={post.detail.content}
239+
icon={pictureWithCircle(detail.user.avatarImage.thumbnailUrl)}
240+
title={detail.user.screenName}
241+
subtitle={detail.content}
239242
actions={
240243
<ActionPanel>
241-
{liked ? (
242-
<UnlikePost onAction={onUnlike} />
244+
{detail.liked ? (
245+
<UnlikePost onAction={onAction('unlike')} />
243246
) : (
244-
<LikePost onAction={onLike} />
247+
<LikePost onAction={onAction('like')} />
245248
)}
246249
<OpenPost type={ApiOptions.PostType.ORIGINAL} id={post.id} />
247250
<Pager />
248-
<CopyUpdate object={post.detail} />
251+
<CopyUpdate object={detail} />
249252
</ActionPanel>
250253
}
251254
detail={
252255
<List.Item.Detail
253256
markdown={markdown}
254257
metadata={
255258
<List.Item.Detail.Metadata>
256-
{post.detail.topic && (
259+
{detail.topic && (
257260
<List.Item.Detail.Metadata.Label
258261
title="圈子"
259262
icon={pictureWithCircle(
260-
post.detail.topic.squarePicture.thumbnailUrl
263+
detail.topic.squarePicture.thumbnailUrl
261264
)}
262-
text={post.detail.topic.content}
265+
text={detail.topic.content}
263266
/>
264267
)}
268+
<List.Item.Detail.Metadata.Label
269+
title="点赞 / 评论"
270+
text={`👍 ${detail.likeCount} / 💬 ${detail.commentCount}`}
271+
/>
272+
<List.Item.Detail.Metadata.Label
273+
title="转帖 / 分享"
274+
text={`↪️ ${detail.repostCount} / 🚀 ${detail.shareCount}`}
275+
/>
265276
</List.Item.Detail.Metadata>
266277
}
267278
/>

0 commit comments

Comments
 (0)