mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-28 12:52:57 +03:00
fix: local provider create workspace should wait sync to idb
This commit is contained in:
parent
b4571539ac
commit
b111c411bd
20
packages/data-center/src/provider/local/indexeddb/utils.ts
Normal file
20
packages/data-center/src/provider/local/indexeddb/utils.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import assert from 'assert';
|
||||
import * as idb from 'lib0/indexeddb.js';
|
||||
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
||||
|
||||
const { encodeStateAsUpdate } = BlocksuiteWorkspace.Y;
|
||||
|
||||
export const initStore = async (blocksuiteWorkspace: BlocksuiteWorkspace) => {
|
||||
const workspaceId = blocksuiteWorkspace.room;
|
||||
assert(workspaceId);
|
||||
await idb.deleteDB(workspaceId);
|
||||
const db = await idb.openDB(workspaceId, db =>
|
||||
idb.createStores(db, [['updates', { autoIncrement: true }], ['custom']])
|
||||
);
|
||||
const currState = encodeStateAsUpdate(blocksuiteWorkspace.doc);
|
||||
const [updatesStore] = idb.transact(db, ['updates']); // , 'readonly')
|
||||
|
||||
if (updatesStore) {
|
||||
await idb.addAutoKey(updatesStore, currState);
|
||||
}
|
||||
};
|
@ -7,7 +7,8 @@ import type {
|
||||
} from '../base';
|
||||
import { varStorage as storage } from 'lib0/storage';
|
||||
import { Workspace as BlocksuiteWorkspace, uuidv4 } from '@blocksuite/store';
|
||||
import { IndexedDBProvider } from './indexeddb.js';
|
||||
import { IndexedDBProvider } from './indexeddb/indexeddb.js';
|
||||
import { initStore } from './indexeddb/utils.js';
|
||||
import assert from 'assert';
|
||||
import { setDefaultAvatar } from '../utils.js';
|
||||
|
||||
@ -101,21 +102,12 @@ export class LocalProvider extends BaseProvider {
|
||||
): Promise<BlocksuiteWorkspace | undefined> {
|
||||
const workspaceId = blocksuiteWorkspace.room;
|
||||
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
|
||||
assert(meta.name, 'Workspace name is required');
|
||||
this._logger('Creating affine workspace');
|
||||
|
||||
const workspaceInfo: WorkspaceMeta0 = {
|
||||
name: meta.name,
|
||||
id: workspaceId,
|
||||
published: false,
|
||||
avatar: '',
|
||||
owner: undefined,
|
||||
syncMode: 'core',
|
||||
memberCount: 1,
|
||||
provider: 'local',
|
||||
...meta,
|
||||
};
|
||||
|
||||
this.linkLocal(blocksuiteWorkspace);
|
||||
blocksuiteWorkspace.meta.setName(meta.name);
|
||||
|
||||
if (!meta.avatar) {
|
||||
@ -123,6 +115,8 @@ export class LocalProvider extends BaseProvider {
|
||||
workspaceInfo.avatar = blocksuiteWorkspace.meta.avatar;
|
||||
}
|
||||
|
||||
await initStore(blocksuiteWorkspace);
|
||||
|
||||
this._workspaces.add(workspaceInfo);
|
||||
this._storeWorkspaces(this._workspaces.list());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user