From 2b18fc91d6e0dd29e5e0a868f484f52af50f60ab Mon Sep 17 00:00:00 2001 From: alexwhelan12 Date: Sat, 17 Jan 2026 14:37:38 -0700 Subject: [PATCH 1/3] Added button w/ password to update finish line location --- .../src/components/global/SocketManager.tsx | 5 +- .../Settings/SetFinishLineLocation.tsx | 102 ++++++++++++++++++ .../LogoStatusMolecules/SettingsComponent.tsx | 3 +- .../LapController/LapController.ts | 2 +- .../src/datasources/SocketIO/SocketIO.ts | 31 ++++-- 5 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 packages/client/src/components/molecules/LogoStatusMolecules/Settings/SetFinishLineLocation.tsx diff --git a/packages/client/src/components/global/SocketManager.tsx b/packages/client/src/components/global/SocketManager.tsx index dd705c9b..3cdeeec3 100644 --- a/packages/client/src/components/global/SocketManager.tsx +++ b/packages/client/src/components/global/SocketManager.tsx @@ -17,7 +17,10 @@ import { socketURL } from "@shared/helios-types"; interface ClientToServerEvents { ping: (cb: (val: number) => void) => void; - setLapCoords: (coords: CoordInfoUpdate) => void; + setLapCoords: ( + coords: CoordInfoUpdate, + callback: (response: CoordUpdateResponse) => void, + ) => void; } interface ServerToClientEvents { diff --git a/packages/client/src/components/molecules/LogoStatusMolecules/Settings/SetFinishLineLocation.tsx b/packages/client/src/components/molecules/LogoStatusMolecules/Settings/SetFinishLineLocation.tsx new file mode 100644 index 00000000..8b0bca55 --- /dev/null +++ b/packages/client/src/components/molecules/LogoStatusMolecules/Settings/SetFinishLineLocation.tsx @@ -0,0 +1,102 @@ +import { useTheme } from "next-themes"; +import React from "react"; + +import { socketIO } from "@/components/global/SocketManager"; +import { usePacketStore } from "@/stores/usePacket"; +import { helios, heliosCompliment, sand } from "@/styles/colors"; +import { notifications } from "@mantine/notifications"; +import { Button, TextField } from "@mui/material"; +import { CoordUpdateResponse } from "@shared/helios-types"; + +const SetFinishLineLocation = () => { + const { currentPacket } = usePacketStore(); + const { resolvedTheme } = useTheme(); + const [password, setPassword] = React.useState(""); + + const handleSetFinishLineLocation = () => { + socketIO.emit( + "setLapCoords", + { + lat: (currentPacket?.Telemetry.GpsLatitude).toString() || "0", + long: (currentPacket?.Telemetry.GpsLongitude).toString() || "0", + password: password, + }, + (response: CoordUpdateResponse) => { + if ("error" in response) { + notifications.show({ + color: "red", + message: response.error, + title: "Error Setting Finish Line Location", + }); + return; + } + notifications.show({ + color: "green", + message: "Finish Line Location Updated Successfully", + title: "Success", + }); + }, + ); + }; + + return ( +
+
+ +
+
+ + setPassword(e.target.value)} + sx={{ + "& .MuiInputBase-input": { + color: resolvedTheme === "dark" ? "white" : "black", + }, + "& .MuiInputBase-input::label": { + color: resolvedTheme === "dark" ? sand : helios, + }, + "& .MuiInputLabel-root, & .MuiInputLabel-root.Mui-focused": { + color: resolvedTheme === "dark" ? sand : helios, + }, + "& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline, & .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline": + { + borderColor: resolvedTheme === "dark" ? sand : helios, + }, + }} + type="password" + value={password} + /> +
+
+ ); +}; + +export default SetFinishLineLocation; diff --git a/packages/client/src/components/molecules/LogoStatusMolecules/SettingsComponent.tsx b/packages/client/src/components/molecules/LogoStatusMolecules/SettingsComponent.tsx index 3d4f3655..fb4b46eb 100644 --- a/packages/client/src/components/molecules/LogoStatusMolecules/SettingsComponent.tsx +++ b/packages/client/src/components/molecules/LogoStatusMolecules/SettingsComponent.tsx @@ -1,9 +1,9 @@ import { useTheme } from "next-themes"; import { useCallback, useState } from "react"; +import SetFinishLineLocation from "@/components/molecules/LogoStatusMolecules/Settings/SetFinishLineLocation"; import { APPUNITS, CONNECTIONTYPES, useAppState } from "@/stores/useAppState"; import { helios, heliosCompliment, sand } from "@/styles/colors"; -import { TimeInput } from "@mantine/dates"; import SettingsIcon from "@mui/icons-material/Settings"; import Modal from "@mui/material/Modal"; import ToggleButton from "@mui/material/ToggleButton"; @@ -242,6 +242,7 @@ function SettingsComponent() { + diff --git a/packages/server/src/controllers/LapController/LapController.ts b/packages/server/src/controllers/LapController/LapController.ts index 936814f0..2d870a5d 100644 --- a/packages/server/src/controllers/LapController/LapController.ts +++ b/packages/server/src/controllers/LapController/LapController.ts @@ -132,7 +132,7 @@ export class LapController implements LapControllerType { ): CoordUpdateResponse { logger.info(JSON.stringify(newCoordInfo)); const { lat, long, password } = newCoordInfo; - if (password !== process.env.LAP_POSITION_PASSWORD) { + if (password !== process.env.FINISH_LINE_UPDATE_PASSWORD) { logger.error("Invalid Password: " + password); return { error: "Invalid Password", invalidFields: ["password"] }; } diff --git a/packages/server/src/datasources/SocketIO/SocketIO.ts b/packages/server/src/datasources/SocketIO/SocketIO.ts index f69a1f95..d40c04a0 100644 --- a/packages/server/src/datasources/SocketIO/SocketIO.ts +++ b/packages/server/src/datasources/SocketIO/SocketIO.ts @@ -68,17 +68,28 @@ export class SocketIO implements SocketIOType { socket.on("ping", (callback: () => void) => { callback(); }); - socket.on("setLapCoords", (newCoordInfo: CoordInfoUpdate) => { - const { lat, long, password } = newCoordInfo; - logger.info("UPDATED COORDS: "); - logger.info("lat: ", lat, "long: ", long); - const res = - this.backendController.lapController.setFinishLineLocation( - newCoordInfo, - ); + socket.on( + "setLapCoords", + ( + newCoordInfo: CoordInfoUpdate, + callback: (response: CoordUpdateResponse) => void, + ) => { + const { lat, long, password } = newCoordInfo; - this.broadcastLapCoords(res); - }); + logger.info("UPDATED COORDS: "); + logger.info("lat: ", lat, "long: ", long); + const res = + this.backendController.lapController.setFinishLineLocation( + newCoordInfo, + ); + // Only broadcast if successful + if (!("error" in res)) { + this.broadcastLapCoords(res); + } + + callback(res); + }, + ); socket.on("disconnect", () => { logger.info("Client disconnected"); }); From 3c110712f3108a6885a87b69124347f057536b9e Mon Sep 17 00:00:00 2001 From: alexwhelan12 Date: Sat, 17 Jan 2026 14:41:37 -0700 Subject: [PATCH 2/3] removed unused destructuring of variable --- packages/server/src/datasources/SocketIO/SocketIO.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/datasources/SocketIO/SocketIO.ts b/packages/server/src/datasources/SocketIO/SocketIO.ts index d40c04a0..350ae88a 100644 --- a/packages/server/src/datasources/SocketIO/SocketIO.ts +++ b/packages/server/src/datasources/SocketIO/SocketIO.ts @@ -74,7 +74,7 @@ export class SocketIO implements SocketIOType { newCoordInfo: CoordInfoUpdate, callback: (response: CoordUpdateResponse) => void, ) => { - const { lat, long, password } = newCoordInfo; + const { lat, long } = newCoordInfo; logger.info("UPDATED COORDS: "); logger.info("lat: ", lat, "long: ", long); From 4d36d1b1ce0d07636713fcd66d87b7eff273e45d Mon Sep 17 00:00:00 2001 From: alexwhelan12 Date: Sat, 24 Jan 2026 10:37:28 -0700 Subject: [PATCH 3/3] fix: address coderabbit fixes --- .../LogoStatusMolecules/Settings/SetFinishLineLocation.tsx | 4 ++-- packages/server/src/datasources/SocketIO/SocketIO.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/client/src/components/molecules/LogoStatusMolecules/Settings/SetFinishLineLocation.tsx b/packages/client/src/components/molecules/LogoStatusMolecules/Settings/SetFinishLineLocation.tsx index 8b0bca55..e0f0ca86 100644 --- a/packages/client/src/components/molecules/LogoStatusMolecules/Settings/SetFinishLineLocation.tsx +++ b/packages/client/src/components/molecules/LogoStatusMolecules/Settings/SetFinishLineLocation.tsx @@ -17,8 +17,8 @@ const SetFinishLineLocation = () => { socketIO.emit( "setLapCoords", { - lat: (currentPacket?.Telemetry.GpsLatitude).toString() || "0", - long: (currentPacket?.Telemetry.GpsLongitude).toString() || "0", + lat: String(currentPacket?.Telemetry?.GpsLatitude ?? 0), + long: String(currentPacket?.Telemetry?.GpsLongitude ?? 0), password: password, }, (response: CoordUpdateResponse) => { diff --git a/packages/server/src/datasources/SocketIO/SocketIO.ts b/packages/server/src/datasources/SocketIO/SocketIO.ts index 350ae88a..2c6f041e 100644 --- a/packages/server/src/datasources/SocketIO/SocketIO.ts +++ b/packages/server/src/datasources/SocketIO/SocketIO.ts @@ -72,7 +72,7 @@ export class SocketIO implements SocketIOType { "setLapCoords", ( newCoordInfo: CoordInfoUpdate, - callback: (response: CoordUpdateResponse) => void, + callback?: (response: CoordUpdateResponse) => void, ) => { const { lat, long } = newCoordInfo; @@ -87,7 +87,9 @@ export class SocketIO implements SocketIOType { this.broadcastLapCoords(res); } - callback(res); + if (typeof callback === "function") { + callback(res); + } }, ); socket.on("disconnect", () => {