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';
|
2023-07-24 12:02:35 +03:00
|
|
|
import { RouterProvider } from 'react-router-dom';
|
2023-07-18 19:53:10 +03:00
|
|
|
|
2023-07-24 12:02:35 +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}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-07-24 12:02:35 +03:00
|
|
|
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>
|
2023-07-24 12:02:35 +03:00
|
|
|
<RouterProvider
|
|
|
|
fallbackElement={<WorkspaceFallback key="RouterFallback" />}
|
|
|
|
router={router}
|
|
|
|
future={future}
|
|
|
|
/>
|
2023-07-18 19:53:10 +03:00
|
|
|
</DebugProvider>
|
|
|
|
</AffineContext>
|
|
|
|
</CacheProvider>
|
|
|
|
);
|
|
|
|
});
|