mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor: ui adapter (#2577)
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton';
|
||||
import type { BlockSuiteFeatureFlags } from '@affine/env';
|
||||
import { config } from '@affine/env';
|
||||
import { Unreachable } from '@affine/env/constant';
|
||||
import { rootCurrentPageIdAtom } from '@affine/workspace/atom';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
@@ -13,7 +11,7 @@ import { useRouter } from 'next/router';
|
||||
import type React from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../../../adapters/workspace';
|
||||
import { getUIAdapter } from '../../../adapters/workspace';
|
||||
import { rootCurrentWorkspaceAtom } from '../../../atoms/root';
|
||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||
import { useSyncRecentViewsWithRouter } from '../../../hooks/use-recent-views';
|
||||
@@ -57,28 +55,15 @@ const WorkspaceDetail: React.FC = () => {
|
||||
setEditorFlags(currentWorkspace.blockSuiteWorkspace);
|
||||
}
|
||||
}, [currentWorkspace]);
|
||||
if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) {
|
||||
const PageDetail =
|
||||
WorkspaceAdapters[currentWorkspace.flavour].UI.PageDetail;
|
||||
return (
|
||||
<PageDetail
|
||||
currentWorkspace={currentWorkspace}
|
||||
currentPageId={currentPageId}
|
||||
onLoadEditor={onLoad}
|
||||
/>
|
||||
);
|
||||
} else if (currentWorkspace.flavour === WorkspaceFlavour.LOCAL) {
|
||||
const PageDetail =
|
||||
WorkspaceAdapters[currentWorkspace.flavour].UI.PageDetail;
|
||||
return (
|
||||
<PageDetail
|
||||
currentWorkspace={currentWorkspace}
|
||||
currentPageId={currentPageId}
|
||||
onLoadEditor={onLoad}
|
||||
/>
|
||||
);
|
||||
}
|
||||
throw new Unreachable();
|
||||
|
||||
const { PageDetail } = getUIAdapter(currentWorkspace.flavour);
|
||||
return (
|
||||
<PageDetail
|
||||
currentWorkspace={currentWorkspace}
|
||||
currentPageId={currentPageId}
|
||||
onLoadEditor={onLoad}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const WorkspaceDetailPage: NextPageWithLayout = () => {
|
||||
|
||||
@@ -6,16 +6,15 @@ import {
|
||||
ViewList,
|
||||
} from '@affine/component/page-list';
|
||||
import { config } from '@affine/env';
|
||||
import { QueryParamError, Unreachable } from '@affine/env/constant';
|
||||
import { QueryParamError } from '@affine/env/constant';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { FolderIcon } from '@blocksuite/icons';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
import Head from 'next/head';
|
||||
import { useRouter } from 'next/router';
|
||||
import React, { useCallback } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../../../adapters/workspace';
|
||||
import { getUIAdapter } from '../../../adapters/workspace';
|
||||
import { PageLoading } from '../../../components/pure/loading';
|
||||
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||
@@ -78,58 +77,31 @@ const AllPage: NextPageWithLayout = () => {
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) {
|
||||
const PageList = WorkspaceAdapters[currentWorkspace.flavour].UI.PageList;
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{t['All pages']()} - AFFiNE</title>
|
||||
</Head>
|
||||
<WorkspaceTitle
|
||||
workspace={currentWorkspace}
|
||||
currentPage={null}
|
||||
isPreview={false}
|
||||
isPublic={false}
|
||||
icon={<FolderIcon />}
|
||||
leftSlot={leftSlot}
|
||||
>
|
||||
{t['All pages']()}
|
||||
</WorkspaceTitle>
|
||||
{filterContainer}
|
||||
<PageList
|
||||
view={setting.currentView}
|
||||
onOpenPage={onClickPage}
|
||||
blockSuiteWorkspace={currentWorkspace.blockSuiteWorkspace}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
} else if (currentWorkspace.flavour === WorkspaceFlavour.LOCAL) {
|
||||
const PageList = WorkspaceAdapters[currentWorkspace.flavour].UI.PageList;
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{t['All pages']()} - AFFiNE</title>
|
||||
</Head>
|
||||
<WorkspaceTitle
|
||||
workspace={currentWorkspace}
|
||||
currentPage={null}
|
||||
isPreview={false}
|
||||
isPublic={false}
|
||||
icon={<FolderIcon />}
|
||||
leftSlot={leftSlot}
|
||||
>
|
||||
{t['All pages']()}
|
||||
</WorkspaceTitle>
|
||||
{filterContainer}
|
||||
<PageList
|
||||
view={setting.currentView}
|
||||
onOpenPage={onClickPage}
|
||||
blockSuiteWorkspace={currentWorkspace.blockSuiteWorkspace}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
throw new Unreachable();
|
||||
|
||||
const { PageList } = getUIAdapter(currentWorkspace.flavour);
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{t['All pages']()} - AFFiNE</title>
|
||||
</Head>
|
||||
<WorkspaceTitle
|
||||
workspace={currentWorkspace}
|
||||
currentPage={null}
|
||||
isPreview={false}
|
||||
isPublic={false}
|
||||
icon={<FolderIcon />}
|
||||
leftSlot={leftSlot}
|
||||
>
|
||||
{t['All pages']()}
|
||||
</WorkspaceTitle>
|
||||
{filterContainer}
|
||||
<PageList
|
||||
view={setting.currentView}
|
||||
onOpenPage={onClickPage}
|
||||
blockSuiteWorkspace={currentWorkspace.blockSuiteWorkspace}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default AllPage;
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { Unreachable } from '@affine/env/constant';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom';
|
||||
import type { SettingPanel } from '@affine/workspace/type';
|
||||
import {
|
||||
settingPanel,
|
||||
settingPanelValues,
|
||||
WorkspaceFlavour,
|
||||
} from '@affine/workspace/type';
|
||||
import { settingPanel, settingPanelValues } from '@affine/workspace/type';
|
||||
import { SettingsIcon } from '@blocksuite/icons';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
@@ -16,7 +11,7 @@ import type { NextRouter } from 'next/router';
|
||||
import { useRouter } from 'next/router';
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../../../adapters/workspace';
|
||||
import { getUIAdapter } from '../../../adapters/workspace';
|
||||
import { PageLoading } from '../../../components/pure/loading';
|
||||
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||
@@ -119,60 +114,31 @@ const SettingPage: NextPageWithLayout = () => {
|
||||
return <PageLoading />;
|
||||
} else if (settingPanelValues.indexOf(currentTab as SettingPanel) === -1) {
|
||||
return <PageLoading />;
|
||||
} else if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) {
|
||||
const Setting =
|
||||
WorkspaceAdapters[currentWorkspace.flavour].UI.SettingsDetail;
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{t['Settings']()} - AFFiNE</title>
|
||||
</Head>
|
||||
<WorkspaceTitle
|
||||
workspace={currentWorkspace}
|
||||
currentPage={null}
|
||||
isPreview={false}
|
||||
isPublic={false}
|
||||
icon={<SettingsIcon />}
|
||||
>
|
||||
{t['Workspace Settings']()}
|
||||
</WorkspaceTitle>
|
||||
<Setting
|
||||
onTransformWorkspace={onTransformWorkspace}
|
||||
onDeleteWorkspace={onDeleteWorkspace}
|
||||
currentWorkspace={currentWorkspace}
|
||||
currentTab={currentTab as SettingPanel}
|
||||
onChangeTab={onChangeTab}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
} else if (currentWorkspace.flavour === WorkspaceFlavour.LOCAL) {
|
||||
const Setting =
|
||||
WorkspaceAdapters[currentWorkspace.flavour].UI.SettingsDetail;
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{t['Settings']()} - AFFiNE</title>
|
||||
</Head>
|
||||
<WorkspaceTitle
|
||||
workspace={currentWorkspace}
|
||||
currentPage={null}
|
||||
isPreview={false}
|
||||
isPublic={false}
|
||||
icon={<SettingsIcon />}
|
||||
>
|
||||
{t['Workspace Settings']()}
|
||||
</WorkspaceTitle>
|
||||
<Setting
|
||||
onTransformWorkspace={onTransformWorkspace}
|
||||
onDeleteWorkspace={onDeleteWorkspace}
|
||||
currentWorkspace={currentWorkspace}
|
||||
currentTab={currentTab as SettingPanel}
|
||||
onChangeTab={onChangeTab}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
throw new Unreachable();
|
||||
const { SettingsDetail } = getUIAdapter(currentWorkspace.flavour);
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>{t['Settings']()} - AFFiNE</title>
|
||||
</Head>
|
||||
<WorkspaceTitle
|
||||
workspace={currentWorkspace}
|
||||
currentPage={null}
|
||||
isPreview={false}
|
||||
isPublic={false}
|
||||
icon={<SettingsIcon />}
|
||||
>
|
||||
{t['Workspace Settings']()}
|
||||
</WorkspaceTitle>
|
||||
<SettingsDetail
|
||||
onTransformWorkspace={onTransformWorkspace}
|
||||
onDeleteWorkspace={onDeleteWorkspace}
|
||||
currentWorkspace={currentWorkspace}
|
||||
currentTab={currentTab as SettingPanel}
|
||||
onChangeTab={onChangeTab}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SettingPage;
|
||||
|
||||
Reference in New Issue
Block a user