Skip to content

Commit

Permalink
fix(app-page-builder): separate state observers for better performance (
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Nov 10, 2023
1 parent 63fa1cb commit fa1befb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export const blocksHandler = async (
});
prevStatusOfSubTask = subTask.status;
} catch (e) {
log("[IMPORT_BLOCKS_PROCESS] Error => ", e.message);
console.error(
"[IMPORT_BLOCKS_PROCESS] Error => ",
e.message,
JSON.stringify(e.data, null, 2)
);

if (subTask && subTask.id) {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class BlocksRepository {
const decompressed = this.decompressPageBlock(pageBlock);

runInAction(() => {
this.pageBlocks.push(decompressed);
this.pageBlocks = [...this.pageBlocks, decompressed];
});

this.createBlockPlugin(decompressed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@ export function usePageBlocks() {

useEffect(() => {
blocksRepository.listPageBlocks();
}, [blocksRepository]);

autorun(() => {
useEffect(() => {
return autorun(() => {
const loading = blocksRepository.getLoading();

setVm({
pageBlocks: blocksRepository.getPageBlocks().map(pageBlock => {
return structuredClone(pageBlock);
}),
setVm(vm => ({
...vm,
loading: loading.isLoading,
loadingLabel: loading.loadingLabel
});
}));
});
}, [blocksRepository]);

useEffect(() => {
return autorun(() => {
const pageBlocks = blocksRepository.getPageBlocks();

setVm(vm => ({ ...vm, pageBlocks }));
});
}, [blocksRepository]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ const List = styled("div")`
`;

const ListItem = styled.div`
position: relative;
border: 1px solid rgba(212, 212, 212, 0.5);
box-shadow: 0px 2px 1px -1px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%),
0px 1px 3px 0px rgb(0 0 0 / 12%);
min-height: 70px;
padding: 15px;
margin-bottom: 10px;
:last-of-type {
margin-bottom: 0;
}
position: relative;
border: 1px solid rgba(212, 212, 212, 0.5);
box-shadow: 0px 2px 1px -1px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%),
0px 1px 3px 0px rgb(0 0 0 / 12%);
min-height: 70px;
padding: 15px;
margin-bottom: 10px;
:last-of-type {
margin-bottom: 0;
}
`;

const ListItemText = styled("div")({
Expand Down

0 comments on commit fa1befb

Please sign in to comment.