mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 12:36:24 +08:00
fix:shapaes bidings error
This commit is contained in:
@@ -9,24 +9,45 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
|
||||
const { pageClientWidth } = usePageClientWidth();
|
||||
// page padding left and right total 300px
|
||||
const editorShapeInitSize = pageClientWidth - 300;
|
||||
const [blocks, setBlocks] = useState<ReturnEditorBlock[]>();
|
||||
const [blocks, setBlocks] = useState<{
|
||||
shapes: [ReturnEditorBlock[]];
|
||||
bindings: string;
|
||||
}>();
|
||||
useEffect(() => {
|
||||
services.api.editorBlock
|
||||
.get({ workspace, ids: [rootBlockId] })
|
||||
.then(async blockData => {
|
||||
const shapes = await Promise.all(
|
||||
(blockData?.[0]?.children || []).map(async childId => {
|
||||
const childBlock = (
|
||||
await services.api.editorBlock.get({
|
||||
workspace,
|
||||
ids: [childId],
|
||||
})
|
||||
)?.[0];
|
||||
return childBlock;
|
||||
})
|
||||
);
|
||||
setBlocks(shapes);
|
||||
});
|
||||
Promise.all([
|
||||
services.api.editorBlock
|
||||
.get({ workspace, ids: [rootBlockId] })
|
||||
.then(async blockData => {
|
||||
const shapes = await Promise.all(
|
||||
(blockData?.[0]?.children || []).map(async childId => {
|
||||
const childBlock = (
|
||||
await services.api.editorBlock.get({
|
||||
workspace,
|
||||
ids: [childId],
|
||||
})
|
||||
)?.[0];
|
||||
return childBlock;
|
||||
})
|
||||
);
|
||||
return shapes;
|
||||
// setBlocks(shapes);
|
||||
}),
|
||||
]).then(shapes => {
|
||||
console.log(shapes);
|
||||
services.api.editorBlock
|
||||
.get({
|
||||
workspace: workspace,
|
||||
ids: [rootBlockId],
|
||||
})
|
||||
.then(blcoks => {
|
||||
setBlocks({
|
||||
shapes,
|
||||
bindings: blcoks[0].properties.bindings?.value,
|
||||
});
|
||||
// setBindings(blcoks[0].properties.bindings?.value);
|
||||
});
|
||||
});
|
||||
|
||||
let unobserve: () => void;
|
||||
services.api.editorBlock
|
||||
.observe({ workspace, id: rootBlockId }, async blockData => {
|
||||
@@ -40,8 +61,23 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
|
||||
)?.[0];
|
||||
return childBlock;
|
||||
})
|
||||
);
|
||||
setBlocks(shapes);
|
||||
).then(shapes => {
|
||||
console.log(shapes);
|
||||
services.api.editorBlock
|
||||
.get({
|
||||
workspace: workspace,
|
||||
ids: [rootBlockId],
|
||||
})
|
||||
.then(blcoks => {
|
||||
setBlocks({
|
||||
shapes: [shapes],
|
||||
bindings: blcoks[0].properties.bindings?.value,
|
||||
});
|
||||
// setBindings(blcoks[0].properties.bindings?.value);
|
||||
});
|
||||
});
|
||||
return shapes;
|
||||
// setBlocks(shapes);
|
||||
})
|
||||
.then(cb => {
|
||||
unobserve = cb;
|
||||
@@ -53,8 +89,7 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
|
||||
}, [workspace, rootBlockId]);
|
||||
|
||||
let groupCount = 0;
|
||||
|
||||
return blocks?.reduce((acc, block) => {
|
||||
let blocksShapes = blocks?.shapes[0]?.reduce((acc, block) => {
|
||||
const shapeProps = block.properties.shapeProps?.value
|
||||
? JSON.parse(block.properties.shapeProps.value)
|
||||
: {};
|
||||
@@ -75,4 +110,24 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
|
||||
|
||||
return acc;
|
||||
}, {} as Record<string, TDShape>);
|
||||
return {
|
||||
shapes: blocksShapes,
|
||||
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) : {};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user