2023-07-18 19:53:10 +03:00
|
|
|
import '@affine/component/theme/global.css';
|
|
|
|
import '@affine/component/theme/theme.css';
|
2023-08-05 02:11:30 +03:00
|
|
|
import '@toeverything/components/style.css';
|
2023-07-18 19:53:10 +03:00
|
|
|
|
|
|
|
import { AffineContext } from '@affine/component/context';
|
|
|
|
import { WorkspaceFallback } from '@affine/component/workspace';
|
|
|
|
import { CacheProvider } from '@emotion/react';
|
2023-08-18 22:50:35 +03:00
|
|
|
import { getCurrentStore } from '@toeverything/infra/atom';
|
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 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-08-04 02:05:46 +03:00
|
|
|
async function loadLanguage() {
|
2023-07-31 12:21:12 +03:00
|
|
|
if (environment.isBrowser) {
|
2023-08-04 02:05:46 +03:00
|
|
|
const { createI18n, setUpLanguage } = await import('@affine/i18n');
|
|
|
|
const i18n = createI18n();
|
2023-07-18 19:53:10 +03:00
|
|
|
document.documentElement.lang = i18n.language;
|
2023-08-04 02:05:46 +03:00
|
|
|
await setUpLanguage(i18n);
|
2023-07-31 12:21:12 +03:00
|
|
|
}
|
2023-08-04 02:05:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const languageLoadingPromise = loadLanguage().catch(console.error);
|
2023-07-31 12:21:12 +03:00
|
|
|
|
|
|
|
export const App = memo(function App() {
|
|
|
|
use(languageLoadingPromise);
|
2023-07-18 19:53:10 +03:00
|
|
|
return (
|
|
|
|
<CacheProvider value={cache}>
|
2023-08-18 22:50:35 +03:00
|
|
|
<AffineContext store={getCurrentStore()}>
|
2023-07-18 19:53:10 +03:00
|
|
|
<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>
|
|
|
|
);
|
|
|
|
});
|