refactor(favorites): replace localStorage with centralized favorite store
This commit is contained in:
+11
-9
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user