mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
refactor: init package @affine/workspace (#1661)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Button, toast } from '@affine/component';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
|
||||
import { nanoid } from '@blocksuite/store';
|
||||
import { Typography } from '@mui/material';
|
||||
import type React from 'react';
|
||||
@@ -9,7 +10,6 @@ import { createBroadCastChannelProvider } from '../../blocksuite/providers';
|
||||
import PageList from '../../components/blocksuite/block-suite-page-list/page-list';
|
||||
import { StyledPage, StyledWrapper } from '../../layouts/styles';
|
||||
import type { BroadCastChannelProvider } from '../../shared';
|
||||
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
||||
|
||||
const logger = new DebugLogger('broadcast');
|
||||
|
||||
|
||||
78
apps/web/src/pages/_debug/login.dev.tsx
Normal file
78
apps/web/src/pages/_debug/login.dev.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import { Button, toast } from '@affine/component';
|
||||
import { currentAffineUserAtom } from '@affine/workspace/affine/atom';
|
||||
import {
|
||||
clearLoginStorage,
|
||||
createAffineAuth,
|
||||
getLoginStorage,
|
||||
isExpired,
|
||||
parseIdToken,
|
||||
setLoginStorage,
|
||||
SignMethod,
|
||||
} from '@affine/workspace/affine/login';
|
||||
import { useAtom } from 'jotai';
|
||||
import type { NextPage } from 'next';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { StyledPage, StyledWrapper } from '../../layouts/styles';
|
||||
|
||||
const LoginDevPage: NextPage = () => {
|
||||
const [user, setUser] = useAtom(currentAffineUserAtom);
|
||||
const auth = useMemo(() => createAffineAuth(), []);
|
||||
return (
|
||||
<StyledPage>
|
||||
<StyledWrapper>
|
||||
<h1>LoginDevPage</h1>
|
||||
<Button
|
||||
onClick={async () => {
|
||||
const storage = getLoginStorage();
|
||||
if (storage) {
|
||||
const user = parseIdToken(storage.token);
|
||||
if (isExpired(user)) {
|
||||
await auth.refreshToken(storage);
|
||||
}
|
||||
}
|
||||
const response = await auth.generateToken(SignMethod.Google);
|
||||
if (response) {
|
||||
setLoginStorage(response);
|
||||
const user = parseIdToken(response.token);
|
||||
setUser(user);
|
||||
} else {
|
||||
toast('Login failed');
|
||||
}
|
||||
}}
|
||||
>
|
||||
Login
|
||||
</Button>
|
||||
<Button
|
||||
onClick={async () => {
|
||||
const storage = getLoginStorage();
|
||||
if (!storage) {
|
||||
throw new Error('No storage');
|
||||
}
|
||||
const response = await auth.refreshToken(storage);
|
||||
if (response) {
|
||||
setLoginStorage(response);
|
||||
const user = parseIdToken(response.token);
|
||||
setUser(user);
|
||||
} else {
|
||||
toast('Login failed');
|
||||
}
|
||||
}}
|
||||
>
|
||||
Refresh Token
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
clearLoginStorage();
|
||||
setUser(null);
|
||||
}}
|
||||
>
|
||||
Reset Storage
|
||||
</Button>
|
||||
{user && JSON.stringify(user)}
|
||||
</StyledWrapper>
|
||||
</StyledPage>
|
||||
);
|
||||
};
|
||||
|
||||
export default LoginDevPage;
|
||||
@@ -1,3 +1,4 @@
|
||||
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
|
||||
import { ContentParser } from '@blocksuite/blocks/content-parser';
|
||||
import type {
|
||||
GetStaticPaths,
|
||||
@@ -16,7 +17,6 @@ import {
|
||||
StyledWrapper,
|
||||
} from '../../layouts/styles';
|
||||
import type { BlockSuiteWorkspace } from '../../shared';
|
||||
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
||||
|
||||
export type PreviewPageProps = {
|
||||
text: string;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { useRouter } from 'next/router';
|
||||
import type React from 'react';
|
||||
import { useEffect } from 'react';
|
||||
@@ -11,7 +12,6 @@ import { useSyncRouterWithCurrentWorkspaceAndPage } from '../../../hooks/use-syn
|
||||
import { WorkspaceLayout } from '../../../layouts';
|
||||
import { WorkspacePlugins } from '../../../plugins';
|
||||
import type { BlockSuiteWorkspace, NextPageWithLayout } from '../../../shared';
|
||||
import { RemWorkspaceFlavour } from '../../../shared';
|
||||
|
||||
function enableFullFlags(blockSuiteWorkspace: BlockSuiteWorkspace) {
|
||||
blockSuiteWorkspace.awarenessStore.setFlag('enable_set_remote_flag', false);
|
||||
@@ -38,12 +38,12 @@ const WorkspaceDetail: React.FC = () => {
|
||||
if (!pageId) {
|
||||
return <PageLoading />;
|
||||
}
|
||||
if (currentWorkspace.flavour === RemWorkspaceFlavour.AFFINE) {
|
||||
if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) {
|
||||
const PageDetail = WorkspacePlugins[currentWorkspace.flavour].UI.PageDetail;
|
||||
return (
|
||||
<PageDetail currentWorkspace={currentWorkspace} currentPageId={pageId} />
|
||||
);
|
||||
} else if (currentWorkspace.flavour === RemWorkspaceFlavour.LOCAL) {
|
||||
} else if (currentWorkspace.flavour === WorkspaceFlavour.LOCAL) {
|
||||
const PageDetail = WorkspacePlugins[currentWorkspace.flavour].UI.PageDetail;
|
||||
return (
|
||||
<PageDetail currentWorkspace={currentWorkspace} currentPageId={pageId} />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useTranslation } from '@affine/i18n';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { FolderIcon } from '@blocksuite/icons';
|
||||
import { assertEquals, assertExists, nanoid } from '@blocksuite/store';
|
||||
import Head from 'next/head';
|
||||
@@ -20,7 +21,6 @@ import type {
|
||||
LocalIndexedDBProvider,
|
||||
NextPageWithLayout,
|
||||
} from '../../../shared';
|
||||
import { RemWorkspaceFlavour } from '../../../shared';
|
||||
|
||||
const AllPage: NextPageWithLayout = () => {
|
||||
const router = useRouter();
|
||||
@@ -78,7 +78,7 @@ const AllPage: NextPageWithLayout = () => {
|
||||
if (currentWorkspace === null) {
|
||||
return <PageLoading />;
|
||||
}
|
||||
if (currentWorkspace.flavour === RemWorkspaceFlavour.AFFINE) {
|
||||
if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) {
|
||||
const PageList = WorkspacePlugins[currentWorkspace.flavour].UI.PageList;
|
||||
return (
|
||||
<>
|
||||
@@ -92,7 +92,7 @@ const AllPage: NextPageWithLayout = () => {
|
||||
/>
|
||||
</>
|
||||
);
|
||||
} else if (currentWorkspace.flavour === RemWorkspaceFlavour.LOCAL) {
|
||||
} else if (currentWorkspace.flavour === WorkspaceFlavour.LOCAL) {
|
||||
const PageList = WorkspacePlugins[currentWorkspace.flavour].UI.PageList;
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { useTranslation } from '@affine/i18n';
|
||||
import type { SettingPanel, WorkspaceRegistry } from '@affine/workspace/type';
|
||||
import {
|
||||
settingPanel,
|
||||
settingPanelValues,
|
||||
WorkspaceFlavour,
|
||||
} from '@affine/workspace/type';
|
||||
import { SettingsIcon } from '@blocksuite/icons';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
import { useAtom } from 'jotai';
|
||||
@@ -16,16 +22,7 @@ import { useTransformWorkspace } from '../../../hooks/use-transform-workspace';
|
||||
import { useWorkspacesHelper } from '../../../hooks/use-workspaces';
|
||||
import { WorkspaceLayout } from '../../../layouts';
|
||||
import { WorkspacePlugins } from '../../../plugins';
|
||||
import type {
|
||||
FlavourToWorkspace,
|
||||
NextPageWithLayout,
|
||||
SettingPanel,
|
||||
} from '../../../shared';
|
||||
import {
|
||||
RemWorkspaceFlavour,
|
||||
settingPanel,
|
||||
settingPanelValues,
|
||||
} from '../../../shared';
|
||||
import type { NextPageWithLayout } from '../../../shared';
|
||||
import { apis } from '../../../shared/apis';
|
||||
|
||||
const settingPanelAtom = atomWithStorage<SettingPanel>(
|
||||
@@ -105,13 +102,12 @@ const SettingPage: NextPageWithLayout = () => {
|
||||
}, [currentWorkspace, helper]);
|
||||
const transformWorkspace = useTransformWorkspace();
|
||||
const onTransformWorkspace = useCallback(
|
||||
async <From extends RemWorkspaceFlavour, To extends RemWorkspaceFlavour>(
|
||||
async <From extends WorkspaceFlavour, To extends WorkspaceFlavour>(
|
||||
from: From,
|
||||
to: To,
|
||||
workspace: FlavourToWorkspace[From]
|
||||
workspace: WorkspaceRegistry[From]
|
||||
): Promise<void> => {
|
||||
const needRefresh =
|
||||
to === RemWorkspaceFlavour.AFFINE && !apis.auth.isLogin;
|
||||
const needRefresh = to === WorkspaceFlavour.AFFINE && !apis.auth.isLogin;
|
||||
if (needRefresh) {
|
||||
await apis.signInWithGoogle();
|
||||
}
|
||||
@@ -135,7 +131,7 @@ const SettingPage: NextPageWithLayout = () => {
|
||||
return <PageLoading />;
|
||||
} else if (settingPanelValues.indexOf(currentTab as SettingPanel) === -1) {
|
||||
return <PageLoading />;
|
||||
} else if (currentWorkspace.flavour === RemWorkspaceFlavour.AFFINE) {
|
||||
} else if (currentWorkspace.flavour === WorkspaceFlavour.AFFINE) {
|
||||
const Setting =
|
||||
WorkspacePlugins[currentWorkspace.flavour].UI.SettingsDetail;
|
||||
return (
|
||||
@@ -155,7 +151,7 @@ const SettingPage: NextPageWithLayout = () => {
|
||||
/>
|
||||
</>
|
||||
);
|
||||
} else if (currentWorkspace.flavour === RemWorkspaceFlavour.LOCAL) {
|
||||
} else if (currentWorkspace.flavour === WorkspaceFlavour.LOCAL) {
|
||||
const Setting =
|
||||
WorkspacePlugins[currentWorkspace.flavour].UI.SettingsDetail;
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user