mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
refactor: rename plugins to adapters (#2480)
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { AFFINE_STORAGE_KEY, config, prefixUrl } from '@affine/env';
|
||||
import { AFFINE_STORAGE_KEY, config } from '@affine/env';
|
||||
import { initPage } from '@affine/env/blocksuite';
|
||||
import { PageNotFoundError } from '@affine/env/constant';
|
||||
import { currentAffineUserAtom } from '@affine/workspace/affine/atom';
|
||||
import {
|
||||
clearLoginStorage,
|
||||
createAffineAuth,
|
||||
getLoginStorage,
|
||||
isExpired,
|
||||
parseIdToken,
|
||||
@@ -37,9 +36,9 @@ import { PageDetailEditor } from '../../components/page-detail-editor';
|
||||
import { PageLoading } from '../../components/pure/loading';
|
||||
import { useAffineRefreshAuthToken } from '../../hooks/affine/use-affine-refresh-auth-token';
|
||||
import { BlockSuiteWorkspace } from '../../shared';
|
||||
import { affineApis } from '../../shared/apis';
|
||||
import { affineApis, affineAuth } from '../../shared/apis';
|
||||
import { toast } from '../../utils';
|
||||
import type { WorkspaceAdapter } from '..';
|
||||
import type { WorkspaceAdapter } from '../type';
|
||||
import { QueryKey } from './fetcher';
|
||||
|
||||
const storage = createJSONStorage(() => localStorage);
|
||||
@@ -79,8 +78,6 @@ const getPersistenceAllWorkspace = () => {
|
||||
return allWorkspaces;
|
||||
};
|
||||
|
||||
export const affineAuth = createAffineAuth(prefixUrl);
|
||||
|
||||
function AuthContext({ children }: PropsWithChildren): ReactElement {
|
||||
const login = useAffineRefreshAuthToken();
|
||||
|
||||
@@ -17,12 +17,31 @@ import {
|
||||
} from '@affine/workspace/type';
|
||||
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
|
||||
import { nanoid } from '@blocksuite/store';
|
||||
import React from 'react';
|
||||
import { lazy } from 'react';
|
||||
|
||||
import { WorkspaceSettingDetail } from '../../components/affine/workspace-setting-detail';
|
||||
import { BlockSuitePageList } from '../../components/blocksuite/block-suite-page-list';
|
||||
import { PageDetailEditor } from '../../components/page-detail-editor';
|
||||
import type { WorkspaceAdapter } from '..';
|
||||
import type { WorkspaceAdapter } from '../type';
|
||||
|
||||
const WorkspaceSettingDetail = lazy(() =>
|
||||
import('../../components/affine/workspace-setting-detail').then(
|
||||
({ WorkspaceSettingDetail }) => ({
|
||||
default: WorkspaceSettingDetail,
|
||||
})
|
||||
)
|
||||
);
|
||||
const BlockSuitePageList = lazy(() =>
|
||||
import('../../components/blocksuite/block-suite-page-list').then(
|
||||
({ BlockSuitePageList }) => ({
|
||||
default: BlockSuitePageList,
|
||||
})
|
||||
)
|
||||
);
|
||||
const PageDetailEditor = lazy(() =>
|
||||
import('../../components/page-detail-editor').then(
|
||||
({ PageDetailEditor }) => ({
|
||||
default: PageDetailEditor,
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const logger = new DebugLogger('use-create-first-workspace');
|
||||
|
||||
21
apps/web/src/adapters/type.tsx
Normal file
21
apps/web/src/adapters/type.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import type {
|
||||
AppEvents,
|
||||
WorkspaceCRUD,
|
||||
WorkspaceUISchema,
|
||||
} from '@affine/workspace/type';
|
||||
import type {
|
||||
LoadPriority,
|
||||
ReleaseType,
|
||||
WorkspaceFlavour,
|
||||
} from '@affine/workspace/type';
|
||||
|
||||
export interface WorkspaceAdapter<Flavour extends WorkspaceFlavour> {
|
||||
releaseType: ReleaseType;
|
||||
flavour: Flavour;
|
||||
// Plugin will be loaded according to the priority
|
||||
loadPriority: LoadPriority;
|
||||
Events: Partial<AppEvents>;
|
||||
// Fetch necessary data for the first render
|
||||
CRUD: WorkspaceCRUD<Flavour>;
|
||||
UI: WorkspaceUISchema<Flavour>;
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
import type {
|
||||
AppEvents,
|
||||
WorkspaceCRUD,
|
||||
WorkspaceUISchema,
|
||||
} from '@affine/workspace/type';
|
||||
import type { AppEvents } from '@affine/workspace/type';
|
||||
import {
|
||||
LoadPriority,
|
||||
ReleaseType,
|
||||
@@ -11,17 +7,7 @@ import {
|
||||
|
||||
import { AffinePlugin } from './affine';
|
||||
import { LocalPlugin } from './local';
|
||||
|
||||
export interface WorkspaceAdapter<Flavour extends WorkspaceFlavour> {
|
||||
releaseType: ReleaseType;
|
||||
flavour: Flavour;
|
||||
// Plugin will be loaded according to the priority
|
||||
loadPriority: LoadPriority;
|
||||
Events: Partial<AppEvents>;
|
||||
// Fetch necessary data for the first render
|
||||
CRUD: WorkspaceCRUD<Flavour>;
|
||||
UI: WorkspaceUISchema<Flavour>;
|
||||
}
|
||||
import type { WorkspaceAdapter } from './type';
|
||||
|
||||
const unimplemented = () => {
|
||||
throw new Error('Not implemented');
|
||||
@@ -19,7 +19,7 @@ import type { Page } from '@blocksuite/store';
|
||||
import { createStore } from 'jotai';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { WorkspaceAdapters } from '../../plugins';
|
||||
import { WorkspaceAdapters } from '../../adapters/workspace';
|
||||
import { rootCurrentWorkspaceAtom } from '../root';
|
||||
|
||||
describe('currentWorkspace atom', () => {
|
||||
|
||||
@@ -11,8 +11,8 @@ import type { Page } from '@blocksuite/store';
|
||||
import { atom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
|
||||
import { WorkspaceAdapters } from '../adapters/workspace';
|
||||
import type { CreateWorkspaceMode } from '../components/affine/create-workspace-modal';
|
||||
import { WorkspaceAdapters } from '../plugins';
|
||||
|
||||
const logger = new DebugLogger('web:atoms');
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
import { atom } from 'jotai';
|
||||
|
||||
import { WorkspaceAdapters } from '../plugins';
|
||||
import type { AllWorkspace } from '../shared';
|
||||
|
||||
const logger = new DebugLogger('web:atoms:root');
|
||||
@@ -22,6 +21,7 @@ const logger = new DebugLogger('web:atoms:root');
|
||||
* Fetch all workspaces from the Plugin CRUD
|
||||
*/
|
||||
export const workspacesAtom = atom<Promise<AllWorkspace[]>>(async get => {
|
||||
const { WorkspaceAdapters } = await import('../adapters/workspace');
|
||||
const flavours: string[] = Object.values(WorkspaceAdapters).map(
|
||||
plugin => plugin.flavour
|
||||
);
|
||||
@@ -82,6 +82,7 @@ export const workspacesAtom = atom<Promise<AllWorkspace[]>>(async get => {
|
||||
*/
|
||||
export const rootCurrentWorkspaceAtom = atom<Promise<AllWorkspace>>(
|
||||
async get => {
|
||||
const { WorkspaceAdapters } = await import('../adapters/workspace');
|
||||
const metadata = get(rootWorkspacesMetadataAtom);
|
||||
const targetId = get(rootCurrentWorkspaceIdAtom);
|
||||
if (targetId === null) {
|
||||
|
||||
@@ -6,8 +6,8 @@ import type React from 'react';
|
||||
import { Suspense, useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import { preload } from 'swr';
|
||||
|
||||
import { fetcher, QueryKey } from '../../../adapters/affine/fetcher';
|
||||
import { useIsWorkspaceOwner } from '../../../hooks/affine/use-is-workspace-owner';
|
||||
import { fetcher, QueryKey } from '../../../plugins/affine/fetcher';
|
||||
import type { AffineOfficialWorkspace } from '../../../shared';
|
||||
import * as style from './index.css';
|
||||
import { CollaborationPanel } from './panel/collaboration';
|
||||
|
||||
@@ -19,8 +19,8 @@ import React, { useEffect, useState } from 'react';
|
||||
|
||||
import { useCurrentWorkspace } from '../../../../hooks/current/use-current-workspace';
|
||||
import { useTransformWorkspace } from '../../../../hooks/use-transform-workspace';
|
||||
import { affineAuth } from '../../../../plugins/affine';
|
||||
import type { AffineOfficialWorkspace } from '../../../../shared';
|
||||
import { affineAuth } from '../../../../shared/apis';
|
||||
import { TransformWorkspaceToAffineModal } from '../../../affine/transform-workspace-to-affine-modal';
|
||||
|
||||
const IconWrapper = styled('div')(() => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import type React from 'react';
|
||||
import { memo, useEffect, useState } from 'react';
|
||||
|
||||
import { useAffineLogOut } from '../../../hooks/affine/use-affine-log-out';
|
||||
import { affineAuth } from '../../../plugins/affine';
|
||||
import { affineAuth } from '../../../shared/apis';
|
||||
import { toast } from '../../../utils';
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -44,7 +44,6 @@ beforeAll(() => {
|
||||
`/workspace/[workspaceId/${WorkspaceSubPath.ALL}`,
|
||||
`/workspace/[workspaceId/${WorkspaceSubPath.SETTING}`,
|
||||
`/workspace/[workspaceId/${WorkspaceSubPath.TRASH}`,
|
||||
`/workspace/[workspaceId/${WorkspaceSubPath.FAVORITE}`,
|
||||
'/workspace/[workspaceId]/[pageId]',
|
||||
])
|
||||
);
|
||||
|
||||
@@ -11,14 +11,15 @@ import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { createStore, Provider } from 'jotai/index';
|
||||
import { createStore, Provider } from 'jotai';
|
||||
import { useRouter } from 'next/router';
|
||||
import routerMock from 'next-router-mock';
|
||||
import { createDynamicRouteParser } from 'next-router-mock/dynamic-routes';
|
||||
import type { FC, PropsWithChildren } from 'react';
|
||||
import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { LocalPlugin } from '../../adapters/local';
|
||||
import { workspacesAtom } from '../../atoms';
|
||||
import { LocalPlugin } from '../../plugins/local';
|
||||
import { BlockSuiteWorkspace } from '../../shared';
|
||||
import { WorkspaceSubPath } from '../../shared';
|
||||
import {
|
||||
@@ -37,7 +38,6 @@ beforeAll(() => {
|
||||
`/workspace/[workspaceId/${WorkspaceSubPath.ALL}`,
|
||||
`/workspace/[workspaceId/${WorkspaceSubPath.SETTING}`,
|
||||
`/workspace/[workspaceId/${WorkspaceSubPath.TRASH}`,
|
||||
`/workspace/[workspaceId/${WorkspaceSubPath.FAVORITE}`,
|
||||
'/workspace/[workspaceId]/[pageId]',
|
||||
])
|
||||
);
|
||||
@@ -45,10 +45,11 @@ beforeAll(() => {
|
||||
|
||||
async function getJotaiContext() {
|
||||
const store = createStore();
|
||||
const ProviderWrapper: React.FC<React.PropsWithChildren> =
|
||||
function ProviderWrapper({ children }) {
|
||||
return <Provider store={store}>{children}</Provider>;
|
||||
};
|
||||
const ProviderWrapper: FC<PropsWithChildren> = function ProviderWrapper({
|
||||
children,
|
||||
}) {
|
||||
return <Provider store={store}>{children}</Provider>;
|
||||
};
|
||||
const workspaces = await store.get(workspacesAtom);
|
||||
expect(workspaces.length).toBe(0);
|
||||
return {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../../plugins';
|
||||
import { WorkspaceAdapters } from '../../adapters/workspace';
|
||||
|
||||
export function useAffineLogIn() {
|
||||
const router = useRouter();
|
||||
|
||||
@@ -2,7 +2,7 @@ import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../../plugins';
|
||||
import { WorkspaceAdapters } from '../../adapters/workspace';
|
||||
|
||||
export function useAffineLogOut() {
|
||||
const router = useRouter();
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from '@affine/workspace/affine/login';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { affineAuth } from '../../plugins/affine';
|
||||
import { affineAuth } from '../../shared/apis';
|
||||
|
||||
const logger = new DebugLogger('auth-token');
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Member } from '@affine/workspace/affine/api';
|
||||
import { useCallback } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { QueryKey } from '../../plugins/affine/fetcher';
|
||||
import { QueryKey } from '../../adapters/affine/fetcher';
|
||||
import { affineApis } from '../../shared/apis';
|
||||
|
||||
export function useMembers(workspaceId: string) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { AffineLegacyCloudWorkspace } from '@affine/workspace/type';
|
||||
import { useCallback } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { QueryKey } from '../../plugins/affine/fetcher';
|
||||
import { QueryKey } from '../../adapters/affine/fetcher';
|
||||
import { affineApis } from '../../shared/apis';
|
||||
|
||||
export function useToggleWorkspacePublish(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { QueryKey } from '../../plugins/affine/fetcher';
|
||||
import { QueryKey } from '../../adapters/affine/fetcher';
|
||||
|
||||
export interface QueryEmailMember {
|
||||
id: string;
|
||||
|
||||
@@ -12,7 +12,7 @@ import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { affineAuth } from '../../plugins/affine';
|
||||
import { affineAuth } from '../../shared/apis';
|
||||
import { useTransformWorkspace } from '../use-transform-workspace';
|
||||
|
||||
export function useOnTransformWorkspace() {
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { WorkspaceRegistry } from '@affine/workspace/type';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../plugins';
|
||||
import { WorkspaceAdapters } from '../adapters/workspace';
|
||||
|
||||
/**
|
||||
* Transform workspace from one flavour to another
|
||||
|
||||
@@ -8,9 +8,9 @@ import { nanoid } from '@blocksuite/store';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { LocalPlugin } from '../adapters/local';
|
||||
import { WorkspaceAdapters } from '../adapters/workspace';
|
||||
import { workspacesAtom } from '../atoms';
|
||||
import { WorkspaceAdapters } from '../plugins';
|
||||
import { LocalPlugin } from '../plugins/local';
|
||||
import type { AllWorkspace } from '../shared';
|
||||
|
||||
export function useWorkspaces(): AllWorkspace[] {
|
||||
|
||||
@@ -26,6 +26,7 @@ import { useRouter } from 'next/router';
|
||||
import type { FC, PropsWithChildren, ReactElement } from 'react';
|
||||
import { lazy, Suspense, useCallback, useEffect, useMemo } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../adapters/workspace';
|
||||
import { openQuickSearchModalAtom, openWorkspacesModalAtom } from '../atoms';
|
||||
import { useTrackRouterHistoryEffect } from '../atoms/history';
|
||||
import {
|
||||
@@ -38,7 +39,6 @@ import { useCurrentWorkspace } from '../hooks/current/use-current-workspace';
|
||||
import { useRouterHelper } from '../hooks/use-router-helper';
|
||||
import { useRouterTitle } from '../hooks/use-router-title';
|
||||
import { useWorkspaces } from '../hooks/use-workspaces';
|
||||
import { WorkspaceAdapters } from '../plugins';
|
||||
import { ModalProvider } from '../providers/modal-provider';
|
||||
import { pathGenerator, publicPathGenerator } from '../shared';
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import { useRouter } from 'next/router';
|
||||
import { Suspense } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { QueryKey } from '../../adapters/affine/fetcher';
|
||||
import { PageLoading } from '../../components/pure/loading';
|
||||
import { RouteLogic, useRouterHelper } from '../../hooks/use-router-helper';
|
||||
import { QueryKey } from '../../plugins/affine/fetcher';
|
||||
import type { NextPageWithLayout } from '../../shared';
|
||||
import { WorkspaceSubPath } from '../../shared';
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { useRouter } from 'next/router';
|
||||
import type React from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../../../adapters/workspace';
|
||||
import { rootCurrentWorkspaceAtom } from '../../../atoms/root';
|
||||
import { useReferenceLinkEffect } from '../../../hooks/affine/use-reference-link-effect';
|
||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||
@@ -22,7 +23,6 @@ import { usePinboardHandler } from '../../../hooks/use-pinboard-handler';
|
||||
import { useSyncRecentViewsWithRouter } from '../../../hooks/use-recent-views';
|
||||
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||
import { WorkspaceLayout } from '../../../layouts/workspace-layout';
|
||||
import { WorkspaceAdapters } from '../../../plugins';
|
||||
import type { BlockSuiteWorkspace, NextPageWithLayout } from '../../../shared';
|
||||
|
||||
function setEditorFlags(blockSuiteWorkspace: BlockSuiteWorkspace) {
|
||||
|
||||
@@ -7,12 +7,12 @@ import Head from 'next/head';
|
||||
import { useRouter } from 'next/router';
|
||||
import React, { useCallback } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../../../adapters/workspace';
|
||||
import { PageLoading } from '../../../components/pure/loading';
|
||||
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||
import { WorkspaceLayout } from '../../../layouts/workspace-layout';
|
||||
import { WorkspaceAdapters } from '../../../plugins';
|
||||
import type { NextPageWithLayout } from '../../../shared';
|
||||
|
||||
const AllPage: NextPageWithLayout = () => {
|
||||
|
||||
@@ -16,13 +16,13 @@ import type { NextRouter } from 'next/router';
|
||||
import { useRouter } from 'next/router';
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
|
||||
import { WorkspaceAdapters } from '../../../adapters/workspace';
|
||||
import { PageLoading } from '../../../components/pure/loading';
|
||||
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||
import { useOnTransformWorkspace } from '../../../hooks/root/use-on-transform-workspace';
|
||||
import { useAppHelper } from '../../../hooks/use-workspaces';
|
||||
import { WorkspaceLayout } from '../../../layouts/workspace-layout';
|
||||
import { WorkspaceAdapters } from '../../../plugins';
|
||||
import type { NextPageWithLayout } from '../../../shared';
|
||||
import { toast } from '../../../utils';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { memo } from 'react';
|
||||
import type { SWRConfiguration } from 'swr';
|
||||
import { SWRConfig } from 'swr';
|
||||
|
||||
import { fetcher } from '../plugins/affine/fetcher';
|
||||
import { fetcher } from '../adapters/affine/fetcher';
|
||||
|
||||
const config: SWRConfiguration = {
|
||||
suspense: true,
|
||||
|
||||
@@ -6,9 +6,14 @@ import {
|
||||
} from '@affine/workspace/affine/api';
|
||||
import { currentAffineUserAtom } from '@affine/workspace/affine/atom';
|
||||
import type { LoginResponse } from '@affine/workspace/affine/login';
|
||||
import { parseIdToken, setLoginStorage } from '@affine/workspace/affine/login';
|
||||
import {
|
||||
createAffineAuth,
|
||||
parseIdToken,
|
||||
setLoginStorage,
|
||||
} from '@affine/workspace/affine/login';
|
||||
import { rootStore } from '@affine/workspace/atom';
|
||||
|
||||
export const affineAuth = createAffineAuth(prefixUrl);
|
||||
const affineApis = {} as ReturnType<typeof createUserApis> &
|
||||
ReturnType<typeof createWorkspaceApis>;
|
||||
Object.assign(affineApis, createUserApis(prefixUrl));
|
||||
|
||||
Reference in New Issue
Block a user