Browse Source

Reduce state updates when selecting layouts

master
Andrew Kingston 4 years ago
parent
commit
fa42acaaf8
  1. 19
      packages/builder/src/builderStore/store/frontend.js
  2. 2
      packages/builder/src/pages/builder/app/[application]/design/[screenId]/layouts/[layoutId]/_components/LayoutListPanel.svelte

19
packages/builder/src/builderStore/store/frontend.js

@ -331,10 +331,23 @@ export const getFrontendStore = () => {
}, },
layouts: { layouts: {
select: layoutId => { select: layoutId => {
// Check this layout exists
const state = get(store)
const layout = store.actions.layouts.find(layoutId)
if (!layout) {
return
}
// Check layout isn't already selected
if (
state.selectedLayoutId === layout._id &&
state.selectedComponentId === layout.props?._id
) {
return
}
// Select new layout
store.update(state => { store.update(state => {
const layout =
store.actions.layouts.find(layoutId) || get(store).layouts[0]
if (!layout) return
state.selectedLayoutId = layout._id state.selectedLayoutId = layout._id
state.selectedComponentId = layout.props?._id state.selectedComponentId = layout.props?._id
return state return state

2
packages/builder/src/pages/builder/app/[application]/design/[screenId]/layouts/[layoutId]/_components/LayoutListPanel.svelte

@ -13,7 +13,7 @@
indentLevel={0} indentLevel={0}
selected={$store.selectedLayoutId === layout._id} selected={$store.selectedLayoutId === layout._id}
text={layout.name} text={layout.name}
on:click={() => ($store.selectedLayoutId = layout._id)} on:click={() => store.actions.layouts.select(layout._id)}
> >
<LayoutDropdownMenu {layout} /> <LayoutDropdownMenu {layout} />
</NavItem> </NavItem>

Loading…
Cancel
Save