mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 09:36:17 +08:00
feat: improve code
This commit is contained in:
@@ -27,7 +27,8 @@ const DynamicBlocksuite = ({
|
||||
useEffect(() => {
|
||||
const openWorkspace: LoadWorkspaceHandler = (
|
||||
workspaceId: string,
|
||||
websocket = false
|
||||
websocket = false,
|
||||
user
|
||||
) =>
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
new Promise(async resolve => {
|
||||
@@ -63,22 +64,16 @@ const DynamicBlocksuite = ({
|
||||
const indexDBProvider = workspace.providers.find(
|
||||
p => p instanceof IndexedDBDocProvider
|
||||
);
|
||||
await new Promise<undefined>(resolve => {
|
||||
downloadWorkspace({ workspaceId })
|
||||
.then(async updates => {
|
||||
updates &&
|
||||
StoreWorkspace.Y.applyUpdate(
|
||||
workspace.doc,
|
||||
new Uint8Array(updates)
|
||||
);
|
||||
// if after update, the space:meta is empty, then we need to get map with doc
|
||||
workspace.doc.getMap('space:meta');
|
||||
resolve(undefined);
|
||||
})
|
||||
.catch(() => {
|
||||
resolve(undefined);
|
||||
});
|
||||
});
|
||||
if (user) {
|
||||
const updates = await downloadWorkspace({ workspaceId });
|
||||
updates &&
|
||||
StoreWorkspace.Y.applyUpdate(
|
||||
workspace.doc,
|
||||
new Uint8Array(updates)
|
||||
);
|
||||
// if after update, the space:meta is empty, then we need to get map with doc
|
||||
workspace.doc.getMap('space:meta');
|
||||
}
|
||||
if (indexDBProvider) {
|
||||
(indexDBProvider as IndexedDBDocProvider).whenSynced.then(() => {
|
||||
resolve(workspace);
|
||||
|
||||
@@ -45,7 +45,8 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
|
||||
(async () => {
|
||||
const workspacesList = await Promise.all(
|
||||
state.workspacesMeta.map(async ({ id }) => {
|
||||
const workspace = (await loadWorkspaceHandler?.(id, false)) || null;
|
||||
const workspace =
|
||||
(await loadWorkspaceHandler?.(id, false, state.user)) || null;
|
||||
return { id, workspace };
|
||||
})
|
||||
);
|
||||
@@ -87,7 +88,8 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
|
||||
if (state.currentWorkspaceId === workspaceId) {
|
||||
return state.currentWorkspace;
|
||||
}
|
||||
const workspace = (await loadWorkspaceHandler?.(workspaceId, true)) || null;
|
||||
const workspace =
|
||||
(await loadWorkspaceHandler?.(workspaceId, true, state.user)) || null;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
|
||||
Reference in New Issue
Block a user