diff --git a/app/client/web/src/App.tsx b/app/client/web/src/App.tsx
index c9140d97..e963a087 100644
--- a/app/client/web/src/App.tsx
+++ b/app/client/web/src/App.tsx
@@ -1,6 +1,7 @@
import React from 'react'
import { Root } from './root/Root'
import { Access } from './access/Access'
+import { Node } from './node/Node'
import { Session } from './session/Session'
import { useColorScheme } from '@mantine/hooks'
import { createTheme, MantineProvider, virtualColor } from '@mantine/core'
@@ -57,9 +58,15 @@ const theme = createTheme({
})
const router = createBrowserRouter([
- { path: '/', element: },
- { path: 'access', element: },
- { path: 'session', element: },
+ {
+ element: ,
+ children: [
+ { path: '/', element: <>> },
+ { path: 'access', element: },
+ { path: 'session', element: },
+ { path: 'node', element: },
+ ],
+ }
])
export function App() {
@@ -67,7 +74,7 @@ export function App() {
const defaultScheme = useColorScheme('light', {
getInitialValueInEffect: false,
})
- const scheme = selectedScheme ? selectedScheme : defaultScheme
+ const scheme = selectedScheme === 'light' ? 'light' : selectedScheme === 'dark' ? 'dark' : defaultScheme
return (
diff --git a/app/client/web/src/context/useAppContext.hook.ts b/app/client/web/src/context/useAppContext.hook.ts
index 7cd946af..98efa958 100644
--- a/app/client/web/src/context/useAppContext.hook.ts
+++ b/app/client/web/src/context/useAppContext.hook.ts
@@ -18,7 +18,6 @@ export function useAppContext() {
const sdk = new DatabagSDK(null)
const store = new SessionStore()
const session: Session | null = await sdk.initOnlineStore(store)
- console.log(session)
if (session) {
updateState({ sdk, session })
} else {
diff --git a/app/client/web/src/node/Node.tsx b/app/client/web/src/node/Node.tsx
new file mode 100644
index 00000000..e8732df5
--- /dev/null
+++ b/app/client/web/src/node/Node.tsx
@@ -0,0 +1,9 @@
+import React from 'react'
+
+export function Node() {
+ return (
+
+ Node
+
+ )
+}
diff --git a/app/client/web/src/root/Root.tsx b/app/client/web/src/root/Root.tsx
index afe17c87..064f973a 100644
--- a/app/client/web/src/root/Root.tsx
+++ b/app/client/web/src/root/Root.tsx
@@ -1,33 +1,12 @@
import React from 'react'
import { TextInput, Button } from '@mantine/core'
-import { useMantineTheme } from '@mantine/core'
+import { useRoot } from './useRoot.hook'
+import { Outlet } from 'react-router-dom'
export function Root() {
- const theme = useMantineTheme()
-
- const press = () => {
- console.log('PRESSED')
- }
+ const { state, actions } = useRoot()
return (
-
-
ROOT
-
-
-
-
+
)
}
diff --git a/app/client/web/src/root/useRoot.hook.ts b/app/client/web/src/root/useRoot.hook.ts
new file mode 100644
index 00000000..22e02cd6
--- /dev/null
+++ b/app/client/web/src/root/useRoot.hook.ts
@@ -0,0 +1,45 @@
+import { useState, useContext, useEffect } from 'react'
+import { AppContext } from '../context/AppContext'
+import { ContextType } from '../context/ContextType'
+import { useLocation, useNavigate } from "react-router-dom";
+
+export function useRoot() {
+ const app = useContext(AppContext) as ContextType
+ const location = useLocation();
+ const navigate = useNavigate();
+ const [ state, setState ] = useState({
+ pathname: '',
+ })
+
+ const updateState = (value: any) => {
+ setState((s) => ({ ...s, ...value }))
+ }
+
+ useEffect(() => {
+ const { pathname } = location;
+ updateState({ pathname });
+ }, [location.pathname]);
+
+ useEffect(() => {
+ if (state.pathname === '/session' && !app.state.session) {
+ navigate('/');
+ }
+ else if (state.pathname === '/node' && !app.state.node) {
+ navigate('/');
+ }
+ else if (state.pathname === '/' && !app.state.session && !app.state.node) {
+ navigate('/access');
+ }
+ else if (state.pathname !== '/node' && app.state.node) {
+ navigate('/node');
+ }
+ else if (state.pathname !== '/session' && app.state.session) {
+ navigate('/session');
+ }
+ }, [state.pathname, app.state.session, app.state.node]);
+
+ const actions = {};
+
+ return { state, actions };
+}
+