feat: reconexión de sesión + 6 nuevas categorías + corrección de bugs
- Añade sistema de reconexión tras refresh/cierre del navegador - Persistencia de sesión en localStorage (3h TTL) - Banner de reconexión en Home - Evento rejoin_room en backend - Nuevas categorías: Series TV, Marvel/DC, Disney, Memes, Pokémon, Mitología - Correcciones de bugs: - Fix: juego bloqueado al fallar robo (steal decision) - Fix: jugador duplicado al cambiar de equipo - Fix: rotación incorrecta de turno tras fallo - Config: soporte para Cloudflare tunnel (allowedHosts) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,48 @@
|
||||
import { create } from 'zustand'
|
||||
import type { GameRoom, Question, ChatMessage, Achievement } from '../types'
|
||||
|
||||
// Session persistence helpers
|
||||
const SESSION_KEY = 'trivy_session'
|
||||
|
||||
interface SavedSession {
|
||||
roomCode: string
|
||||
playerName: string
|
||||
team: 'A' | 'B'
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
export function saveSession(roomCode: string, playerName: string, team: 'A' | 'B') {
|
||||
const session: SavedSession = {
|
||||
roomCode,
|
||||
playerName,
|
||||
team,
|
||||
timestamp: Date.now()
|
||||
}
|
||||
localStorage.setItem(SESSION_KEY, JSON.stringify(session))
|
||||
}
|
||||
|
||||
export function getSavedSession(): SavedSession | null {
|
||||
try {
|
||||
const data = localStorage.getItem(SESSION_KEY)
|
||||
if (!data) return null
|
||||
|
||||
const session: SavedSession = JSON.parse(data)
|
||||
// Session expires after 3 hours (same as room TTL)
|
||||
const threeHours = 3 * 60 * 60 * 1000
|
||||
if (Date.now() - session.timestamp > threeHours) {
|
||||
clearSession()
|
||||
return null
|
||||
}
|
||||
return session
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function clearSession() {
|
||||
localStorage.removeItem(SESSION_KEY)
|
||||
}
|
||||
|
||||
export interface Reaction {
|
||||
id: string
|
||||
player_name: string
|
||||
|
||||
Reference in New Issue
Block a user