From 39592bd579aae04631fc5eee9792bb846cab8206 Mon Sep 17 00:00:00 2001 From: Michess Date: Mon, 13 Apr 2026 13:45:43 +0200 Subject: [PATCH] fix: convert PublicGames to client component to avoid async server component in client tree --- .../home/PublicGames/PublicGames.tsx | 21 +++++++++++++++---- .../home/PublicGames/RefreshButton.tsx | 5 +++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/client/src/components/home/PublicGames/PublicGames.tsx b/client/src/components/home/PublicGames/PublicGames.tsx index 067b6bd..8b21762 100644 --- a/client/src/components/home/PublicGames/PublicGames.tsx +++ b/client/src/components/home/PublicGames/PublicGames.tsx @@ -1,14 +1,27 @@ +"use client"; + +import { useEffect, useState } from "react"; import { fetchPublicGames } from "@/lib/game"; +import type { Game } from "@michess/types"; import JoinButton from "./JoinButton"; import RefreshButton from "./RefreshButton"; -export default async function PublicGames() { - const games = await fetchPublicGames(); +export default function PublicGames() { + const [games, setGames] = useState([]); + + async function load() { + const data = await fetchPublicGames(); + setGames(data || []); + } + + useEffect(() => { + load(); + }, []); return (

- Public games + Public games

@@ -21,7 +34,7 @@ export default async function PublicGames() { - {games && games.length > 0 ? ( + {games.length > 0 ? ( games.map((game) => ( diff --git a/client/src/components/home/PublicGames/RefreshButton.tsx b/client/src/components/home/PublicGames/RefreshButton.tsx index 7a3722e..33a1671 100644 --- a/client/src/components/home/PublicGames/RefreshButton.tsx +++ b/client/src/components/home/PublicGames/RefreshButton.tsx @@ -4,13 +4,14 @@ import { IconRefresh } from "@tabler/icons-react"; import { useRouter } from "next/navigation"; import { useTransition } from "react"; -export default function RefreshButton() { +export default function RefreshButton({ onRefresh }: { onRefresh?: () => void }) { const router = useRouter(); const [isLoading, startTransition] = useTransition(); function handleRefresh() { startTransition(() => { - router.refresh(); + if (onRefresh) onRefresh(); + else router.refresh(); }); }