Fix: Resolver error de React hooks en fase MISSION

- Mover useState de cardOrder al nivel del componente
- Eliminar IIFE que causaba violación de reglas de hooks
- Usar cardOrder directamente en lugar de successFirst
- Ahora la fase MISSION debería funcionar correctamente
This commit is contained in:
Resistencia Dev
2025-12-05 23:18:20 +01:00
parent 79ec36dd1a
commit 7fbf964c12

View File

@@ -15,6 +15,10 @@ export default function GameBoard({ gameState, currentPlayerId, actions }: GameB
// Hooks para FASE REVEAL ROLE
const [revealCard, setRevealCard] = useState(false);
// Orden aleatorio de cartas de misión (se genera una vez)
const [cardOrder] = useState(() => Math.random() > 0.5);
// Timer para avanzar automáticamente en REVEAL_ROLE
useEffect(() => {
if (gameState.phase === 'reveal_role' as any) {
@@ -463,18 +467,14 @@ export default function GameBoard({ gameState, currentPlayerId, actions }: GameB
) : (
<div className="text-white text-xl font-mono animate-pulse">
VOTO REGISTRADO. ESPERANDO AL RESTO...
```
</div>
)}
</motion.div>
)}
{/* FASE: MISIÓN */}
{gameState.phase === GamePhase.MISSION && (() => {
// Generar orden aleatorio de cartas (solo una vez por jugador)
const [cardOrder] = useState(() => Math.random() > 0.5);
const successFirst = cardOrder;
return (
{gameState.phase === GamePhase.MISSION && (
<motion.div
key="mission"
className="fixed inset-0 flex items-center justify-center bg-black/90 z-50"
@@ -497,7 +497,7 @@ export default function GameBoard({ gameState, currentPlayerId, actions }: GameB
{/* Cartas en orden aleatorio */}
<div className="flex gap-12 flex-wrap justify-center">
{successFirst ? (
{cardOrder ? (
<>
{/* Carta de Éxito primero */}
<button onClick={() => actions.voteMission(true)} className="group">
@@ -564,8 +564,7 @@ export default function GameBoard({ gameState, currentPlayerId, actions }: GameB
</div>
)}
</motion.div>
);
})()}
)}
{/* FASE: REVELACIÓN DE CARTAS */}
{gameState.phase === 'mission_reveal' as any && (