From c22f91858cd99b18bd7b359d55e2871440917c3d Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Fri, 24 Jan 2025 15:04:22 +0000 Subject: [PATCH] Remember last selected transport and SSE URL --- client/src/App.tsx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 1c6d6b6..39c13c2 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React from "react"; import { useDraggablePane } from "./lib/hooks/useDraggablePane"; import { useConnection } from "./lib/hooks/useConnection"; import { @@ -51,8 +51,10 @@ const PROXY_SERVER_URL = `http://localhost:${PROXY_PORT}`; const App = () => { // Handle OAuth callback route - if (window.location.pathname === '/oauth/callback') { - const OAuthCallback = React.lazy(() => import('./components/OAuthCallback')); + if (window.location.pathname === "/oauth/callback") { + const OAuthCallback = React.lazy( + () => import("./components/OAuthCallback"), + ); return ( Loading...}> @@ -81,8 +83,14 @@ const App = () => { return localStorage.getItem("lastArgs") || ""; }); - const [sseUrl, setSseUrl] = useState("http://localhost:3001/sse"); - const [transportType, setTransportType] = useState<"stdio" | "sse">("stdio"); + const [sseUrl, setSseUrl] = useState(() => { + return localStorage.getItem("lastSseUrl") || "http://localhost:3001/sse"; + }); + const [transportType, setTransportType] = useState<"stdio" | "sse">(() => { + return ( + (localStorage.getItem("lastTransportType") as "stdio" | "sse") || "stdio" + ); + }); const [notifications, setNotifications] = useState([]); const [stdErrNotifications, setStdErrNotifications] = useState< StdErrNotification[] @@ -200,6 +208,14 @@ const App = () => { localStorage.setItem("lastArgs", args); }, [args]); + useEffect(() => { + localStorage.setItem("lastSseUrl", sseUrl); + }, [sseUrl]); + + useEffect(() => { + localStorage.setItem("lastTransportType", transportType); + }, [transportType]); + useEffect(() => { fetch(`${PROXY_SERVER_URL}/config`) .then((response) => response.json())