refactor(core): remove adapter (#5324)
workspace adapter is no longer used.
This commit is contained in:
52
packages/common/env/src/workspace.ts
vendored
52
packages/common/env/src/workspace.ts
vendored
@@ -1,5 +1,3 @@
|
|||||||
import type { PropsWithChildren, ReactNode } from 'react';
|
|
||||||
|
|
||||||
export enum WorkspaceSubPath {
|
export enum WorkspaceSubPath {
|
||||||
ALL = 'all',
|
ALL = 'all',
|
||||||
Collection = 'collection',
|
Collection = 'collection',
|
||||||
@@ -8,18 +6,6 @@ export enum WorkspaceSubPath {
|
|||||||
SHARED = 'shared',
|
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 {
|
export enum WorkspaceFlavour {
|
||||||
/**
|
/**
|
||||||
* New AFFiNE Cloud Workspace using Nest.js Server.
|
* New AFFiNE Cloud Workspace using Nest.js Server.
|
||||||
@@ -27,41 +13,3 @@ export enum WorkspaceFlavour {
|
|||||||
AFFINE_CLOUD = 'affine-cloud',
|
AFFINE_CLOUD = 'affine-cloud',
|
||||||
LOCAL = 'local',
|
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;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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;
|
|
||||||
@@ -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,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -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,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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>;
|
|
||||||
};
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { WorkspaceMetadata } from '@affine/workspace/metadata';
|
import type { WorkspaceMetadata } from '@affine/workspace/metadata';
|
||||||
|
|
||||||
import { NewWorkspaceSettingDetail } from '../../../../adapters/shared';
|
|
||||||
import { useIsWorkspaceOwner } from '../../../../hooks/affine/use-is-workspace-owner';
|
import { useIsWorkspaceOwner } from '../../../../hooks/affine/use-is-workspace-owner';
|
||||||
|
import { WorkspaceSettingDetail } from '../../new-workspace-setting-detail';
|
||||||
|
|
||||||
export const WorkspaceSetting = ({
|
export const WorkspaceSetting = ({
|
||||||
workspaceMetadata,
|
workspaceMetadata,
|
||||||
@@ -10,7 +10,7 @@ export const WorkspaceSetting = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const isOwner = useIsWorkspaceOwner(workspaceMetadata);
|
const isOwner = useIsWorkspaceOwner(workspaceMetadata);
|
||||||
return (
|
return (
|
||||||
<NewWorkspaceSettingDetail
|
<WorkspaceSettingDetail
|
||||||
workspaceMetadata={workspaceMetadata}
|
workspaceMetadata={workspaceMetadata}
|
||||||
isOwner={isOwner}
|
isOwner={isOwner}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import { useLocation, useParams } from 'react-router-dom';
|
|||||||
import { Map as YMap } from 'yjs';
|
import { Map as YMap } from 'yjs';
|
||||||
|
|
||||||
import { openQuickSearchModalAtom, openSettingModalAtom } from '../atoms';
|
import { openQuickSearchModalAtom, openSettingModalAtom } from '../atoms';
|
||||||
import { AdapterProviderWrapper } from '../components/adapter-worksapce-wrapper';
|
|
||||||
import { AppContainer } from '../components/affine/app-container';
|
import { AppContainer } from '../components/affine/app-container';
|
||||||
import { SyncAwareness } from '../components/affine/awareness';
|
import { SyncAwareness } from '../components/affine/awareness';
|
||||||
import { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
|
import { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
|
||||||
@@ -41,6 +40,7 @@ import {
|
|||||||
AllWorkspaceModals,
|
AllWorkspaceModals,
|
||||||
CurrentWorkspaceModals,
|
CurrentWorkspaceModals,
|
||||||
} from '../providers/modal-provider';
|
} from '../providers/modal-provider';
|
||||||
|
import { SWRConfigProvider } from '../providers/swr-config-provider';
|
||||||
import { pathGenerator } from '../shared';
|
import { pathGenerator } from '../shared';
|
||||||
|
|
||||||
const CMDKQuickSearchModal = lazy(() =>
|
const CMDKQuickSearchModal = lazy(() =>
|
||||||
@@ -78,7 +78,7 @@ export const WorkspaceLayout = function WorkspaceLayout({
|
|||||||
children,
|
children,
|
||||||
}: PropsWithChildren) {
|
}: PropsWithChildren) {
|
||||||
return (
|
return (
|
||||||
<AdapterProviderWrapper>
|
<SWRConfigProvider>
|
||||||
{/* load all workspaces is costly, do not block the whole UI */}
|
{/* load all workspaces is costly, do not block the whole UI */}
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<AllWorkspaceModals />
|
<AllWorkspaceModals />
|
||||||
@@ -87,7 +87,7 @@ export const WorkspaceLayout = function WorkspaceLayout({
|
|||||||
<Suspense fallback={<WorkspaceFallback />}>
|
<Suspense fallback={<WorkspaceFallback />}>
|
||||||
<WorkspaceLayoutInner>{children}</WorkspaceLayoutInner>
|
<WorkspaceLayoutInner>{children}</WorkspaceLayoutInner>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</AdapterProviderWrapper>
|
</SWRConfigProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { useCallback } from 'react';
|
|||||||
import type { SWRConfiguration } from 'swr';
|
import type { SWRConfiguration } from 'swr';
|
||||||
import { SWRConfig } from 'swr';
|
import { SWRConfig } from 'swr';
|
||||||
|
|
||||||
const cloudConfig: SWRConfiguration = {
|
const swrConfig: SWRConfiguration = {
|
||||||
suspense: true,
|
suspense: true,
|
||||||
use: [
|
use: [
|
||||||
useSWRNext => (key, fetcher, config) => {
|
useSWRNext => (key, fetcher, config) => {
|
||||||
@@ -49,10 +49,6 @@ const cloudConfig: SWRConfiguration = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Provider = (props: PropsWithChildren): ReactNode => {
|
export const SWRConfigProvider = (props: PropsWithChildren): ReactNode => {
|
||||||
if (!runtimeConfig.enableCloud) {
|
return <SWRConfig value={swrConfig}>{props.children}</SWRConfig>;
|
||||||
return props.children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <SWRConfig value={cloudConfig}>{props.children}</SWRConfig>;
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user