修正按讚、儀表板彙總 BUG

This commit is contained in:
2025-09-23 17:16:52 +08:00
parent 36b3e45499
commit 6f3b56d494
6 changed files with 446 additions and 152 deletions

View File

@@ -63,23 +63,22 @@ export function LikeButton({ appId, size = "default", className, showCount = tru
setIsLoading(true)
// 立即更新本地狀態
const newLikedState = !hasLiked
const newLikeCount = hasLiked ? likeCount - 1 : likeCount + 1
setLocalUserLiked(newLikedState)
setLocalLikeCount(newLikeCount)
try {
const success = await toggleLike(appId)
const newLikedState = await toggleLike(appId)
// 更新本地狀態(基於 API 返回的結果)
setLocalUserLiked(newLikedState)
if (newLikedState) {
// 剛剛按讚了
setLocalLikeCount(prev => prev + 1)
toast({
title: "按讚成功!",
description: "感謝您的支持",
})
} else {
// 剛剛取消按讚了
setLocalLikeCount(prev => Math.max(prev - 1, 0))
toast({
title: "取消按讚",
description: "已取消對該應用的按讚",
@@ -87,9 +86,6 @@ export function LikeButton({ appId, size = "default", className, showCount = tru
}
} catch (error) {
console.error("按讚操作失敗:", error)
// 如果操作失敗,回滾本地狀態
setLocalUserLiked(hasLiked)
setLocalLikeCount(likeCount)
toast({
title: "操作失敗",
description: "請稍後再試",