From f19345c652cfcf1bdf13d0a44a2f302e0cd1aa4c Mon Sep 17 00:00:00 2001
From: Nate Sesti <sestinj@gmail.com>
Date: Sun, 6 Aug 2023 09:28:22 -0700
Subject: feat: :construction: Router and new history page

---
 extension/react-app/src/App.tsx | 50 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 3 deletions(-)

(limited to 'extension/react-app/src/App.tsx')

diff --git a/extension/react-app/src/App.tsx b/extension/react-app/src/App.tsx
index aa462171..15b536db 100644
--- a/extension/react-app/src/App.tsx
+++ b/extension/react-app/src/App.tsx
@@ -1,8 +1,26 @@
-import DebugPanel from "./components/DebugPanel";
 import GUI from "./pages/gui";
-import { createContext } from "react";
+import History from "./pages/history";
+import Layout from "./components/Layout";
+import { createContext, useEffect } from "react";
 import useContinueGUIProtocol from "./hooks/useWebsocket";
 import ContinueGUIClientProtocol from "./hooks/ContinueGUIClientProtocol";
+import {
+  BrowserRouter as Router,
+  Route,
+  Routes,
+  BrowserRouter,
+} from "react-router-dom";
+import { useDispatch } from "react-redux";
+import {
+  setApiUrl,
+  setVscMachineId,
+  setSessionId,
+  setVscMediaUrl,
+  setDataSwitchOn,
+} from "./redux/slices/configSlice";
+import { updateFileSystem } from "./redux/slices/debugContexSlice";
+import { setHighlightedCode } from "./redux/slices/miscSlice";
+import { postVscMessage } from "./vscode";
 
 export const GUIClientContext = createContext<
   ContinueGUIClientProtocol | undefined
@@ -11,9 +29,35 @@ export const GUIClientContext = createContext<
 function App() {
   const client = useContinueGUIProtocol();
 
+  const dispatch = useDispatch();
+  useEffect(() => {
+    const eventListener = (event: any) => {
+      switch (event.data.type) {
+        case "onLoad":
+          dispatch(setApiUrl(event.data.apiUrl));
+          dispatch(setVscMachineId(event.data.vscMachineId));
+          dispatch(setSessionId(event.data.sessionId));
+          dispatch(setVscMediaUrl(event.data.vscMediaUrl));
+          dispatch(setDataSwitchOn(event.data.dataSwitchOn));
+          break;
+        case "highlightedCode":
+          dispatch(setHighlightedCode(event.data.rangeInFile));
+          dispatch(updateFileSystem(event.data.filesystem));
+          break;
+      }
+    };
+    window.addEventListener("message", eventListener);
+    postVscMessage("onLoad", {});
+    return () => window.removeEventListener("message", eventListener);
+  }, []);
+
   return (
     <GUIClientContext.Provider value={client}>
-      <DebugPanel tabs={[{ element: <GUI />, title: "GUI" }]} />
+      <Routes>
+        <Route path="/" element={<Layout />} />
+        <Route path="/gui" element={<GUI />} />
+        <Route path="/history" element={<History />} />
+      </Routes>
     </GUIClientContext.Provider>
   );
 }
-- 
cgit v1.2.3-70-g09d2

