AFFiNE/apps/core/src/app.tsx

65 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-07-18 19:53:10 +03:00
import '@affine/component/theme/global.css';
import '@affine/component/theme/theme.css';
import { AffineContext } from '@affine/component/context';
import { WorkspaceFallback } from '@affine/component/workspace';
import { createI18n, setUpLanguage } from '@affine/i18n';
import { CacheProvider } from '@emotion/react';
2023-07-31 12:21:12 +03:00
import { use } from 'foxact/use';
2023-07-18 19:53:10 +03:00
import type { PropsWithChildren, ReactElement } from 'react';
2023-07-31 12:21:12 +03:00
import { lazy, memo, Suspense } from 'react';
import { RouterProvider } from 'react-router-dom';
2023-07-18 19:53:10 +03:00
import { router } from './router';
2023-07-18 19:53:10 +03:00
import createEmotionCache from './utils/create-emotion-cache';
const i18n = createI18n();
const cache = createEmotionCache();
const DevTools = lazy(() =>
import('jotai-devtools').then(m => ({ default: m.DevTools }))
);
const DebugProvider = ({ children }: PropsWithChildren): ReactElement => {
return (
<>
<Suspense>{process.env.DEBUG_JOTAI === 'true' && <DevTools />}</Suspense>
{children}
</>
);
};
const future = {
v7_startTransition: true,
} as const;
2023-07-31 12:21:12 +03:00
const languageLoadingPromise = new Promise<void>(resolve => {
if (environment.isBrowser) {
2023-07-18 19:53:10 +03:00
document.documentElement.lang = i18n.language;
2023-07-31 12:21:12 +03:00
setUpLanguage(i18n)
.then(() => resolve())
.catch(error => {
console.error(error);
});
} else {
resolve();
}
});
export const App = memo(function App() {
use(languageLoadingPromise);
2023-07-18 19:53:10 +03:00
return (
<CacheProvider value={cache}>
<AffineContext>
<DebugProvider>
<RouterProvider
fallbackElement={<WorkspaceFallback key="RouterFallback" />}
router={router}
future={future}
/>
2023-07-18 19:53:10 +03:00
</DebugProvider>
</AffineContext>
</CacheProvider>
);
});