mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
✨ Move styling options to Redux store!
This commit is contained in:
parent
34cc8f8fab
commit
033b6e5b74
1 changed files with 16 additions and 30 deletions
|
@ -8,8 +8,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useCallback, useState } from '@wordpress/element'; // Temporary
|
import { useCallback } from '@wordpress/element'; // Temporary
|
||||||
import { useDispatch } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
|
|
||||||
import { createHooksForStore } from '../utils';
|
import { createHooksForStore } from '../utils';
|
||||||
import { STORE_NAME } from './constants';
|
import { STORE_NAME } from './constants';
|
||||||
|
@ -33,43 +33,29 @@ const useHooks = () => {
|
||||||
const [ location, setLocation ] = useTransient( 'location' );
|
const [ location, setLocation ] = useTransient( 'location' );
|
||||||
|
|
||||||
// Persistent accessors.
|
// Persistent accessors.
|
||||||
// TODO - this is a dummy implementation.
|
const persistentData = useSelect(
|
||||||
const defaultStyle = {
|
( select ) => select( STORE_NAME ).persistentData(),
|
||||||
paymentMethods: [],
|
[]
|
||||||
color: 'gold',
|
);
|
||||||
shape: 'rect',
|
|
||||||
label: 'paypal',
|
|
||||||
layout: 'vertical',
|
|
||||||
tagline: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
// This data-struct is already present in the Redux store via persistentData, e.g. "persistentData.cart.label"
|
const [ locationStyles, setLocationStyles ] = usePersistent( location );
|
||||||
const [ styles, setStyles ] = useState( {
|
|
||||||
cart: { ...defaultStyle, label: 'checkout' },
|
|
||||||
'classic-checkout': { ...defaultStyle },
|
|
||||||
'express-checkout': { ...defaultStyle, label: 'pay' },
|
|
||||||
'mini-cart': { ...defaultStyle, label: 'pay' },
|
|
||||||
'product-page': { ...defaultStyle },
|
|
||||||
} );
|
|
||||||
|
|
||||||
const getLocationProp = useCallback(
|
const getLocationProp = useCallback(
|
||||||
( prop ) => styles[ location ]?.[ prop ],
|
( prop ) => {
|
||||||
[ location, styles ]
|
return persistentData[ location ]?.[ prop ];
|
||||||
|
},
|
||||||
|
[ location, persistentData ]
|
||||||
);
|
);
|
||||||
|
|
||||||
const setLocationProp = useCallback(
|
const setLocationProp = useCallback(
|
||||||
( prop, value ) => {
|
( prop, value ) => {
|
||||||
setStyles( ( prevState ) => ( {
|
setLocationStyles( {
|
||||||
...prevState,
|
...locationStyles,
|
||||||
[ location ]: {
|
[ prop ]: value,
|
||||||
...prevState[ location ],
|
} );
|
||||||
[ prop ]: value,
|
|
||||||
},
|
|
||||||
} ) );
|
|
||||||
},
|
},
|
||||||
[ location ]
|
[ locationStyles, setLocationStyles ]
|
||||||
);
|
);
|
||||||
// end of dummy implementation
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
persist,
|
persist,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue