feat: fix workspace name

This commit is contained in:
MingLiang Wang
2022-12-23 12:40:39 +08:00
parent 5747061663
commit c1505feed6
2 changed files with 22 additions and 11 deletions
@@ -13,7 +13,11 @@ import type {
LoadWorkspaceHandler,
CreateEditorHandler,
} from './context';
import { token, WebsocketProvider } from '@pathfinder/data-services';
import {
downloadWorkspace,
token,
WebsocketProvider,
} from '@pathfinder/data-services';
interface Props {
setLoadWorkspaceHandler: (handler: LoadWorkspaceHandler) => void;
@@ -64,6 +68,11 @@ const DynamicBlocksuite = ({
const indexDBProvider = workspace.providers.find(
p => p instanceof IndexedDBDocProvider
);
const updates = await downloadWorkspace({ workspaceId });
updates &&
Workspace.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).on('synced', async () => {
resolve(workspace);
@@ -44,15 +44,17 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
const refreshWorkspacesInfo = async (
workspaces: AppStateValue['workspaces']
) => {
Object.entries(workspaces).forEach(async ([workspaceId, workspace]) => {
if (workspace) {
const updates = await downloadWorkspace({ workspaceId });
updates &&
Workspace.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');
}
});
return Promise.all(
Object.entries(workspaces).map(async ([workspaceId, workspace]) => {
if (workspace) {
const updates = await downloadWorkspace({ workspaceId });
updates &&
Workspace.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');
}
})
);
};
useEffect(() => {
@@ -67,11 +69,11 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
workspacesList.forEach(({ id, workspace }) => {
workspaces[id] = workspace;
});
await refreshWorkspacesInfo(workspaces);
setState(state => ({
...state,
workspaces,
}));
refreshWorkspacesInfo(workspaces);
})();
}, [state.workspacesMeta]);