2024-04-08 09:12:01 +00:00
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
2023-09-03 13:05:22 +00:00
|
|
|
import { useUserStore } from './store/user';
|
2023-09-04 17:18:43 +00:00
|
|
|
import { QueryClientProvider } from '@tanstack/react-query';
|
|
|
|
import { queryClient } from './api/cache';
|
2023-09-05 07:32:16 +00:00
|
|
|
import { TokenLoginContainer } from './components/TokenLoginContainer';
|
2024-02-17 16:47:22 +00:00
|
|
|
import React, { useRef } from 'react';
|
2023-09-27 09:56:32 +00:00
|
|
|
import { trpc, trpcClient } from './api/trpc';
|
2023-10-20 16:18:30 +00:00
|
|
|
import { useInjectWebsiteScript } from './hooks/useInjectWebsiteScript';
|
2024-04-19 16:21:26 +00:00
|
|
|
import { ConfigProvider } from 'antd';
|
2024-03-20 18:00:23 +00:00
|
|
|
import { RouterProvider, createRouter } from '@tanstack/react-router';
|
|
|
|
import { routeTree } from './routeTree.gen';
|
2024-03-25 12:10:01 +00:00
|
|
|
import { DefaultNotFound } from './components/DefaultNotFound';
|
2024-04-03 03:30:22 +00:00
|
|
|
import { TooltipProvider } from './components/ui/tooltip';
|
2024-04-03 07:36:02 +00:00
|
|
|
import { Toaster } from './components/ui/sonner';
|
2024-04-05 07:29:47 +00:00
|
|
|
import { DefaultError } from './components/DefaultError';
|
2024-04-19 16:21:26 +00:00
|
|
|
import { useAntdTheme } from './hooks/useTheme';
|
2024-03-20 18:00:23 +00:00
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
routeTree,
|
|
|
|
context: {
|
|
|
|
userInfo: undefined,
|
|
|
|
},
|
2024-03-25 12:10:01 +00:00
|
|
|
defaultNotFoundComponent: DefaultNotFound,
|
2024-04-05 07:29:47 +00:00
|
|
|
defaultErrorComponent: DefaultError,
|
2024-03-20 18:00:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Register the router instance for type safety
|
|
|
|
declare module '@tanstack/react-router' {
|
|
|
|
interface Register {
|
|
|
|
router: typeof router;
|
|
|
|
}
|
|
|
|
}
|
2023-09-05 07:32:16 +00:00
|
|
|
|
2024-04-08 16:02:28 +00:00
|
|
|
const AppRouter: React.FC = React.memo(() => {
|
|
|
|
const { info: userInfo } = useUserStore();
|
|
|
|
|
|
|
|
useInjectWebsiteScript();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BrowserRouter>
|
|
|
|
{/* Compatible with old routes */}
|
|
|
|
<TooltipProvider delayDuration={0}>
|
|
|
|
<RouterProvider router={router} context={{ userInfo }} />
|
|
|
|
</TooltipProvider>
|
|
|
|
|
2024-07-30 16:40:04 +00:00
|
|
|
<Toaster position="top-center" />
|
2024-04-08 16:02:28 +00:00
|
|
|
</BrowserRouter>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
AppRouter.displayName = 'AppRouter';
|
|
|
|
|
2023-09-05 07:32:16 +00:00
|
|
|
export const App: React.FC = React.memo(() => {
|
2024-01-07 16:01:49 +00:00
|
|
|
const rootRef = useRef<HTMLDivElement | null>(null);
|
2024-04-19 16:21:26 +00:00
|
|
|
const theme = useAntdTheme();
|
2024-04-08 09:12:01 +00:00
|
|
|
|
2023-08-31 13:17:57 +00:00
|
|
|
return (
|
2024-03-17 16:57:02 +00:00
|
|
|
<div ref={rootRef} className="App">
|
2023-09-27 09:56:32 +00:00
|
|
|
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
|
|
<QueryClientProvider client={queryClient}>
|
2024-03-20 18:00:23 +00:00
|
|
|
<ConfigProvider
|
2024-04-19 16:21:26 +00:00
|
|
|
theme={theme}
|
2024-03-20 18:00:23 +00:00
|
|
|
getPopupContainer={() => rootRef.current!}
|
|
|
|
>
|
|
|
|
<TokenLoginContainer>
|
2024-04-08 16:02:28 +00:00
|
|
|
<AppRouter />
|
2024-03-20 18:00:23 +00:00
|
|
|
</TokenLoginContainer>
|
|
|
|
</ConfigProvider>
|
2023-09-27 09:56:32 +00:00
|
|
|
</QueryClientProvider>
|
|
|
|
</trpc.Provider>
|
2023-08-31 13:17:57 +00:00
|
|
|
</div>
|
|
|
|
);
|
2023-09-05 07:32:16 +00:00
|
|
|
});
|
|
|
|
App.displayName = 'App';
|