fix: Redirigir al lobby cuando la partida deja de existir tras recargar
Some checks failed
CI/CD - Francia Ocupada (La Resistencia) / build-and-deploy (push) Failing after 6s

- Añadido listener de errores de socket para detectar fallos de reconexión
- Actualizada la lógica de transiciones de vista para evitar bloqueos en pantallas vacías
- Limpieza de sesión al fallar la reconexión
This commit is contained in:
Resistencia Dev
2025-12-22 18:38:07 +01:00
parent 91da241423
commit 3ac48e50fb

View File

@@ -65,10 +65,30 @@ export default function Home() {
updateSession({ currentView: 'game', roomId: gameState.roomId });
} else if (view === 'game' && !gameState) {
// Si estábamos en juego y volvemos a null, volver al lobby
setView('lobby');
updateSession({ currentView: 'lobby', roomId: undefined });
// Pero solo si no estamos esperando una reconexión inicial
if (hasReconnected) {
setView('lobby');
updateSession({ currentView: 'lobby', roomId: undefined });
}
}
}, [gameState]);
}, [gameState, view, hasReconnected]);
// Listener para errores de socket que deben expulsar al lobby
useEffect(() => {
if (!socket) return;
const handleError = (msg: string) => {
if (msg === 'La partida ya no existe' || msg === 'No se pudo reconectar a la partida') {
setView('lobby');
updateSession({ currentView: 'lobby', roomId: undefined });
}
};
socket.on('error', handleError);
return () => {
socket.off('error', handleError);
};
}, [socket, updateSession]);
const handleLogin = (e: React.FormEvent) => {
e.preventDefault();