diff --git a/client/src/app/correspondence/[code]/page.tsx b/client/src/app/correspondence/[code]/page.tsx index 2cf3389..e398990 100644 --- a/client/src/app/correspondence/[code]/page.tsx +++ b/client/src/app/correspondence/[code]/page.tsx @@ -14,6 +14,7 @@ import { useCallback, useEffect, useState } from "react"; import { Chessboard } from "react-chessboard"; import type { Square } from "chess.js"; import { APP_URL } from "@/config"; +import InviteFriendsModal from "@/components/InviteFriendsModal"; export default function CorrespondenceGamePage() { const { user } = useSession(); @@ -194,6 +195,7 @@ export default function CorrespondenceGamePage() { > {copied ? "Kopiert!" : `${APP_URL.replace(/^https?:\/\//, "")}/correspondence/${code}`} + {!isPlayer && user?.id && ( - + {tournament.status === "waiting" && user?.id && !isJoined && ( )} + {tournament.status === "waiting" && isJoined && ( + + )} {canStart && ( ([]); + const [loading, setLoading] = useState(false); + const [sent, setSent] = useState>({}); + + async function openModal() { + if (!user?.id || typeof user.id === "string") return; + setOpen(true); + setLoading(true); + const res = await fetch(`${API_URL}/v1/friends`, { credentials: "include" }); + if (res.ok) setFriends(await res.json()); + setLoading(false); + } + + function invite(friendId: number) { + sendGameInvite(friendId, gameCode); + setSent((prev) => ({ ...prev, [friendId]: true })); + setTimeout(() => setSent((prev) => ({ ...prev, [friendId]: false })), 3000); + } + + if (!user?.id || typeof user.id === "string") return null; + + return ( + <> + + {label} + + + {open && ( + + + setOpen(false)} + > + ✕ + + {label} + {loading ? ( + + + + ) : friends.length === 0 ? ( + + Keine Freunde gefunden. Füge zuerst Freunde hinzu. + + ) : ( + + {friends.map((f) => ( + + {f.friend_name} + invite(f.friend_id)} + > + {sent[f.friend_id] ? "✓ Gesendet" : "Einladen"} + + + ))} + + )} + + setOpen(false)} /> + + )} + > + ); +} diff --git a/client/src/components/game/GamePage.tsx b/client/src/components/game/GamePage.tsx index f794a76..5439261 100644 --- a/client/src/components/game/GamePage.tsx +++ b/client/src/components/game/GamePage.tsx @@ -23,6 +23,7 @@ import type { ClearPremoves } from "react-chessboard"; import { Chessboard } from "react-chessboard"; import { API_URL, APP_URL } from "@/config"; +import InviteFriendsModal from "@/components/InviteFriendsModal"; import { io } from "socket.io-client"; import { lobbyReducer, squareReducer } from "./reducers"; @@ -654,6 +655,11 @@ export default function GamePage({ initialLobby }: { initialLobby: Game }) { + {!lobby.endReason && ( + + + + )} {getMoveListHtml()}
+ Keine Freunde gefunden. Füge zuerst Freunde hinzu. +