1- import "@mantine/core/styles.css" ;
21import { QueryClient , QueryClientProvider } from "@tanstack/react-query" ;
3- import { useEffect , useState } from "react " ;
2+ import { Route , Switch } from "wouter " ;
43import "./App.css" ;
5- import { useBackendData , useExecutable } from "./hooks/useBackendData" ;
6- import { NotifierProvider , useNotifier } from "./hooks/useNotifier" ;
7- import { SettingsProvider } from "./hooks/useSettings" ;
8- import { AppShell , View , Viewer } from "./layout" ;
9- import { ThemeProvider } from "./theme/ThemeProvider" ;
10- import { NotificationType } from "./types/notification" ;
4+ import { AppProvider } from "./hooks/useAppContext.tsx" ;
5+ import { NotifierProvider } from "./hooks/useNotifier" ;
6+ import { AppShell } from "./layout" ;
7+ import { PageWrapper } from "./components/PageWrapper.tsx" ;
8+ import { Settings , Welcome , Data } from "./pages" ;
9+ import { WorkspaceRoute } from "./pages/Workspace/WorkspaceRoute.tsx" ;
10+ import { ExecutableRoute } from "./pages/Executable/ExecutableRoute.tsx" ;
11+ import { Text } from "@mantine/core" ;
1112
1213const queryClient = new QueryClient ( {
1314 defaultOptions : {
@@ -18,104 +19,42 @@ const queryClient = new QueryClient({
1819 } ,
1920} ) ;
2021
21- function AppContent ( ) {
22- const [ currentView , setCurrentView ] = useState < View > ( View . Welcome ) ;
23- const [ welcomeMessage , setWelcomeMessage ] = useState < string > ( "" ) ;
24- const [ selectedExecutable , setSelectedExecutable ] = useState < string | null > (
25- null
26- ) ;
27- const [ selectedWorkspace , setSelectedWorkspace ] = useState < string | null > (
28- null
29- ) ;
30- const { notification, setNotification } = useNotifier ( ) ;
31-
32- const { config, workspaces, executables, isLoading, hasError, refreshAll } =
33- useBackendData ( selectedWorkspace ) ;
34-
35- const { executable, executableError } = useExecutable (
36- selectedExecutable || ""
37- ) ;
38-
39- // Set initial workspace from config when it loads
40- useEffect ( ( ) => {
41- if ( config ?. currentWorkspace && workspaces && workspaces . length > 0 ) {
42- // Only update if we don't have a selected workspace or if the config workspace is different
43- if ( ! selectedWorkspace || config . currentWorkspace !== selectedWorkspace ) {
44- setSelectedWorkspace ( config . currentWorkspace ) ;
45- }
46- }
47- } , [ config , workspaces ] ) ;
48-
49- useEffect ( ( ) => {
50- if ( hasError ) {
51- setNotification ( {
52- title : "Unexpected error" ,
53- message : hasError . message || "An error occurred" ,
54- type : NotificationType . Error ,
55- autoClose : false ,
56- } ) ;
57- }
58- } , [ hasError ] ) ;
59-
60- useEffect ( ( ) => {
61- if ( welcomeMessage === "" && executables ?. length > 0 ) {
62- setWelcomeMessage ( "Select an executable to get started." ) ;
63- }
64- } , [ executables , welcomeMessage ] ) ;
65-
66- const handleLogoClick = ( ) => {
67- setCurrentView ( View . Welcome ) ;
68- } ;
69-
70- return (
71- < AppShell
72- currentView = { currentView }
73- setCurrentView = { ( view : string ) => setCurrentView ( view as View ) }
74- workspaces = { workspaces || [ ] }
75- selectedWorkspace = { selectedWorkspace }
76- onSelectWorkspace = { ( workspaceName ) => {
77- setSelectedWorkspace ( workspaceName ) ;
78- setCurrentView ( View . Workspace ) ;
79- } }
80- visibleExecutables = { executables || [ ] }
81- onSelectExecutable = { ( executable ) => {
82- if ( executable === selectedExecutable ) {
83- return ;
84- }
85- setSelectedExecutable ( executable ) ;
86- if ( currentView !== View . Executable ) {
87- setCurrentView ( View . Executable ) ;
88- }
89- } }
90- onLogoClick = { handleLogoClick }
91- hasError = { hasError }
92- isLoading = { isLoading }
93- refreshAll = { refreshAll }
94- notification = { notification }
95- setNotification = { setNotification }
96- >
97- < Viewer
98- currentView = { currentView }
99- selectedExecutable = { executable }
100- executableError = { executableError }
101- welcomeMessage = { welcomeMessage }
102- workspace = {
103- workspaces ?. find ( ( w ) => w . name === selectedWorkspace ) || null
104- }
105- />
106- </ AppShell >
107- ) ;
108- }
109-
11022function App ( ) {
11123 return (
11224 < QueryClientProvider client = { queryClient } >
11325 < NotifierProvider >
114- < SettingsProvider >
115- < ThemeProvider >
116- < AppContent />
117- </ ThemeProvider >
118- </ SettingsProvider >
26+ < AppProvider >
27+ < AppShell >
28+ < Switch >
29+ < Route path = "/" >
30+ < PageWrapper >
31+ < Welcome />
32+ </ PageWrapper >
33+ </ Route >
34+ < Route
35+ path = "/workspace/:workspaceName"
36+ component = { WorkspaceRoute }
37+ />
38+ < Route
39+ path = "/executable/:executableId"
40+ component = { ExecutableRoute }
41+ />
42+ < Route path = "/logs" >
43+ < PageWrapper >
44+ < Text > Logs view coming soon...</ Text >
45+ </ PageWrapper >
46+ </ Route >
47+ < Route path = "/vault" component = { Data } />
48+ < Route path = "/cache" component = { Data } />
49+ < Route path = "/settings" component = { Settings } />
50+ < Route >
51+ < PageWrapper >
52+ < Welcome welcomeMessage = "404: What you are looking for couldn't be found" />
53+ </ PageWrapper >
54+ </ Route >
55+ </ Switch >
56+ </ AppShell >
57+ </ AppProvider >
11958 </ NotifierProvider >
12059 </ QueryClientProvider >
12160 ) ;
0 commit comments