feat(catalog): fetch players, services, shops

This commit is contained in:
zetaloop
2026-02-28 16:37:15 +08:00
parent f4365668ab
commit f1ae3e04bb
11 changed files with 234 additions and 57 deletions
+7 -5
View File
@@ -6,16 +6,16 @@ import { Button } from "@/components/ui/button"
import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card"
import { listGames, listOrders, listPlayers, listPosts } from "@/lib/api"
import { roleLabels } from "@/lib/constants"
import type { Game } from "@/lib/types"
import type { Game, Player } from "@/lib/types"
import { ClipboardList, Heart, MessageCircle, PenSquare, Pin } from "lucide-react"
import Link from "next/link"
import { useEffect, useState } from "react"
export default function CommunityPage() {
const [games, setGames] = useState<Game[]>([])
const [players, setPlayers] = useState<Player[]>([])
const posts = listPosts()
const orders = listOrders()
const players = listPlayers()
const [sortMode, setSortMode] = useState<"latest" | "hot">("latest")
const [selectedGame, setSelectedGame] = useState<string | null>(null)
@@ -23,14 +23,16 @@ export default function CommunityPage() {
useEffect(() => {
let cancelled = false
listGames()
.then((items) => {
Promise.all([listGames(), listPlayers()])
.then(([gamesItems, playersItems]) => {
if (cancelled) return
setGames(items)
setGames(gamesItems)
setPlayers(playersItems)
})
.catch(() => {
if (cancelled) return
setGames([])
setPlayers([])
})
return () => {
+1 -3
View File
@@ -9,9 +9,7 @@ import { ArrowRight, Search, ShoppingBag, Star } from "lucide-react"
import Link from "next/link"
export default async function HomePage() {
const games = await listGames()
const players = listPlayers()
const shops = listShops()
const [games, players, shops] = await Promise.all([listGames(), listPlayers(), listShops()])
return (
<div className="container mx-auto py-8 px-4 space-y-12">
+3 -3
View File
@@ -12,14 +12,14 @@ import {
} from "@/components/ui/card"
import { Separator } from "@/components/ui/separator"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { listPlayers, listReviewsByTargetUser, listServicesByPlayer } from "@/lib/api"
import { getPlayerById, listReviewsByTargetUser, listServicesByPlayer } from "@/lib/api"
import { CheckCircle, Clock, MapPin, MessageSquare, ShoppingBag, Star } from "lucide-react"
import Link from "next/link"
import { notFound } from "next/navigation"
export default async function PlayerDetailPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params
const player = listPlayers().find((p) => p.id === id)
const player = await getPlayerById(id)
if (!player) {
notFound()
@@ -29,7 +29,7 @@ export default async function PlayerDetailPage({ params }: { params: Promise<{ i
const playerServices =
player.services && player.services.length > 0
? player.services
: listServicesByPlayer(player.id)
: await listServicesByPlayer(player.id)
return (
<div className="container mx-auto py-8 px-4 max-w-5xl">
<div className="flex flex-col md:flex-row gap-8 mb-8">
+1 -1
View File
@@ -18,7 +18,7 @@ export default async function PostDetailPage({ params }: { params: Promise<{ id:
if (!post) notFound()
const linkedOrder = post.linkedOrderId ? getOrderById(post.linkedOrderId) : null
const linkedPlayer = linkedOrder ? getPlayerById(linkedOrder.playerId) : null
const linkedPlayer = linkedOrder ? await getPlayerById(linkedOrder.playerId) : null
return (
<div className="container mx-auto max-w-2xl px-4 py-8 space-y-6">
+3 -3
View File
@@ -16,15 +16,15 @@ interface PageProps {
export default async function ShopPage({ params }: PageProps) {
const { id } = await params
const shop = getShopById(id)
const shop = await getShopById(id)
if (!shop) {
notFound()
}
const shopPlayers = listPlayersByShop(shop.id)
const [shopPlayers, allServices] = await Promise.all([listPlayersByShop(shop.id), listServices()])
const playerIds = shopPlayers.map((p) => p.id)
const shopServices = listServices().filter((s) => playerIds.includes(s.playerId))
const shopServices = allServices.filter((s) => playerIds.includes(s.playerId))
const shopReviews = listReviews().filter((r) => playerIds.includes(r.toUserId))
const sortedSections = [...shop.templateConfig.sections]
.filter((s) => s.enabled)
+8 -4
View File
@@ -21,15 +21,19 @@ export default async function UserProfilePage({ params }: { params: Promise<{ id
notFound()
}
const userPosts = listPostsByAuthor(user.id)
const userFavorites = listFavoritesByUser(user.id)
const [userPosts, userFavorites, players, shops] = await Promise.all([
listPostsByAuthor(user.id),
listFavoritesByUser(user.id),
listPlayers(),
listShops(),
])
const favoritePlayers = userFavorites
.filter((f) => f.targetType === "player")
.map((f) => listPlayers().find((p) => p.id === f.targetId))
.map((f) => players.find((p) => p.id === f.targetId))
.filter((p): p is NonNullable<typeof p> => p != null)
const favoriteShops = userFavorites
.filter((f) => f.targetType === "shop")
.map((f) => listShops().find((s) => s.id === f.targetId))
.map((f) => shops.find((s) => s.id === f.targetId))
.filter((s): s is NonNullable<typeof s> => s != null)
return (