refactor: add AppRouter to make sure useUserStore run under trpc provider

This commit is contained in:
moonrailgun 2024-04-09 00:02:28 +08:00
parent 62cc934035
commit 2c5ff71725
2 changed files with 20 additions and 12 deletions

View File

@ -31,14 +31,29 @@ declare module '@tanstack/react-router' {
}
}
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>
<Toaster />
</BrowserRouter>
);
});
AppRouter.displayName = 'AppRouter';
export const App: React.FC = React.memo(() => {
const rootRef = useRef<HTMLDivElement | null>(null);
const colorScheme = useColorSchema();
const algorithm =
colorScheme === 'dark' ? theme.darkAlgorithm : theme.defaultAlgorithm;
const { info: userInfo } = useUserStore();
useInjectWebsiteScript();
return (
<div ref={rootRef} className="App">
@ -49,14 +64,7 @@ export const App: React.FC = React.memo(() => {
getPopupContainer={() => rootRef.current!}
>
<TokenLoginContainer>
{/* Compatible with old routes */}
<BrowserRouter>
<TooltipProvider delayDuration={0}>
<RouterProvider router={router} context={{ userInfo }} />
</TooltipProvider>
<Toaster />
</BrowserRouter>
<AppRouter />
</TokenLoginContainer>
</ConfigProvider>
</QueryClientProvider>

View File

@ -10,7 +10,7 @@ export const useSettingsStore = create<SettingsState>()(
persist(
() =>
({
colorScheme: 'light' as const,
colorScheme: 'dark' as const,
}) as SettingsState,
{
name: 'settings',