2023-07-27 18:59:40 -04:00
|
|
|
import { App } from './App'
|
2023-08-10 13:30:32 -04:00
|
|
|
import {
|
|
|
|
createBrowserRouter,
|
2024-08-16 07:15:42 -04:00
|
|
|
createHashRouter,
|
2023-08-10 13:30:32 -04:00
|
|
|
Outlet,
|
|
|
|
redirect,
|
|
|
|
RouterProvider,
|
|
|
|
} from 'react-router-dom'
|
2023-07-27 18:59:40 -04:00
|
|
|
import { ErrorPage } from './components/ErrorPage'
|
|
|
|
import { Settings } from './routes/Settings'
|
2024-02-11 12:59:00 +11:00
|
|
|
import Onboarding, { onboardingRoutes } from './routes/Onboarding'
|
2023-07-27 18:59:40 -04:00
|
|
|
import SignIn from './routes/SignIn'
|
|
|
|
import { Auth } from './Auth'
|
2024-08-16 07:15:42 -04:00
|
|
|
import { isDesktop } from './lib/isDesktop'
|
2023-08-15 21:56:24 -04:00
|
|
|
import Home from './routes/Home'
|
2024-06-04 08:32:24 -04:00
|
|
|
import { NetworkContext } from './hooks/useNetworkContext'
|
|
|
|
import { useNetworkStatus } from './hooks/useNetworkStatus'
|
2023-08-15 21:56:24 -04:00
|
|
|
import makeUrlPathRelative from './lib/makeUrlPathRelative'
|
2024-03-14 15:56:45 -04:00
|
|
|
import DownloadAppBanner from 'components/DownloadAppBanner'
|
|
|
|
import { WasmErrBanner } from 'components/WasmErrBanner'
|
|
|
|
import { CommandBar } from 'components/CommandBar/CommandBar'
|
2023-10-11 13:36:54 +11:00
|
|
|
import ModelingMachineProvider from 'components/ModelingMachineProvider'
|
2023-10-16 13:28:41 -04:00
|
|
|
import FileMachineProvider from 'components/FileMachineProvider'
|
2024-10-25 19:28:10 -04:00
|
|
|
import { MachineManagerProvider } from 'components/MachineManagerProvider'
|
2024-08-09 02:47:25 -04:00
|
|
|
import { PATHS } from 'lib/paths'
|
2024-03-14 15:56:45 -04:00
|
|
|
import {
|
|
|
|
fileLoader,
|
|
|
|
homeLoader,
|
|
|
|
onboardingRedirectLoader,
|
2024-04-02 10:29:34 -04:00
|
|
|
settingsLoader,
|
2024-03-14 15:56:45 -04:00
|
|
|
} from 'lib/routeLoaders'
|
|
|
|
import { CommandBarProvider } from 'components/CommandBar/CommandBarProvider'
|
|
|
|
import SettingsAuthProvider from 'components/SettingsAuthProvider'
|
2024-03-11 17:50:31 -07:00
|
|
|
import LspProvider from 'components/LspProvider'
|
2024-03-22 16:55:30 +11:00
|
|
|
import { KclContextProvider } from 'lang/KclProvider'
|
2024-04-02 10:29:34 -04:00
|
|
|
import { BROWSER_PROJECT_NAME } from 'lib/constants'
|
2024-07-02 17:16:27 +10:00
|
|
|
import { CoreDumpManager } from 'lib/coredump'
|
2024-08-14 17:56:28 -07:00
|
|
|
import { codeManager, engineCommandManager } from 'lib/singletons'
|
2024-07-02 17:16:27 +10:00
|
|
|
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
|
|
|
|
import useHotkeyWrapper from 'lib/hotkeyWrapper'
|
|
|
|
import toast from 'react-hot-toast'
|
|
|
|
import { coreDump } from 'lang/wasm'
|
|
|
|
import { useMemo } from 'react'
|
2024-07-04 15:58:29 +10:00
|
|
|
import { AppStateProvider } from 'AppState'
|
2024-09-09 18:17:45 -04:00
|
|
|
import { reportRejection } from 'lib/trap'
|
2024-10-28 16:18:06 -04:00
|
|
|
import { ProjectsContextProvider } from 'components/ProjectsContextProvider'
|
2023-10-04 18:00:55 -04:00
|
|
|
|
2024-08-16 07:15:42 -04:00
|
|
|
const createRouter = isDesktop() ? createHashRouter : createBrowserRouter
|
|
|
|
|
|
|
|
const router = createRouter([
|
2024-03-14 15:56:45 -04:00
|
|
|
{
|
2024-04-02 10:29:34 -04:00
|
|
|
loader: settingsLoader,
|
2024-08-09 02:47:25 -04:00
|
|
|
id: PATHS.INDEX,
|
2024-10-25 19:28:10 -04:00
|
|
|
// TODO: Re-evaluate if this is true
|
2024-04-12 14:30:00 -07:00
|
|
|
/* Make sure auth is the outermost provider or else we will have
|
|
|
|
* inefficient re-renders, use the react profiler to see. */
|
2024-03-14 15:56:45 -04:00
|
|
|
element: (
|
|
|
|
<CommandBarProvider>
|
2024-04-12 14:30:00 -07:00
|
|
|
<SettingsAuthProvider>
|
|
|
|
<LspProvider>
|
2024-10-28 16:18:06 -04:00
|
|
|
<ProjectsContextProvider>
|
|
|
|
<KclContextProvider>
|
|
|
|
<AppStateProvider>
|
|
|
|
<MachineManagerProvider>
|
|
|
|
<Outlet />
|
|
|
|
</MachineManagerProvider>
|
|
|
|
</AppStateProvider>
|
|
|
|
</KclContextProvider>
|
|
|
|
</ProjectsContextProvider>
|
2024-04-12 14:30:00 -07:00
|
|
|
</LspProvider>
|
|
|
|
</SettingsAuthProvider>
|
2024-03-14 15:56:45 -04:00
|
|
|
</CommandBarProvider>
|
|
|
|
),
|
2024-04-02 10:29:34 -04:00
|
|
|
errorElement: <ErrorPage />,
|
2024-03-14 15:56:45 -04:00
|
|
|
children: [
|
|
|
|
{
|
2024-08-09 02:47:25 -04:00
|
|
|
path: PATHS.INDEX,
|
2024-04-25 05:52:08 -07:00
|
|
|
loader: async () => {
|
2024-08-16 07:15:42 -04:00
|
|
|
const onDesktop = isDesktop()
|
|
|
|
return onDesktop
|
2024-08-09 02:47:25 -04:00
|
|
|
? redirect(PATHS.HOME)
|
|
|
|
: redirect(PATHS.FILE + '/%2F' + BROWSER_PROJECT_NAME)
|
2024-04-25 05:52:08 -07:00
|
|
|
},
|
2024-03-14 15:56:45 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: fileLoader,
|
2024-08-09 02:47:25 -04:00
|
|
|
id: PATHS.FILE,
|
|
|
|
path: PATHS.FILE + '/:id',
|
2024-03-14 15:56:45 -04:00
|
|
|
element: (
|
2024-02-11 12:59:00 +11:00
|
|
|
<Auth>
|
|
|
|
<FileMachineProvider>
|
2023-10-16 13:28:41 -04:00
|
|
|
<ModelingMachineProvider>
|
2024-07-02 17:16:27 +10:00
|
|
|
<CoreDump />
|
2023-10-17 12:31:14 -04:00
|
|
|
<Outlet />
|
2023-10-16 13:28:41 -04:00
|
|
|
<App />
|
2024-02-23 11:24:22 -05:00
|
|
|
<CommandBar />
|
2024-08-16 07:15:42 -04:00
|
|
|
{
|
|
|
|
// @ts-ignore
|
|
|
|
!isDesktop() && import.meta.env.PROD && <DownloadAppBanner />
|
|
|
|
}
|
2023-10-16 13:28:41 -04:00
|
|
|
</ModelingMachineProvider>
|
2023-10-17 12:07:48 +11:00
|
|
|
<WasmErrBanner />
|
2024-02-11 12:59:00 +11:00
|
|
|
</FileMachineProvider>
|
|
|
|
</Auth>
|
2024-03-14 15:56:45 -04:00
|
|
|
),
|
|
|
|
children: [
|
|
|
|
{
|
2024-08-09 02:47:25 -04:00
|
|
|
id: PATHS.FILE + 'SETTINGS',
|
2024-04-02 10:29:34 -04:00
|
|
|
loader: settingsLoader,
|
2024-03-14 15:56:45 -04:00
|
|
|
children: [
|
2024-04-02 10:29:34 -04:00
|
|
|
{
|
|
|
|
loader: onboardingRedirectLoader,
|
|
|
|
index: true,
|
|
|
|
element: <></>,
|
|
|
|
},
|
2024-03-14 15:56:45 -04:00
|
|
|
{
|
2024-08-09 02:47:25 -04:00
|
|
|
path: makeUrlPathRelative(PATHS.SETTINGS),
|
2024-03-14 15:56:45 -04:00
|
|
|
element: <Settings />,
|
|
|
|
},
|
|
|
|
{
|
2024-08-09 02:47:25 -04:00
|
|
|
path: makeUrlPathRelative(PATHS.ONBOARDING.INDEX),
|
2024-03-14 15:56:45 -04:00
|
|
|
element: <Onboarding />,
|
|
|
|
children: onboardingRoutes,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2023-08-22 05:34:20 +10:00
|
|
|
},
|
2024-03-14 15:56:45 -04:00
|
|
|
{
|
2024-08-09 02:47:25 -04:00
|
|
|
path: PATHS.HOME,
|
2024-03-14 15:56:45 -04:00
|
|
|
element: (
|
|
|
|
<Auth>
|
|
|
|
<Outlet />
|
|
|
|
<Home />
|
|
|
|
<CommandBar />
|
|
|
|
</Auth>
|
|
|
|
),
|
2024-08-09 02:47:25 -04:00
|
|
|
id: PATHS.HOME,
|
2024-03-14 15:56:45 -04:00
|
|
|
loader: homeLoader,
|
|
|
|
children: [
|
2024-04-02 10:29:34 -04:00
|
|
|
{
|
|
|
|
index: true,
|
|
|
|
element: <></>,
|
2024-08-09 02:47:25 -04:00
|
|
|
id: PATHS.HOME + 'SETTINGS',
|
2024-04-02 10:29:34 -04:00
|
|
|
loader: settingsLoader,
|
|
|
|
},
|
2024-03-14 15:56:45 -04:00
|
|
|
{
|
2024-08-09 02:47:25 -04:00
|
|
|
path: makeUrlPathRelative(PATHS.SETTINGS),
|
2024-04-02 10:29:34 -04:00
|
|
|
loader: settingsLoader,
|
2024-03-14 15:56:45 -04:00
|
|
|
element: <Settings />,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2024-08-09 02:47:25 -04:00
|
|
|
path: PATHS.SIGN_IN,
|
2024-03-14 15:56:45 -04:00
|
|
|
element: <SignIn />,
|
2023-08-15 21:56:24 -04:00
|
|
|
},
|
2024-03-14 15:56:45 -04:00
|
|
|
],
|
|
|
|
},
|
|
|
|
])
|
2023-07-27 18:59:40 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* All routes in the app, used in src/index.tsx
|
|
|
|
* @returns RouterProvider
|
|
|
|
*/
|
|
|
|
export const Router = () => {
|
2024-06-04 08:32:24 -04:00
|
|
|
const networkStatus = useNetworkStatus()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<NetworkContext.Provider value={networkStatus}>
|
|
|
|
<RouterProvider router={router} />
|
|
|
|
</NetworkContext.Provider>
|
|
|
|
)
|
2023-07-27 18:59:40 -04:00
|
|
|
}
|
2024-07-02 17:16:27 +10:00
|
|
|
|
|
|
|
function CoreDump() {
|
|
|
|
const { auth } = useSettingsAuthContext()
|
|
|
|
const token = auth?.context?.token
|
|
|
|
const coreDumpManager = useMemo(
|
2024-08-14 17:56:28 -07:00
|
|
|
() => new CoreDumpManager(engineCommandManager, codeManager, token),
|
2024-07-02 17:16:27 +10:00
|
|
|
[]
|
|
|
|
)
|
2024-08-22 19:13:27 -04:00
|
|
|
useHotkeyWrapper(['mod + shift + .'], () => {
|
2024-09-09 18:17:45 -04:00
|
|
|
toast
|
|
|
|
.promise(
|
|
|
|
coreDump(coreDumpManager, true),
|
|
|
|
{
|
|
|
|
loading: 'Starting core dump...',
|
|
|
|
success: 'Core dump completed successfully',
|
|
|
|
error: 'Error while exporting core dump',
|
2024-07-02 17:16:27 +10:00
|
|
|
},
|
2024-09-09 18:17:45 -04:00
|
|
|
{
|
|
|
|
success: {
|
|
|
|
// Note: this extended duration is especially important for Playwright e2e testing
|
|
|
|
// default duration is 2000 - https://react-hot-toast.com/docs/toast#default-durations
|
|
|
|
duration: 6000,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.catch(reportRejection)
|
2024-07-02 17:16:27 +10:00
|
|
|
})
|
|
|
|
return null
|
|
|
|
}
|