mirror of
https://github.com/MeshCore-Beacon/beacon-web.git
synced 2026-09-01 16:48:19 +00:00
Small bug fixes
This commit is contained in:
@@ -24,6 +24,7 @@ export class WsManager {
|
||||
private subscriptionId: string | null = null;
|
||||
private status: WsStatus = "disconnected";
|
||||
private reconnectAttempt = 0;
|
||||
private intentionalClose = false;
|
||||
private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private pingTimer: ReturnType<typeof setInterval> | null = null;
|
||||
private msgCounter = 0;
|
||||
@@ -111,6 +112,8 @@ export class WsManager {
|
||||
}
|
||||
|
||||
disconnect(): void {
|
||||
this.intentionalClose = true;
|
||||
this.reconnectAttempt = 0;
|
||||
this.clearTimers();
|
||||
this.ws?.close();
|
||||
this.ws = null;
|
||||
@@ -120,6 +123,7 @@ export class WsManager {
|
||||
// exponential backoff w/ jitter to avoid thundering herd on reconnect
|
||||
|
||||
private doConnect(): void {
|
||||
this.intentionalClose = false;
|
||||
this.clearTimers();
|
||||
this.setStatus("connecting");
|
||||
|
||||
@@ -142,7 +146,7 @@ export class WsManager {
|
||||
|
||||
this.ws.onclose = (e: CloseEvent) => {
|
||||
this.clearTimers();
|
||||
if (e.code === 1000) {
|
||||
if (this.intentionalClose || e.code === 1000) {
|
||||
this.setStatus("disconnected");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useRef, useCallback, type ReactNode } from "react";
|
||||
import { useState, useRef, useCallback, useEffect, type ReactNode } from "react";
|
||||
import { useClickOutside } from "../hooks/useClickOutside";
|
||||
|
||||
export function Dropdown({ renderTrigger, align = "right", width = "w-48", children }: {
|
||||
@@ -13,6 +13,15 @@ export function Dropdown({ renderTrigger, align = "right", width = "w-48", child
|
||||
const toggle = useCallback(() => setOpen((v) => !v), []);
|
||||
useClickOutside(ref, open, close);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
function handleKey(e: KeyboardEvent) {
|
||||
if (e.key === "Escape") close();
|
||||
}
|
||||
document.addEventListener("keydown", handleKey);
|
||||
return () => document.removeEventListener("keydown", handleKey);
|
||||
}, [open, close]);
|
||||
|
||||
return (
|
||||
<div ref={ref} className="relative">
|
||||
{renderTrigger({ open, toggle })}
|
||||
|
||||
@@ -15,8 +15,12 @@ export function SplashScreen() {
|
||||
// Synchronous gate: decided before first paint so StrictMode's double-mount
|
||||
// (and any same-session reload) never re-shows it.
|
||||
const [render, setRender] = useState(() => {
|
||||
if (typeof sessionStorage === "undefined") return false;
|
||||
return sessionStorage.getItem(SPLASH_KEY) !== "1";
|
||||
try {
|
||||
if (typeof sessionStorage === "undefined") return false;
|
||||
return sessionStorage.getItem(SPLASH_KEY) !== "1";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
const [fading, setFading] = useState(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user