"use client" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { IconInput } from "@/components/ui/icon-input" import { StatusBadge } from "@/components/ui/status-badge" import { listGames, listPlayers, listShops } from "@/lib/api" import { toApiError } from "@/lib/errors" import { GameIcon } from "@/lib/game-icons" import { ArrowRight, Search, ShoppingBag, Star } from "lucide-react" import Link from "next/link" import { useEffect, useState } from "react" export default function HomePage() { const [games, setGames] = useState>>([]) const [players, setPlayers] = useState>>([]) const [shops, setShops] = useState>>([]) const [loading, setLoading] = useState(true) const [loadingError, setLoadingError] = useState(null) useEffect(() => { let cancelled = false const load = async () => { try { const [nextGames, nextPlayers, nextShops] = await Promise.all([ listGames(), listPlayers(), listShops(), ]) if (cancelled) return setGames(nextGames) setPlayers(nextPlayers) setShops(nextShops) setLoading(false) } catch (err: unknown) { if (cancelled) return setLoading(false) setLoadingError(toApiError(err).msg) } } void load() return () => { cancelled = true } }, []) return (

找到你的游戏搭档

找人一起打游戏,从这里开始

{loading &&

加载中...

} {!loading && loadingError && (

{loadingError}

)}

游戏分类

{!loading && !loadingError ? games.map((game) => ( )) : null}

推荐内容

{/* Players */} {!loading && !loadingError ? players.map((player) => ( {player.user.nickname[0]}
{player.user.nickname}
{player.rating}
{player.totalOrders} 单 {player.status === "available" ? "可接单" : player.status === "busy" ? "忙碌" : "离线"}
{player.tags.map((tag) => ( {tag} ))}
{player.shopName && (

所属店铺: {player.shopName}

)}
{player.services?.[0]?.price ?? 35} 元/{player.services?.[0]?.unit ?? "时"}
)) : null} {/* Community Teaser */} 逛逛社区

发现更多有趣的游戏日常和讨论

{/* Shops */} {!loading && !loadingError ? shops.map((shop) => ( {shop.name}

{shop.description}

{shop.rating}
{shop.totalOrders} 单
{shop.playerCount} 名打手
)) : null}
) }