refactor: rootWorkspacesMetadataAtom loading logic (#2882)

This commit is contained in:
Alex Yang
2023-06-29 16:48:12 +08:00
parent df7f782e05
commit f7b07f4216
22 changed files with 436 additions and 353 deletions

View File

@@ -5,14 +5,14 @@ import '../bootstrap';
import { AffineContext } from '@affine/component/context';
import { WorkspaceFallback } from '@affine/component/workspace';
import { createI18n, I18nextProvider } from '@affine/i18n';
import { createI18n, I18nextProvider, setUpLanguage } from '@affine/i18n';
import type { EmotionCache } from '@emotion/cache';
import { CacheProvider } from '@emotion/react';
import type { AppProps } from 'next/app';
import Head from 'next/head';
import { useRouter } from 'next/router';
import type { PropsWithChildren, ReactElement } from 'react';
import React, { lazy, Suspense } from 'react';
import React, { lazy, Suspense, useEffect } from 'react';
import { AffineErrorBoundary } from '../components/affine/affine-error-eoundary';
import { MessageCenter } from '../components/pure/message-center';
@@ -49,6 +49,13 @@ const App = function App({
}: AppPropsWithLayout & {
emotionCache?: EmotionCache;
}) {
useEffect(() => {
document.documentElement.lang = i18n.language;
// todo(himself65): this is a hack, we should use a better way to set the language
setUpLanguage(i18n)?.catch(error => {
console.error(error);
});
}, []);
const getLayout = Component.getLayout || EmptyLayout;
return (
@@ -56,20 +63,20 @@ const App = function App({
<I18nextProvider i18n={i18n}>
<MessageCenter />
<AffineErrorBoundary router={useRouter()}>
<Suspense fallback={<WorkspaceFallback key="RootPageLoading" />}>
<AffineContext>
<Head>
<title>AFFiNE</title>
<meta
name="viewport"
content="initial-scale=1, width=device-width"
/>
</Head>
<DebugProvider>
<AffineContext>
<Head>
<title>AFFiNE</title>
<meta
name="viewport"
content="initial-scale=1, width=device-width"
/>
</Head>
<DebugProvider>
<Suspense fallback={<WorkspaceFallback key="RootPageLoading" />}>
{getLayout(<Component {...pageProps} />)}
</DebugProvider>
</AffineContext>
</Suspense>
</Suspense>
</DebugProvider>
</AffineContext>
</AffineErrorBoundary>
</I18nextProvider>
</CacheProvider>