feat(frontend): polish web (logout, 401→pairing, reconnexion globale) (#13)
Flow logout : POST /api/logout puis retour à l'écran de pairing et déconnexion du live. 401 renvoie au pairing sans boucle. Bannière de reconnexion couvrant le cas live-only et le serveur indisponible. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
29
frontend/src/features/web/useLiveConnectionState.ts
Normal file
29
frontend/src/features/web/useLiveConnectionState.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* `useLiveConnectionState` — ticket #13, lot F6. Web-only hook exposing the shared
|
||||
* live WebSocket's current {@link ConnectionState} to the UI so a reconnection
|
||||
* banner can be shown even when no terminal is open (the F3 xterm notice only
|
||||
* covers terminal cells; live-only surfaces had no visible signal).
|
||||
*
|
||||
* Inert outside web transport (no client registered), so it is safe to mount
|
||||
* unconditionally: it returns `null` on desktop.
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { getWebLiveClient, type ConnectionState } from "@/adapters/http";
|
||||
|
||||
export function useLiveConnectionState(): ConnectionState | null {
|
||||
const [state, setState] = useState<ConnectionState | null>(
|
||||
() => getWebLiveClient()?.getConnectionState() ?? null,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const client = getWebLiveClient();
|
||||
if (!client) return;
|
||||
// Sync in case the state changed between the initial render and this effect.
|
||||
setState(client.getConnectionState());
|
||||
return client.onConnectionStateChange(setState);
|
||||
}, []);
|
||||
|
||||
return state;
|
||||
}
|
||||
Reference in New Issue
Block a user