fix: Hex Wars - Spielliste zeigt current_turn sofort korrekt
This commit is contained in:
@@ -547,7 +547,14 @@ export default function HexWars({ toast }) {
|
||||
const g = await api(`/tools/gebietseroberung/${activeId}`).catch(() => null);
|
||||
if (!g) return;
|
||||
setGame(g);
|
||||
if (g.current_turn === myId) toast?.('Du bist dran! ⬡');
|
||||
if (g.current_turn === myId) {
|
||||
toast?.('Du bist dran! ⬡');
|
||||
// games-Liste sofort aktualisieren
|
||||
setGames(prev => prev.map(p => p.id === g.id
|
||||
? { ...p, current_turn: g.current_turn, move_count: g.move_count }
|
||||
: p
|
||||
));
|
||||
}
|
||||
}, 10000);
|
||||
return () => clearInterval(iv);
|
||||
}, [activeId, game, myId]);
|
||||
@@ -555,13 +562,20 @@ export default function HexWars({ toast }) {
|
||||
const handleMove = async (row, col) => {
|
||||
const updated = await api(`/tools/gebietseroberung/${activeId}/move`, { body: { row, col } });
|
||||
setGame(updated);
|
||||
loadGames(); // Spielliste aktualisieren damit current_turn stimmt
|
||||
// Direkt den games-State patchen damit die Liste sofort stimmt (kein Warten auf loadGames)
|
||||
setGames(prev => prev.map(g => g.id === updated.id
|
||||
? { ...g, current_turn: updated.current_turn, move_count: updated.move_count, status: updated.status, winner_id: updated.winner_id }
|
||||
: g
|
||||
));
|
||||
};
|
||||
|
||||
const handleScout = async (row, col) => {
|
||||
const updated = await api(`/tools/gebietseroberung/${activeId}/scout`, { body: { row, col } });
|
||||
setGame(updated);
|
||||
loadGames();
|
||||
setGames(prev => prev.map(g => g.id === updated.id
|
||||
? { ...g, current_turn: updated.current_turn, move_count: updated.move_count }
|
||||
: g
|
||||
));
|
||||
};
|
||||
|
||||
const handleResign = async () => {
|
||||
@@ -589,7 +603,7 @@ export default function HexWars({ toast }) {
|
||||
<div style={{ maxWidth:600, margin:'0 auto' }}>
|
||||
<div style={{ display:'flex', alignItems:'center', gap:8, marginBottom:8 }}>
|
||||
{activeId && (
|
||||
<button onClick={() => { setActiveId(null); setGame(null); }} style={S.btn('#666666', true)}>← Zurück</button>
|
||||
<button onClick={() => { setActiveId(null); setGame(null); loadGames(); }} style={S.btn('#666666', true)}>← Zurück</button>
|
||||
)}
|
||||
<h2 style={{ margin:0, fontSize:13, fontFamily:'monospace', color:'rgba(255,255,255,0.55)', letterSpacing:2, fontWeight:400, flexShrink:0 }}>
|
||||
⬡ HEX WARS
|
||||
|
||||
Reference in New Issue
Block a user