- implement user settings reset functionality with modal confirmation

and bug fixes regarding lane IDs to sighting endpoints
This commit is contained in:
2026-01-07 09:39:46 +00:00
parent f046ae6dfc
commit f9188bb46f
13 changed files with 186 additions and 140 deletions

View File

@@ -1,33 +0,0 @@
import { createContext, useContext } from "react";
import type { InfoBarData } from "../types/types";
import { ReadyState } from "react-use-websocket";
type InfoSocketState = {
data: InfoBarData | null;
readyState: ReadyState;
sendJson: (msg: unknown) => void;
send?: (msg: string) => void;
};
type heatmapSocketState = {
data: null;
readyState: ReadyState;
sendJson: (msg: unknown) => void;
send?: (msg: string) => void;
};
export type WebsocketContextValue = {
info: InfoSocketState;
heatmap?: heatmapSocketState;
};
export const WebsocketContext = createContext<WebsocketContextValue | null>(null);
const useWebSocketContext = () => {
const ctx = useContext(WebsocketContext);
if (!ctx) throw new Error("useWebSocketContext must be used inside <WebSocketConext.Provider>");
return ctx;
};
export const useInfoBarSocket = () => useWebSocketContext().info;
export const useHeatmapSocket = () => useWebSocketContext().heatmap;

View File

@@ -1,40 +0,0 @@
import { useEffect, useMemo, useState, type ReactNode } from "react";
import type { InfoBarData } from "../../types/types";
import useWebSocket from "react-use-websocket";
import { ws_config } from "../../utils/ws_config";
import { WebsocketContext, type WebsocketContextValue } from "../WebsocketContext";
type WebSocketProviderProps = {
children: ReactNode;
};
const WebSocketProvider = ({ children }: WebSocketProviderProps) => {
const [systemData, setSystemData] = useState<InfoBarData | null>(null);
const infoSocket = useWebSocket(ws_config.infoBar, { share: true, shouldReconnect: () => true });
useEffect(() => {
async function parseData() {
if (infoSocket.lastMessage) {
const text = await infoSocket.lastMessage.data.text();
const data = JSON.parse(text);
setSystemData(data);
}
}
parseData();
}, [infoSocket.lastMessage]);
const value = useMemo<WebsocketContextValue>(
() => ({
info: {
data: systemData,
readyState: infoSocket.readyState,
sendJson: infoSocket.sendJsonMessage,
},
}),
[systemData, infoSocket.readyState, infoSocket.sendJsonMessage]
);
return <WebsocketContext.Provider value={value}>{children}</WebsocketContext.Provider>;
};
export default WebSocketProvider;

View File

@@ -69,6 +69,8 @@ export function reducer(state: SoundState, action: SoundAction): SoundState {
...state,
uploadedSound: action.payload,
};
case "RESET":
return initialState;
default:
return state;
}