refactor(favorites): replace localStorage with centralized favorite store

This commit is contained in:
zetaloop
2026-02-22 08:29:37 +08:00
parent 8ce3b8a8b5
commit 237cf90f5e
3 changed files with 72 additions and 34 deletions
+11 -9
View File
@@ -1,18 +1,20 @@
import { mockFavorites } from "@/lib/mock"
import { useFavoriteStore } from "@/store/favorites"
export function listFavorites() {
return mockFavorites
return useFavoriteStore.getState().favorites
}
export function listFavoritesByUser(userId: string) {
return mockFavorites.filter((favorite) => favorite.userId === userId)
return useFavoriteStore.getState().favorites.filter((favorite) => favorite.userId === userId)
}
export function isFavorited(userId: string, targetType: "player" | "shop", targetId: string) {
return mockFavorites.some(
(favorite) =>
favorite.userId === userId &&
favorite.targetType === targetType &&
favorite.targetId === targetId,
)
return useFavoriteStore
.getState()
.favorites.some(
(favorite) =>
favorite.userId === userId &&
favorite.targetType === targetType &&
favorite.targetId === targetId,
)
}