diff --git a/apps/web/src/components/pure/loading/page-loading.tsx b/apps/web/src/components/pure/loading/page-loading.tsx index c62ab1084e..3823adc704 100644 --- a/apps/web/src/components/pure/loading/page-loading.tsx +++ b/apps/web/src/components/pure/loading/page-loading.tsx @@ -1,6 +1,5 @@ import { styled } from '@affine/component'; import { AffineLoading } from '@affine/component/affine-loading'; -import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { memo, Suspense } from 'react'; export const Loading = memo(function Loading() { @@ -35,12 +34,15 @@ const StyledLoadingContainer = styled('div')(() => { }; }); -export const PageLoading = ({ text }: { text?: string }) => { - const t = useAFFiNEI18N(); +export const PageLoading = () => { + // We disable the loading on desktop, because want it looks faster. + // This is a design requirement. + if (environment.isDesktop) { + return null; + } return ( -

{text ? text : t['Loading']()}

); }; diff --git a/apps/web/src/layouts/workspace-layout.tsx b/apps/web/src/layouts/workspace-layout.tsx index b5b1eb7e0c..f2f2b1739d 100644 --- a/apps/web/src/layouts/workspace-layout.tsx +++ b/apps/web/src/layouts/workspace-layout.tsx @@ -2,12 +2,12 @@ import { AppContainer, MainContainer, ToolContainer, + WorkspaceFallback, } from '@affine/component/workspace'; import { DebugLogger } from '@affine/debug'; import { DEFAULT_HELLO_WORLD_PAGE_ID } from '@affine/env'; import { initPage } from '@affine/env/blocksuite'; import { setUpLanguage, useI18N } from '@affine/i18n'; -import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { createAffineGlobalChannel } from '@affine/workspace/affine/sync'; import { rootCurrentPageIdAtom, @@ -31,7 +31,6 @@ import { publicWorkspaceIdAtom, } from '../atoms/public-workspace'; import { HelpIsland } from '../components/pure/help-island'; -import { PageLoading } from '../components/pure/loading'; import { RootAppSidebar } from '../components/root-app-sidebar'; import { useCurrentWorkspace } from '../hooks/current/use-current-workspace'; import { useRouterHelper } from '../hooks/use-router-helper'; @@ -141,15 +140,14 @@ export const CurrentWorkspaceContext = ({ useRouterWithWorkspaceIdDefense(router); const metadata = useAtomValue(rootWorkspacesMetadataAtom); const exist = metadata.find(m => m.id === workspaceId); - const t = useAFFiNEI18N(); if (!router.isReady) { - return ; + return ; } if (!workspaceId) { - return ; + return ; } if (!exist) { - return ; + return ; } return <>{children}; }; @@ -157,7 +155,6 @@ export const CurrentWorkspaceContext = ({ export const WorkspaceLayout: FC = function WorkspacesSuspense({ children }) { const i18n = useI18N(); - const t = useAFFiNEI18N(); useEffect(() => { document.documentElement.lang = i18n.language; // todo(himself65): this is a hack, we should use a better way to set the language @@ -233,9 +230,7 @@ export const WorkspaceLayout: FC = - } - > + }> {children} @@ -251,7 +246,6 @@ export const WorkspaceLayoutInner: FC = ({ children }) => { const currentPageId = useAtomValue(rootCurrentPageIdAtom); const router = useRouter(); const { jumpToPage } = useRouterHelper(router); - const t = useAFFiNEI18N(); //#region init workspace if (currentWorkspace.blockSuiteWorkspace.isEmpty) { @@ -360,9 +354,7 @@ export const WorkspaceLayoutInner: FC = ({ children }) => { paths={isPublicWorkspace ? publicPathGenerator : pathGenerator} /> - }> - {children} - + }>{children} {/* fixme(himself65): remove this */}
diff --git a/apps/web/src/pages/_app.tsx b/apps/web/src/pages/_app.tsx index a51f64afb7..d7817ef7d7 100644 --- a/apps/web/src/pages/_app.tsx +++ b/apps/web/src/pages/_app.tsx @@ -1,6 +1,7 @@ import '@affine/component/theme/global.css'; import '@affine/component/theme/theme.css'; +import { WorkspaceFallback } from '@affine/component/workspace'; import { config, setupGlobal } from '@affine/env'; import { createI18n, I18nextProvider } from '@affine/i18n'; import { rootStore } from '@affine/workspace/atom'; @@ -15,7 +16,6 @@ import React, { lazy, Suspense, useEffect, useMemo } from 'react'; import { AffineErrorBoundary } from '../components/affine/affine-error-eoundary'; import { ProviderComposer } from '../components/provider-composer'; -import { PageLoading } from '../components/pure/loading'; import { MessageCenter } from '../components/pure/message-center'; import { ThemeProvider } from '../providers/theme-provider'; import type { NextPageWithLayout } from '../shared'; @@ -66,7 +66,7 @@ const App = function App({ - }> + }> diff --git a/apps/web/src/pages/index.tsx b/apps/web/src/pages/index.tsx index 368f9ba258..40a72052b5 100644 --- a/apps/web/src/pages/index.tsx +++ b/apps/web/src/pages/index.tsx @@ -1,5 +1,4 @@ import { DebugLogger } from '@affine/debug'; -import { useAFFiNEI18N } from '@affine/i18n/hooks'; import type { NextPage } from 'next'; import { useRouter } from 'next/router'; import { Suspense, useEffect } from 'react'; @@ -63,9 +62,8 @@ const IndexPageInner = () => { }; const IndexPage: NextPage = () => { - const t = useAFFiNEI18N(); return ( - }> + }> ); diff --git a/apps/web/src/plugins/affine/index.tsx b/apps/web/src/plugins/affine/index.tsx index 22305bbd5e..3ec7ef5f7b 100644 --- a/apps/web/src/plugins/affine/index.tsx +++ b/apps/web/src/plugins/affine/index.tsx @@ -84,9 +84,7 @@ function AuthContext({ children }: PropsWithChildren): ReactElement { } }, [login]); if (!login) { - return ( - - ); + return ; } return <>{children}; } @@ -278,7 +276,7 @@ export const AffinePlugin: WorkspacePlugin = { UI: { Provider: ({ children }) => { return ( - }> + }> {children} ); diff --git a/packages/component/src/components/app-sidebar/fallback.css.ts b/packages/component/src/components/app-sidebar/fallback.css.ts new file mode 100644 index 0000000000..8a38d29eb1 --- /dev/null +++ b/packages/component/src/components/app-sidebar/fallback.css.ts @@ -0,0 +1,15 @@ +import { style } from '@vanilla-extract/css'; + +export const fallbackStyle = style({ + margin: '0 2px', + height: '100%', +}); + +export const fallbackHeaderStyle = style({ + padding: '0 6px', + height: '58px', + width: '100%', + display: 'flex', + flexDirection: 'row', + gap: '8px', +}); diff --git a/packages/component/src/components/app-sidebar/fallback.tsx b/packages/component/src/components/app-sidebar/fallback.tsx new file mode 100644 index 0000000000..652ee3756e --- /dev/null +++ b/packages/component/src/components/app-sidebar/fallback.tsx @@ -0,0 +1,18 @@ +import { Skeleton } from '@mui/material'; +import type { ReactElement } from 'react'; + +import { fallbackHeaderStyle, fallbackStyle } from './fallback.css'; +import { AppSidebar } from './index'; + +export const AppSidebarFallback = (): ReactElement | null => { + return ( + +
+
+ + +
+
+
+ ); +}; diff --git a/packages/component/src/components/app-sidebar/index.stories.tsx b/packages/component/src/components/app-sidebar/index.stories.tsx index e7854e9954..7b2c0fb5b9 100644 --- a/packages/component/src/components/app-sidebar/index.stories.tsx +++ b/packages/component/src/components/app-sidebar/index.stories.tsx @@ -2,9 +2,15 @@ import { IconButton } from '@affine/component'; import { SidebarIcon } from '@blocksuite/icons'; import type { Meta, StoryFn } from '@storybook/react'; import { useAtom } from 'jotai'; +import type { PropsWithChildren } from 'react'; import { useState } from 'react'; -import { AppSidebar, appSidebarOpenAtom, ResizeIndicator } from '.'; +import { + AppSidebar, + AppSidebarFallback, + appSidebarOpenAtom, + ResizeIndicator, +} from '.'; import { navHeaderStyle, sidebarButtonStyle } from './index.css'; export default { @@ -12,42 +18,61 @@ export default { component: AppSidebar, } satisfies Meta; +const Container = ({ children }: PropsWithChildren) => ( +
+ {children} +
+); +const Main = () => { + const [open, setOpen] = useAtom(appSidebarOpenAtom); + return ( +
+
+ {!open && ( + { + setOpen(true); + }} + > + + + )} +
+
+ ); +}; const Footer = () =>
Add Page
; export const Default: StoryFn = () => { - const [open, setOpen] = useAtom(appSidebarOpenAtom); const [ref, setRef] = useState(null); return ( <> -
+ } ref={setRef}> Test -
-
- {!open && ( - { - setOpen(true); - }} - > - - - )} -
-
-
+
+ ); }; + +export const Fallback = () => { + return ( + + +
+ + ); +}; diff --git a/packages/component/src/components/app-sidebar/index.tsx b/packages/component/src/components/app-sidebar/index.tsx index cb0df5e360..db3d807a54 100644 --- a/packages/component/src/components/app-sidebar/index.tsx +++ b/packages/component/src/components/app-sidebar/index.tsx @@ -151,5 +151,6 @@ export const AppSidebar = forwardRef( } ); +export { AppSidebarFallback } from './fallback'; export type { ResizeIndicatorProps } from './resize-indicator'; export { ResizeIndicator } from './resize-indicator'; diff --git a/packages/component/src/components/block-suite-editor/index.css.ts b/packages/component/src/components/block-suite-editor/index.css.ts index a3b38b41d5..3b7bd0186d 100644 --- a/packages/component/src/components/block-suite-editor/index.css.ts +++ b/packages/component/src/components/block-suite-editor/index.css.ts @@ -1,5 +1,12 @@ import { style } from '@vanilla-extract/css'; export const blockSuiteEditorStyle = style({ - padding: '0 1rem', + maxWidth: 'var(--affine-editor-width)', + margin: '0 2rem', + padding: '0 24px', +}); + +export const blockSuiteEditorHeaderStyle = style({ + marginTop: '40px', + marginBottom: '40px', }); diff --git a/packages/component/src/components/block-suite-editor/index.tsx b/packages/component/src/components/block-suite-editor/index.tsx index eef7dea7e0..0d437d328c 100644 --- a/packages/component/src/components/block-suite-editor/index.tsx +++ b/packages/component/src/components/block-suite-editor/index.tsx @@ -12,7 +12,10 @@ import { createPortal } from 'react-dom'; import type { FallbackProps } from 'react-error-boundary'; import { ErrorBoundary } from 'react-error-boundary'; -import { blockSuiteEditorStyle } from './index.css'; +import { + blockSuiteEditorHeaderStyle, + blockSuiteEditorStyle, +} from './index.css'; export type EditorProps = { page: Page; @@ -136,10 +139,11 @@ const BlockSuiteErrorFallback = ( export const BlockSuiteFallback = memo(function BlockSuiteFallback() { return (
- - {Array.from({ length: 10 }).map((_, index) => ( - - ))} +
); diff --git a/packages/component/src/components/workspace/index.tsx b/packages/component/src/components/workspace/index.tsx index 876bf3707f..83ffd3326c 100644 --- a/packages/component/src/components/workspace/index.tsx +++ b/packages/component/src/components/workspace/index.tsx @@ -1,6 +1,7 @@ import { clsx } from 'clsx'; import type { PropsWithChildren, ReactElement } from 'react'; +import { AppSidebarFallback } from '../app-sidebar'; import { appStyle, mainContainerStyle, toolStyle } from './index.css'; export type WorkspaceRootProps = PropsWithChildren<{ @@ -32,3 +33,12 @@ export const MainContainer = (props: MainContainerProps): ReactElement => { export const ToolContainer = (props: PropsWithChildren): ReactElement => { return
{props.children}
; }; + +export const WorkspaceFallback = (): ReactElement => { + return ( + + + + + ); +};