refactor(data): add mock API adapters, id utility, and toast feedback
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { useChatStore } from "@/store/chat"
|
||||
|
||||
export function listChatSessions() {
|
||||
return useChatStore.getState().sessions
|
||||
}
|
||||
|
||||
export function getChatSessionById(sessionId: string) {
|
||||
return useChatStore.getState().sessions.find((session) => session.id === sessionId)
|
||||
}
|
||||
|
||||
export function listChatMessages(sessionId: string) {
|
||||
return useChatStore.getState().messages.filter((message) => message.sessionId === sessionId)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { mockComments } from "@/lib/mock"
|
||||
|
||||
export function listComments() {
|
||||
return mockComments
|
||||
}
|
||||
|
||||
export function listCommentsByPost(postId: string) {
|
||||
return mockComments.filter((comment) => comment.postId === postId)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { mockDisputes } from "@/lib/mock"
|
||||
|
||||
export function listDisputes() {
|
||||
return mockDisputes
|
||||
}
|
||||
|
||||
export function getDisputeByOrderId(orderId: string) {
|
||||
return mockDisputes.find((dispute) => dispute.orderId === orderId)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { mockFavorites } from "@/lib/mock"
|
||||
|
||||
export function listFavorites() {
|
||||
return mockFavorites
|
||||
}
|
||||
|
||||
export function listFavoritesByUser(userId: string) {
|
||||
return mockFavorites.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,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { mockGames } from "@/lib/mock"
|
||||
|
||||
export function listGames() {
|
||||
return mockGames
|
||||
}
|
||||
|
||||
export function getGameById(gameId: string) {
|
||||
return mockGames.find((game) => game.id === gameId)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export { getChatSessionById, listChatMessages, listChatSessions } from "./chat"
|
||||
export { listComments, listCommentsByPost } from "./comments"
|
||||
export { getDisputeByOrderId, listDisputes } from "./disputes"
|
||||
export { isFavorited, listFavorites, listFavoritesByUser } from "./favorites"
|
||||
export { getGameById, listGames } from "./games"
|
||||
export { listNotifications } from "./notifications"
|
||||
export { getOrderById, listOrders, listOrdersByConsumer } from "./orders"
|
||||
export { getPlayerById, listPlayers, listPlayersByShop } from "./players"
|
||||
export { getPostById, listPosts, listPostsByAuthor } from "./posts"
|
||||
export { listReviews, listReviewsByOrder, listReviewsByTargetUser } from "./reviews"
|
||||
export { getServiceById, listServices, listServicesByPlayer } from "./services"
|
||||
export { getShopById, getShopByOwnerId, listShops } from "./shops"
|
||||
export { listTransactions } from "./transactions"
|
||||
export { getCurrentUserForLogin, getUserById, listUsers } from "./users"
|
||||
@@ -0,0 +1,5 @@
|
||||
import { useNotificationStore } from "@/store/notifications"
|
||||
|
||||
export function listNotifications() {
|
||||
return useNotificationStore.getState().notifications
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useOrderStore } from "@/store/orders"
|
||||
|
||||
export function listOrders() {
|
||||
return useOrderStore.getState().orders
|
||||
}
|
||||
|
||||
export function getOrderById(orderId: string) {
|
||||
return useOrderStore.getState().orders.find((order) => order.id === orderId)
|
||||
}
|
||||
|
||||
export function listOrdersByConsumer(consumerId: string) {
|
||||
return useOrderStore.getState().orders.filter((order) => order.consumerId === consumerId)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { usePlayerStore } from "@/store/players"
|
||||
|
||||
export function listPlayers() {
|
||||
return usePlayerStore.getState().players
|
||||
}
|
||||
|
||||
export function getPlayerById(playerId: string) {
|
||||
return usePlayerStore.getState().players.find((player) => player.id === playerId)
|
||||
}
|
||||
|
||||
export function listPlayersByShop(shopId: string) {
|
||||
return usePlayerStore.getState().players.filter((player) => player.shopId === shopId)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { mockPosts } from "@/lib/mock"
|
||||
|
||||
export function listPosts() {
|
||||
return mockPosts
|
||||
}
|
||||
|
||||
export function getPostById(postId: string) {
|
||||
return mockPosts.find((post) => post.id === postId)
|
||||
}
|
||||
|
||||
export function listPostsByAuthor(userId: string) {
|
||||
return mockPosts.filter((post) => post.author.id === userId)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { mockReviews } from "@/lib/mock"
|
||||
|
||||
export function listReviews() {
|
||||
return mockReviews
|
||||
}
|
||||
|
||||
export function listReviewsByOrder(orderId: string) {
|
||||
return mockReviews.filter((review) => review.orderId === orderId)
|
||||
}
|
||||
|
||||
export function listReviewsByTargetUser(userId: string) {
|
||||
return mockReviews.filter((review) => review.toUserId === userId)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useServiceStore } from "@/store/services"
|
||||
|
||||
export function listServices() {
|
||||
return useServiceStore.getState().services
|
||||
}
|
||||
|
||||
export function getServiceById(serviceId: string) {
|
||||
return useServiceStore.getState().services.find((service) => service.id === serviceId)
|
||||
}
|
||||
|
||||
export function listServicesByPlayer(playerId: string) {
|
||||
return useServiceStore.getState().services.filter((service) => service.playerId === playerId)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useShopStore } from "@/store/shops"
|
||||
|
||||
export function listShops() {
|
||||
return useShopStore.getState().shops
|
||||
}
|
||||
|
||||
export function getShopById(shopId: string) {
|
||||
return useShopStore.getState().shops.find((shop) => shop.id === shopId)
|
||||
}
|
||||
|
||||
export function getShopByOwnerId(ownerId: string) {
|
||||
return useShopStore.getState().shops.find((shop) => shop.owner.id === ownerId)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { mockTransactions } from "@/lib/mock"
|
||||
|
||||
export function listTransactions() {
|
||||
return mockTransactions
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { currentUser, mockUsers } from "@/lib/mock"
|
||||
|
||||
export function listUsers() {
|
||||
return mockUsers
|
||||
}
|
||||
|
||||
export function getUserById(userId: string) {
|
||||
return mockUsers.find((user) => user.id === userId)
|
||||
}
|
||||
|
||||
export function getCurrentUserForLogin() {
|
||||
return currentUser
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
let counter = 0
|
||||
|
||||
export function generateId(prefix: string) {
|
||||
counter += 1
|
||||
return `${prefix}-${Date.now()}-${counter}`
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { toast } from "sonner"
|
||||
|
||||
export function notifySuccess(message: string) {
|
||||
toast.success(message)
|
||||
}
|
||||
|
||||
export function notifyInfo(message: string) {
|
||||
toast(message)
|
||||
}
|
||||
Reference in New Issue
Block a user