fix:shapaes bidings error

This commit is contained in:
DiamondThree
2022-08-19 10:49:30 +08:00
parent 4724aee96e
commit 22883de54e
2 changed files with 14 additions and 25 deletions
+14 -9
View File
@@ -64,9 +64,6 @@ const AffineBoard = ({ workspace, rootBlockId }: AffineBoardProps) => {
set_app(app); set_app(app);
}, },
async onChangePage(app, shapes, bindings, assets) { async onChangePage(app, shapes, bindings, assets) {
console.log('shapes, bindings: ', shapes, bindings);
//
await Promise.all( await Promise.all(
Object.entries(shapes).map(async ([id, shape]) => { Object.entries(shapes).map(async ([id, shape]) => {
if (shape === undefined) { if (shape === undefined) {
@@ -110,7 +107,7 @@ const AffineBoard = ({ workspace, rootBlockId }: AffineBoardProps) => {
bindings[bilingKey].toId = block.id; bindings[bilingKey].toId = block.id;
} }
}); });
return services.api.editorBlock.update({ return await services.api.editorBlock.update({
workspace: shape.workspace, workspace: shape.workspace,
id: block.id, id: block.id,
properties: { properties: {
@@ -122,19 +119,27 @@ const AffineBoard = ({ workspace, rootBlockId }: AffineBoardProps) => {
} }
}) })
); );
// let pageBindings = services.api.editorBlock.get({workspace: workspace,ids:[rootBlockId]})?[0] let pageBindingsString = (
let block = (
await services.api.editorBlock.get({ await services.api.editorBlock.get({
workspace: workspace, workspace: workspace,
ids: [rootBlockId], ids: [rootBlockId],
}) })
)?.[0]; )?.[0].properties.bindings.value;
let pageBindings = JSON.parse(pageBindingsString ?? '{}');
Object.keys(bindings).forEach(bindingsKey => {
if (bindings[bindingsKey] === undefined) {
delete pageBindings[bindingsKey];
} else {
Object.assign(pageBindings, bindings);
}
});
console.log(pageBindings);
services.api.editorBlock.update({ services.api.editorBlock.update({
workspace: workspace, workspace: workspace,
id: block.id, id: rootBlockId,
properties: { properties: {
bindings: { bindings: {
value: JSON.stringify(bindings), value: JSON.stringify(pageBindings),
}, },
}, },
}); });
@@ -115,19 +115,3 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
bindings: JSON.parse(blocks?.bindings ?? '{}'), bindings: JSON.parse(blocks?.bindings ?? '{}'),
}; };
}; };
export const useBindings = (workspace: string, rootBlockId: string) => {
const [bindings, setBindings] = useState<string>();
useEffect(() => {
services.api.editorBlock
.get({
workspace: workspace,
ids: [rootBlockId],
})
.then(blcoks => {
setBindings(blcoks[0].properties.bindings?.value);
});
return () => {};
}, [workspace, rootBlockId]);
return bindings ? JSON.parse(bindings) : {};
};