Skip to content

Commit

Permalink
Creating a new action type, so we can update the state with one actio…
Browse files Browse the repository at this point in the history
…n call.
  • Loading branch information
ramonjd committed Nov 1, 2021
1 parent e7cec87 commit 5cac465
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ const expanded = ( state, action ) => {
return { ...state, ...{ [ action.clientId ]: true } };
case 'collapse':
return { ...state, ...{ [ action.clientId ]: false } };
case 'expandAll':
return {
...state,
...action.clientIds.reduce(
( newState, id ) => ( {
...newState,
[ id ]: true,
} ),
{}
),
};
default:
return state;
}
Expand Down Expand Up @@ -182,13 +193,9 @@ function ListView(
Array.isArray( selectedBlockParentClientIds ) &&
selectedBlockParentClientIds.length
) {
selectedBlockParentClientIds.forEach( ( clientId ) => {
if ( ! expandedState[ clientId ] ) {
setExpandedState( {
type: 'expand',
clientId,
} );
}
setExpandedState( {
type: 'expandAll',
clientIds: selectedBlockParentClientIds,
} );
}
}, [ hasFocus, selectedBlockParentClientIds ] );
Expand Down

0 comments on commit 5cac465

Please sign in to comment.