refactor(core): remove adapter (#5324)

workspace adapter is no longer used.
This commit is contained in:
EYHN
2023-12-25 03:34:22 +00:00
parent 05025bf59a
commit e1bd13a018
9 changed files with 8 additions and 160 deletions

View File

@@ -1,5 +1,3 @@
import type { PropsWithChildren, ReactNode } from 'react';
export enum WorkspaceSubPath {
ALL = 'all',
Collection = 'collection',
@@ -8,18 +6,6 @@ export enum WorkspaceSubPath {
SHARED = 'shared',
}
export enum ReleaseType {
// if workspace is not released yet, we will not show it in the workspace list
UNRELEASED = 'unreleased',
STABLE = 'stable',
}
export enum LoadPriority {
HIGH = 1,
MEDIUM = 2,
LOW = 3,
}
export enum WorkspaceFlavour {
/**
* New AFFiNE Cloud Workspace using Nest.js Server.
@@ -27,41 +13,3 @@ export enum WorkspaceFlavour {
AFFINE_CLOUD = 'affine-cloud',
LOCAL = 'local',
}
export const settingPanel = {
General: 'general',
Collaboration: 'collaboration',
Publish: 'publish',
Export: 'export',
Sync: 'sync',
} as const;
export const settingPanelValues = Object.values(settingPanel);
export type SettingPanel = (typeof settingPanel)[keyof typeof settingPanel];
export type WorkspaceHeaderProps = {
rightSlot?: ReactNode;
currentEntry:
| {
subPath: WorkspaceSubPath;
}
| {
pageId: string;
};
};
interface FC<P> {
(props: P): ReactNode;
}
export interface WorkspaceUISchema {
Provider: FC<PropsWithChildren>;
LoginCard?: FC<object>;
}
export interface WorkspaceAdapter<Flavour extends WorkspaceFlavour> {
releaseType: ReleaseType;
flavour: Flavour;
// The Adapter will be loaded according to the priority
loadPriority: LoadPriority;
UI: WorkspaceUISchema;
}

View File

@@ -1,15 +0,0 @@
import type { WorkspaceUISchema } from '@affine/env/workspace';
import { lazy } from 'react';
import { Provider } from '../shared';
const LoginCard = lazy(() =>
import('../../components/cloud/login-card').then(({ LoginCard }) => ({
default: LoginCard,
}))
);
export const UI = {
Provider,
LoginCard,
} satisfies WorkspaceUISchema;

View File

@@ -1,17 +0,0 @@
import type { WorkspaceAdapter } from '@affine/env/workspace';
import {
LoadPriority,
ReleaseType,
WorkspaceFlavour,
} from '@affine/env/workspace';
import { Provider } from '../shared';
export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
releaseType: ReleaseType.STABLE,
flavour: WorkspaceFlavour.LOCAL,
loadPriority: LoadPriority.LOW,
UI: {
Provider,
},
};

View File

@@ -1,15 +0,0 @@
import { lazy } from 'react';
export const Provider = lazy(() =>
import('../components/cloud/provider').then(({ Provider }) => ({
default: Provider,
}))
);
export const NewWorkspaceSettingDetail = lazy(() =>
import('../components/affine/new-workspace-setting-detail').then(
({ WorkspaceSettingDetail }) => ({
default: WorkspaceSettingDetail,
})
)
);

View File

@@ -1,35 +0,0 @@
import { Unreachable } from '@affine/env/constant';
import type {
WorkspaceAdapter,
WorkspaceUISchema,
} from '@affine/env/workspace';
import {
LoadPriority,
ReleaseType,
WorkspaceFlavour,
} from '@affine/env/workspace';
import { UI as CloudUI } from './cloud/ui';
import { LocalAdapter } from './local';
export const WorkspaceAdapters = {
[WorkspaceFlavour.LOCAL]: LocalAdapter,
[WorkspaceFlavour.AFFINE_CLOUD]: {
releaseType: ReleaseType.UNRELEASED,
flavour: WorkspaceFlavour.AFFINE_CLOUD,
loadPriority: LoadPriority.HIGH,
UI: CloudUI,
},
} satisfies {
[Key in WorkspaceFlavour]: WorkspaceAdapter<Key>;
};
export function getUIAdapter<Flavour extends WorkspaceFlavour>(
flavour: Flavour
): WorkspaceUISchema {
const ui = WorkspaceAdapters[flavour].UI as WorkspaceUISchema;
if (!ui) {
throw new Unreachable();
}
return ui;
}

View File

@@ -1,14 +0,0 @@
import { waitForCurrentWorkspaceAtom } from '@affine/workspace/atom';
import { assertExists } from '@blocksuite/global/utils';
import { useAtomValue } from 'jotai';
import type { FC, PropsWithChildren } from 'react';
import { WorkspaceAdapters } from '../adapters/workspace';
export const AdapterProviderWrapper: FC<PropsWithChildren> = ({ children }) => {
const currentWorkspace = useAtomValue(waitForCurrentWorkspaceAtom);
const Provider = WorkspaceAdapters[currentWorkspace.flavour].UI.Provider;
assertExists(Provider);
return <Provider>{children}</Provider>;
};

View File

@@ -1,7 +1,7 @@
import type { WorkspaceMetadata } from '@affine/workspace/metadata';
import { NewWorkspaceSettingDetail } from '../../../../adapters/shared';
import { useIsWorkspaceOwner } from '../../../../hooks/affine/use-is-workspace-owner';
import { WorkspaceSettingDetail } from '../../new-workspace-setting-detail';
export const WorkspaceSetting = ({
workspaceMetadata,
@@ -10,7 +10,7 @@ export const WorkspaceSetting = ({
}) => {
const isOwner = useIsWorkspaceOwner(workspaceMetadata);
return (
<NewWorkspaceSettingDetail
<WorkspaceSettingDetail
workspaceMetadata={workspaceMetadata}
isOwner={isOwner}
/>

View File

@@ -27,7 +27,6 @@ import { useLocation, useParams } from 'react-router-dom';
import { Map as YMap } from 'yjs';
import { openQuickSearchModalAtom, openSettingModalAtom } from '../atoms';
import { AdapterProviderWrapper } from '../components/adapter-worksapce-wrapper';
import { AppContainer } from '../components/affine/app-container';
import { SyncAwareness } from '../components/affine/awareness';
import { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
@@ -41,6 +40,7 @@ import {
AllWorkspaceModals,
CurrentWorkspaceModals,
} from '../providers/modal-provider';
import { SWRConfigProvider } from '../providers/swr-config-provider';
import { pathGenerator } from '../shared';
const CMDKQuickSearchModal = lazy(() =>
@@ -78,7 +78,7 @@ export const WorkspaceLayout = function WorkspaceLayout({
children,
}: PropsWithChildren) {
return (
<AdapterProviderWrapper>
<SWRConfigProvider>
{/* load all workspaces is costly, do not block the whole UI */}
<Suspense>
<AllWorkspaceModals />
@@ -87,7 +87,7 @@ export const WorkspaceLayout = function WorkspaceLayout({
<Suspense fallback={<WorkspaceFallback />}>
<WorkspaceLayoutInner>{children}</WorkspaceLayoutInner>
</Suspense>
</AdapterProviderWrapper>
</SWRConfigProvider>
);
};

View File

@@ -7,7 +7,7 @@ import { useCallback } from 'react';
import type { SWRConfiguration } from 'swr';
import { SWRConfig } from 'swr';
const cloudConfig: SWRConfiguration = {
const swrConfig: SWRConfiguration = {
suspense: true,
use: [
useSWRNext => (key, fetcher, config) => {
@@ -49,10 +49,6 @@ const cloudConfig: SWRConfiguration = {
],
};
export const Provider = (props: PropsWithChildren): ReactNode => {
if (!runtimeConfig.enableCloud) {
return props.children;
}
return <SWRConfig value={cloudConfig}>{props.children}</SWRConfig>;
export const SWRConfigProvider = (props: PropsWithChildren): ReactNode => {
return <SWRConfig value={swrConfig}>{props.children}</SWRConfig>;
};