@@ -73,7 +73,12 @@ export function Feeds() {
73
73
74
74
toLatest : ( ) => {
75
75
setLastKeys ( [ ] )
76
- setLastKey ( undefined )
76
+ if ( lastKey ) setLastKey ( undefined )
77
+ else
78
+ setLastKey ( ( ) => {
79
+ fetchFeeds ( )
80
+ return undefined
81
+ } )
77
82
} ,
78
83
}
79
84
@@ -195,73 +200,79 @@ const UserInteract = ({
195
200
)
196
201
197
202
const OriginalPost = ( { post } : { post : JikePostWithDetail } ) => {
198
- const [ liked , setLiked ] = useState ( post . detail . liked )
203
+ const [ detail , setDetail ] = useState ( post . detail )
199
204
const markdown = useMemo (
200
- ( ) => `${ post . detail . content
205
+ ( ) => `${ detail . content
201
206
. replaceAll ( '\n' , '\n\n' )
202
207
. replaceAll ( / ( [ ! # ( ) * + . [ \\ \] _ ` { } - ] ) / g, `\\$1` ) }
203
208
204
- ${ post . detail . pictures
209
+ ${ detail . pictures
205
210
?. map ( ( picture : Entity . Picture ) => `` )
206
211
. join ( '\n\n' ) } `,
207
- [ post . detail . content , post . detail . pictures ]
212
+ [ detail . content , detail . pictures ]
208
213
)
209
214
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 ( ) => {
222
216
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
+ } )
225
230
return true
226
231
} catch ( err ) {
227
232
handleError ( err )
228
233
return false
229
234
}
230
235
}
231
236
232
- const refreshLiked = ( ) => setLiked ( post . detail . liked )
233
-
234
237
return (
235
238
< 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 }
239
242
actions = {
240
243
< ActionPanel >
241
- { liked ? (
242
- < UnlikePost onAction = { onUnlike } />
244
+ { detail . liked ? (
245
+ < UnlikePost onAction = { onAction ( 'unlike' ) } />
243
246
) : (
244
- < LikePost onAction = { onLike } />
247
+ < LikePost onAction = { onAction ( 'like' ) } />
245
248
) }
246
249
< OpenPost type = { ApiOptions . PostType . ORIGINAL } id = { post . id } />
247
250
< Pager />
248
- < CopyUpdate object = { post . detail } />
251
+ < CopyUpdate object = { detail } />
249
252
</ ActionPanel >
250
253
}
251
254
detail = {
252
255
< List . Item . Detail
253
256
markdown = { markdown }
254
257
metadata = {
255
258
< List . Item . Detail . Metadata >
256
- { post . detail . topic && (
259
+ { detail . topic && (
257
260
< List . Item . Detail . Metadata . Label
258
261
title = "圈子"
259
262
icon = { pictureWithCircle (
260
- post . detail . topic . squarePicture . thumbnailUrl
263
+ detail . topic . squarePicture . thumbnailUrl
261
264
) }
262
- text = { post . detail . topic . content }
265
+ text = { detail . topic . content }
263
266
/>
264
267
) }
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
+ />
265
276
</ List . Item . Detail . Metadata >
266
277
}
267
278
/>
0 commit comments