metacubexd/src/App.tsx

61 lines
2.0 KiB
TypeScript
Raw Normal View History

import { Navigate, Route, Routes, useNavigate } from '@solidjs/router'
import { Show, createEffect, lazy, onMount } from 'solid-js'
2023-08-24 04:20:53 +08:00
import { Header } from '~/components/Header'
import { curTheme, endpoint, selectedEndpoint } from '~/signals'
2023-09-02 16:58:22 +08:00
import { ROUTE } from './config/enum'
2023-09-02 19:06:02 +08:00
import { useAutoSwitchTheme } from './signals/config'
import { useProxies } from './signals/proxies'
2023-08-24 04:20:53 +08:00
const Setup = lazy(() => import('~/pages/Setup'))
const Overview = lazy(() => import('~/pages/Overview'))
const Connections = lazy(() => import('~/pages/Connections'))
const Logs = lazy(() => import('~/pages/Logs'))
const Proxies = lazy(() => import('~/pages/Proxies'))
2023-09-02 16:58:22 +08:00
const ProxyProvider = lazy(() => import('~/pages/ProxyProvider'))
const Rules = lazy(() => import('~/pages/Rules'))
const Config = lazy(() => import('~/pages/Config'))
2023-08-24 04:20:53 +08:00
export const App = () => {
const navigate = useNavigate()
2023-09-02 19:06:02 +08:00
useAutoSwitchTheme()
createEffect(() => {
if (selectedEndpoint() && endpoint()) {
useProxies().updateProxy()
}
})
2023-09-02 16:58:22 +08:00
onMount(async () => {
2023-08-24 04:20:53 +08:00
if (!selectedEndpoint()) {
navigate('/setup')
}
})
return (
<div
2023-08-29 00:03:32 +08:00
class="relative flex h-screen flex-col subpixel-antialiased"
data-theme={curTheme()}
>
2023-08-27 22:25:41 +08:00
<Header />
2023-08-24 04:20:53 +08:00
<div class="flex-1 overflow-y-auto overflow-x-hidden p-2 sm:p-4">
2023-08-24 04:20:53 +08:00
<Routes>
<Show when={selectedEndpoint()}>
2023-09-02 16:58:22 +08:00
<Route path={ROUTE.Overview} component={Overview} />
<Route path={ROUTE.Proxies} component={Proxies} />
<Route path={ROUTE.Proxyprovider} component={ProxyProvider} />
<Route path={ROUTE.Rules} component={Rules} />
<Route path={ROUTE.Conns} component={Connections} />
<Route path={ROUTE.Log} component={Logs} />
<Route path={ROUTE.Config} component={Config} />
<Route path="*" element={<Navigate href={ROUTE.Overview} />} />
2023-08-24 04:20:53 +08:00
</Show>
<Route path="/setup" component={Setup} />
</Routes>
</div>
</div>
)
}