Expire a scout session whose timestamp cannot be read.
sessioneScaduta compared Date.now() against NaN when aggiornato_il was not a valid date, and every comparison with NaN is false: the session was reported as still active, so the Scout Live table stayed locked to a player who could no longer release it. An unreadable timestamp now frees the session, which is the safe direction: at worst someone takes over a scouting session that was already unattended. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+13
-3
@@ -24,7 +24,10 @@ export type SessioneScout = {
|
||||
|
||||
export function sessioneScaduta(s: SessioneScout | null): boolean {
|
||||
if (!s) return true;
|
||||
return Date.now() - new Date(s.aggiornato_il).getTime() > SCADENZA_MINUTI * 60_000;
|
||||
const aggiornato = new Date(s.aggiornato_il).getTime();
|
||||
// Timestamp illeggibile: meglio liberare la sessione che lasciarla bloccata per sempre.
|
||||
if (Number.isNaN(aggiornato)) return true;
|
||||
return Date.now() - aggiornato > SCADENZA_MINUTI * 60_000;
|
||||
}
|
||||
|
||||
const storageKey = (eventoId: string) => `crap-scout-session-${eventoId}`;
|
||||
@@ -82,7 +85,10 @@ export function useSessioneScout(eventoId: string | null) {
|
||||
} catch {
|
||||
const onStorage = (e: StorageEvent) => {
|
||||
if (e.key === storageKey(eventoId)) {
|
||||
queryClient.setQueryData(SESSIONE_KEY(eventoId), e.newValue ? (JSON.parse(e.newValue) as SessioneScout) : null);
|
||||
queryClient.setQueryData(
|
||||
SESSIONE_KEY(eventoId),
|
||||
e.newValue ? (JSON.parse(e.newValue) as SessioneScout) : null,
|
||||
);
|
||||
}
|
||||
};
|
||||
window.addEventListener("storage", onStorage);
|
||||
@@ -140,7 +146,11 @@ export function useChiudiSessioneScout() {
|
||||
}
|
||||
|
||||
/** Mantiene viva la sessione mentre lo scout è aperto. */
|
||||
export function useHeartbeatScout(eventoId: string | null, giocatoreId: string | null, attivo: boolean) {
|
||||
export function useHeartbeatScout(
|
||||
eventoId: string | null,
|
||||
giocatoreId: string | null,
|
||||
attivo: boolean,
|
||||
) {
|
||||
useEffect(() => {
|
||||
if (!attivo || !eventoId || !giocatoreId || typeof window === "undefined") return;
|
||||
const id = window.setInterval(() => {
|
||||
|
||||
Reference in New Issue
Block a user