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);
},
async onChangePage(app, shapes, bindings, assets) {
console.log('shapes, bindings: ', shapes, bindings);
//
await Promise.all(
Object.entries(shapes).map(async ([id, shape]) => {
if (shape === undefined) {
@@ -110,7 +107,7 @@ const AffineBoard = ({ workspace, rootBlockId }: AffineBoardProps) => {
bindings[bilingKey].toId = block.id;
}
});
return services.api.editorBlock.update({
return await services.api.editorBlock.update({
workspace: shape.workspace,
id: block.id,
properties: {
@@ -122,19 +119,27 @@ const AffineBoard = ({ workspace, rootBlockId }: AffineBoardProps) => {
}
})
);
// let pageBindings = services.api.editorBlock.get({workspace: workspace,ids:[rootBlockId]})?[0]
let block = (
let pageBindingsString = (
await services.api.editorBlock.get({
workspace: workspace,
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({
workspace: workspace,
id: block.id,
id: rootBlockId,
properties: {
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 ?? '{}'),
};
};
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) : {};
};