Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
move view definition outside of components
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhtungdu committed Dec 13, 2021
1 parent 9ecc545 commit bdf9748
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
26 changes: 14 additions & 12 deletions assets/js/blocks/cart-checkout/cart/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ const ALLOWED_BLOCKS = [
'woocommerce/empty-cart-block',
];

const views = [
{
view: 'woocommerce/filled-cart-block',
label: __( 'Filled Cart', 'woo-gutenberg-products-block' ),
icon: <Icon srcElement={ filledCart } />,
},
{
view: 'woocommerce/empty-cart-block',
label: __( 'Empty Cart', 'woo-gutenberg-products-block' ),
icon: <Icon srcElement={ removeCart } />,
},
];

const BlockSettings = ( { attributes, setAttributes } ) => {
const { hasDarkControls } = attributes;
const { currentPostId } = useEditorContext();
Expand Down Expand Up @@ -104,18 +117,7 @@ export const Edit = ( { className, attributes, setAttributes, clientId } ) => {
const { hasDarkControls } = attributes;
const { currentView, component: ViewSwitcherComponent } = useViewSwitcher(
clientId,
[
{
view: 'woocommerce/filled-cart-block',
label: __( 'Filled Cart', 'woo-gutenberg-products-block' ),
icon: <Icon srcElement={ filledCart } />,
},
{
view: 'woocommerce/empty-cart-block',
label: __( 'Empty Cart', 'woo-gutenberg-products-block' ),
icon: <Icon srcElement={ removeCart } />,
},
]
views
);
const defaultTemplate = [
[ 'woocommerce/filled-cart-block', {}, [] ],
Expand Down
27 changes: 15 additions & 12 deletions assets/js/blocks/cart-checkout/mini-cart-contents/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ const ALLOWED_BLOCKS = [
'woocommerce/filled-mini-cart-contents-block',
'woocommerce/empty-mini-cart-contents-block',
];

const views = [
{
view: 'woocommerce/filled-mini-cart-contents-block',
label: __( 'Filled Mini Cart', 'woo-gutenberg-products-block' ),
icon: <Icon srcElement={ filledCart } />,
},
{
view: 'woocommerce/empty-mini-cart-contents-block',
label: __( 'Empty Mini Cart', 'woo-gutenberg-products-block' ),
icon: <Icon srcElement={ removeCart } />,
},
];

interface Props {
clientId: string;
}
Expand All @@ -36,18 +50,7 @@ const Edit = ( { clientId }: Props ): ReactElement => {

const { currentView, component: ViewSwitcherComponent } = useViewSwitcher(
clientId,
[
{
view: 'woocommerce/filled-mini-cart-contents-block',
label: __( 'Filled Mini Cart', 'woo-gutenberg-products-block' ),
icon: <Icon srcElement={ filledCart } />,
},
{
view: 'woocommerce/empty-mini-cart-contents-block',
label: __( 'Empty Mini Cart', 'woo-gutenberg-products-block' ),
icon: <Icon srcElement={ removeCart } />,
},
]
views
);

useForcedLayout( {
Expand Down

0 comments on commit bdf9748

Please sign in to comment.