refactor: abstract workspace provider (#1809)
This commit is contained in:
@@ -10,14 +10,13 @@ import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import dynamic from 'next/dynamic';
|
||||
import Head from 'next/head';
|
||||
import { useRouter } from 'next/router';
|
||||
import type React from 'react';
|
||||
import type { FC, PropsWithChildren } from 'react';
|
||||
import { Suspense, useCallback, useEffect } from 'react';
|
||||
|
||||
import {
|
||||
currentWorkspaceIdAtom,
|
||||
openQuickSearchModalAtom,
|
||||
openWorkspacesModalAtom,
|
||||
workspaceLockAtom,
|
||||
} from '../atoms';
|
||||
import {
|
||||
publicBlockSuiteAtom,
|
||||
@@ -63,7 +62,7 @@ const QuickSearchModal = dynamic(
|
||||
() => import('../components/pure/quick-search-modal')
|
||||
);
|
||||
|
||||
export const PublicQuickSearch: React.FC = () => {
|
||||
export const PublicQuickSearch: FC = () => {
|
||||
const blockSuiteWorkspace = useAtomValue(publicBlockSuiteAtom);
|
||||
const router = useRouter();
|
||||
const [openQuickSearchModal, setOpenQuickSearchModalAtom] = useAtom(
|
||||
@@ -79,7 +78,11 @@ export const PublicQuickSearch: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export const QuickSearch: React.FC = () => {
|
||||
function DefaultProvider({ children }: PropsWithChildren) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
export const QuickSearch: FC = () => {
|
||||
const [currentWorkspace] = useCurrentWorkspace();
|
||||
const router = useRouter();
|
||||
const [openQuickSearchModal, setOpenQuickSearchModalAtom] = useAtom(
|
||||
@@ -110,7 +113,7 @@ const logger = new DebugLogger('workspace-layout');
|
||||
const affineGlobalChannel = createAffineGlobalChannel(
|
||||
WorkspacePlugins[WorkspaceFlavour.AFFINE].CRUD
|
||||
);
|
||||
export const WorkspaceLayout: React.FC<React.PropsWithChildren> =
|
||||
export const WorkspaceLayout: FC<PropsWithChildren> =
|
||||
function WorkspacesSuspense({ children }) {
|
||||
const { i18n } = useTranslation();
|
||||
useEffect(() => {
|
||||
@@ -180,9 +183,7 @@ function AffineWorkspaceEffect() {
|
||||
return null;
|
||||
}
|
||||
|
||||
export const WorkspaceLayoutInner: React.FC<React.PropsWithChildren> = ({
|
||||
children,
|
||||
}) => {
|
||||
export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
|
||||
const [currentWorkspace] = useCurrentWorkspace();
|
||||
const [currentPageId] = useCurrentPageId();
|
||||
const workspaces = useWorkspaces();
|
||||
@@ -260,7 +261,6 @@ export const WorkspaceLayoutInner: React.FC<React.PropsWithChildren> = ({
|
||||
setOpenQuickSearchModalAtom(true);
|
||||
}, [setOpenQuickSearchModalAtom]);
|
||||
const [resizingSidebar, setIsResizing] = useSidebarResizing();
|
||||
const lock = useAtomValue(workspaceLockAtom);
|
||||
const [sidebarOpen, setSidebarOpen] = useSidebarStatus();
|
||||
const sidebarFloating = useSidebarFloating();
|
||||
const [sidebarWidth, setSliderWidth] = useSidebarWidth();
|
||||
@@ -291,12 +291,16 @@ export const WorkspaceLayoutInner: React.FC<React.PropsWithChildren> = ({
|
||||
);
|
||||
}, [setIsResizing, setSidebarOpen, setSliderWidth]);
|
||||
|
||||
if (lock) {
|
||||
return <PageLoading />;
|
||||
}
|
||||
const Provider = currentWorkspace
|
||||
? WorkspacePlugins[currentWorkspace.flavour].UI.Provider
|
||||
: DefaultProvider;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Provider
|
||||
key={`${
|
||||
currentWorkspace ? currentWorkspace.flavour : 'default'
|
||||
}-provider`}
|
||||
>
|
||||
<Head>
|
||||
<title>{title}</title>
|
||||
</Head>
|
||||
@@ -353,6 +357,6 @@ export const WorkspaceLayoutInner: React.FC<React.PropsWithChildren> = ({
|
||||
</MainContainerWrapper>
|
||||
</StyledPage>
|
||||
<QuickSearch />
|
||||
</>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user