mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
fix(core): transform workspace db when enable cloud (#7744)
This commit is contained in:
@@ -29,6 +29,8 @@ type ConfirmEnableArgs = [Workspace, ConfirmEnableCloudOptions | undefined];
|
||||
|
||||
export const useEnableCloud = () => {
|
||||
const t = useI18n();
|
||||
const authService = useService(AuthService);
|
||||
const account = useLiveData(authService.session.account$);
|
||||
const loginStatus = useLiveData(useService(AuthService).session.status$);
|
||||
const setAuthAtom = useSetAtom(authAtom);
|
||||
const { openConfirmModal, closeConfirmModal } = useConfirmModal();
|
||||
@@ -39,7 +41,11 @@ export const useEnableCloud = () => {
|
||||
async (ws: Workspace | null, options?: ConfirmEnableCloudOptions) => {
|
||||
try {
|
||||
if (!ws) return;
|
||||
const { id: newId } = await workspacesService.transformLocalToCloud(ws);
|
||||
if (!account) return;
|
||||
const { id: newId } = await workspacesService.transformLocalToCloud(
|
||||
ws,
|
||||
account.id
|
||||
);
|
||||
openPage(newId, options?.openPageId || WorkspaceSubPath.ALL);
|
||||
options?.onSuccess?.();
|
||||
} catch (e) {
|
||||
@@ -49,7 +55,7 @@ export const useEnableCloud = () => {
|
||||
});
|
||||
}
|
||||
},
|
||||
[openPage, t, workspacesService]
|
||||
[account, openPage, t, workspacesService]
|
||||
);
|
||||
|
||||
const openSignIn = useCallback(() => {
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
ApplicationStarted,
|
||||
type BlobStorage,
|
||||
catchErrorInto,
|
||||
type DocStorage,
|
||||
exhaustMapSwitchUntilChanged,
|
||||
fromPromise,
|
||||
type GlobalState,
|
||||
@@ -77,11 +78,10 @@ export class CloudWorkspaceFlavourProviderService
|
||||
async createWorkspace(
|
||||
initial: (
|
||||
docCollection: DocCollection,
|
||||
blobStorage: BlobStorage
|
||||
blobStorage: BlobStorage,
|
||||
docStorage: DocStorage
|
||||
) => Promise<void>
|
||||
): Promise<WorkspaceMetadata> {
|
||||
const tempId = nanoid();
|
||||
|
||||
// create workspace on cloud, get workspace id
|
||||
const {
|
||||
createWorkspace: { id: workspaceId },
|
||||
@@ -94,7 +94,7 @@ export class CloudWorkspaceFlavourProviderService
|
||||
const docStorage = this.storageProvider.getDocStorage(workspaceId);
|
||||
|
||||
const docCollection = new DocCollection({
|
||||
id: tempId,
|
||||
id: workspaceId,
|
||||
idGenerator: () => nanoid(),
|
||||
schema: globalBlockSuiteSchema,
|
||||
blobSources: {
|
||||
@@ -103,7 +103,7 @@ export class CloudWorkspaceFlavourProviderService
|
||||
});
|
||||
|
||||
// apply initial state
|
||||
await initial(docCollection, blobStorage);
|
||||
await initial(docCollection, blobStorage, docStorage);
|
||||
|
||||
// save workspace to local storage, should be vary fast
|
||||
await docStorage.doc.set(
|
||||
|
||||
@@ -3,6 +3,7 @@ import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import type {
|
||||
BlobStorage,
|
||||
DocStorage,
|
||||
WorkspaceEngineProvider,
|
||||
WorkspaceFlavourProvider,
|
||||
WorkspaceMetadata,
|
||||
@@ -56,7 +57,8 @@ export class LocalWorkspaceFlavourProvider
|
||||
async createWorkspace(
|
||||
initial: (
|
||||
docCollection: DocCollection,
|
||||
blobStorage: BlobStorage
|
||||
blobStorage: BlobStorage,
|
||||
docStorage: DocStorage
|
||||
) => Promise<void>
|
||||
): Promise<WorkspaceMetadata> {
|
||||
const id = nanoid();
|
||||
@@ -73,7 +75,7 @@ export class LocalWorkspaceFlavourProvider
|
||||
});
|
||||
|
||||
// apply initial state
|
||||
await initial(docCollection, blobStorage);
|
||||
await initial(docCollection, blobStorage, docStorage);
|
||||
|
||||
// save workspace to local storage, should be vary fast
|
||||
await docStorage.doc.set(id, encodeStateAsUpdate(docCollection.doc));
|
||||
|
||||
Reference in New Issue
Block a user