fix:shapaes
This commit is contained in:
@@ -45,8 +45,6 @@ const AffineBoard = ({ workspace, rootBlockId }: AffineBoardProps) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { shapes, bindings } = useShapes(workspace, rootBlockId);
|
const { shapes, bindings } = useShapes(workspace, rootBlockId);
|
||||||
|
|
||||||
// const bindings = useBindings(workspace, rootBlockId);
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (app) {
|
if (app) {
|
||||||
app.replacePageContent(shapes || {}, bindings, {});
|
app.replacePageContent(shapes || {}, bindings, {});
|
||||||
@@ -124,7 +122,7 @@ const AffineBoard = ({ workspace, rootBlockId }: AffineBoardProps) => {
|
|||||||
workspace: workspace,
|
workspace: workspace,
|
||||||
ids: [rootBlockId],
|
ids: [rootBlockId],
|
||||||
})
|
})
|
||||||
)?.[0].properties.bindings.value;
|
)?.[0].properties.bindings?.value;
|
||||||
let pageBindings = JSON.parse(pageBindingsString ?? '{}');
|
let pageBindings = JSON.parse(pageBindingsString ?? '{}');
|
||||||
Object.keys(bindings).forEach(bindingsKey => {
|
Object.keys(bindings).forEach(bindingsKey => {
|
||||||
if (bindings[bindingsKey] === undefined) {
|
if (bindings[bindingsKey] === undefined) {
|
||||||
@@ -133,7 +131,6 @@ const AffineBoard = ({ workspace, rootBlockId }: AffineBoardProps) => {
|
|||||||
Object.assign(pageBindings, bindings);
|
Object.assign(pageBindings, bindings);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(pageBindings);
|
|
||||||
services.api.editorBlock.update({
|
services.api.editorBlock.update({
|
||||||
workspace: workspace,
|
workspace: workspace,
|
||||||
id: rootBlockId,
|
id: rootBlockId,
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ import { services } from '@toeverything/datasource/db-service';
|
|||||||
import { usePageClientWidth } from '@toeverything/datasource/state';
|
import { usePageClientWidth } from '@toeverything/datasource/state';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
const getBindings = (workspace: string, rootBlockId: string) => {
|
||||||
|
return services.api.editorBlock
|
||||||
|
.get({
|
||||||
|
workspace: workspace,
|
||||||
|
ids: [rootBlockId],
|
||||||
|
})
|
||||||
|
.then(blcoks => {
|
||||||
|
return blcoks[0].properties.bindings?.value;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const useShapes = (workspace: string, rootBlockId: string) => {
|
export const useShapes = (workspace: string, rootBlockId: string) => {
|
||||||
const { pageClientWidth } = usePageClientWidth();
|
const { pageClientWidth } = usePageClientWidth();
|
||||||
// page padding left and right total 300px
|
// page padding left and right total 300px
|
||||||
@@ -30,28 +41,20 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
return shapes;
|
return shapes;
|
||||||
// setBlocks(shapes);
|
|
||||||
}),
|
}),
|
||||||
]).then(shapes => {
|
]).then(shapes => {
|
||||||
console.log(shapes);
|
getBindings(workspace, rootBlockId).then(bindings => {
|
||||||
services.api.editorBlock
|
|
||||||
.get({
|
|
||||||
workspace: workspace,
|
|
||||||
ids: [rootBlockId],
|
|
||||||
})
|
|
||||||
.then(blcoks => {
|
|
||||||
setBlocks({
|
setBlocks({
|
||||||
shapes,
|
shapes,
|
||||||
bindings: blcoks[0].properties.bindings?.value,
|
bindings: bindings,
|
||||||
});
|
});
|
||||||
// setBindings(blcoks[0].properties.bindings?.value);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let unobserve: () => void;
|
let unobserve: () => void;
|
||||||
services.api.editorBlock
|
services.api.editorBlock
|
||||||
.observe({ workspace, id: rootBlockId }, async blockData => {
|
.observe({ workspace, id: rootBlockId }, async blockData => {
|
||||||
const shapes = await Promise.all(
|
Promise.all(
|
||||||
(blockData?.children || []).map(async childId => {
|
(blockData?.children || []).map(async childId => {
|
||||||
const childBlock = (
|
const childBlock = (
|
||||||
await services.api.editorBlock.get({
|
await services.api.editorBlock.get({
|
||||||
@@ -62,22 +65,13 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
|
|||||||
return childBlock;
|
return childBlock;
|
||||||
})
|
})
|
||||||
).then(shapes => {
|
).then(shapes => {
|
||||||
console.log(shapes);
|
getBindings(workspace, rootBlockId).then(bindings => {
|
||||||
services.api.editorBlock
|
|
||||||
.get({
|
|
||||||
workspace: workspace,
|
|
||||||
ids: [rootBlockId],
|
|
||||||
})
|
|
||||||
.then(blcoks => {
|
|
||||||
setBlocks({
|
setBlocks({
|
||||||
shapes: [shapes],
|
shapes: [shapes],
|
||||||
bindings: blcoks[0].properties.bindings?.value,
|
bindings: bindings,
|
||||||
});
|
});
|
||||||
// setBindings(blcoks[0].properties.bindings?.value);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return shapes;
|
|
||||||
// setBlocks(shapes);
|
|
||||||
})
|
})
|
||||||
.then(cb => {
|
.then(cb => {
|
||||||
unobserve = cb;
|
unobserve = cb;
|
||||||
|
|||||||
Reference in New Issue
Block a user