mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 17:46:18 +08:00
feat: fix workspace name
This commit is contained in:
@@ -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]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user