Skip to content

Commit

Permalink
Use private selectors and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Sep 20, 2023
1 parent 94a3440 commit 33dbc93
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 1 addition & 2 deletions packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export default function AddNewPattern() {
const settings = select( editSiteStore ).getSettings();
return !! settings.supportsTemplatePartsMode;
}, [] );
const { __experimentalCreatePatternFromFile: createPatternFromFile } =
useDispatch( patternsStore );
const { createPatternFromFile } = unlock( useDispatch( patternsStore ) );
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );
const patternUploadInputRef = useRef();
Expand Down
5 changes: 3 additions & 2 deletions packages/patterns/src/components/create-pattern-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import { PATTERN_DEFAULT_CATEGORY, PATTERN_SYNC_TYPES } from '../constants';
/**
* Internal dependencies
*/
import { store } from '../store';
import { store as patternsStore } from '../store';
import CategorySelector from './category-selector';
import { unlock } from '../lock-unlock';

export default function CreatePatternModal( {
onSuccess,
Expand All @@ -35,7 +36,7 @@ export default function CreatePatternModal( {
const [ syncType, setSyncType ] = useState( PATTERN_SYNC_TYPES.full );
const [ categories, setCategories ] = useState( [] );
const [ title, setTitle ] = useState( '' );
const { createPattern } = useDispatch( store );
const { createPattern } = unlock( useDispatch( patternsStore ) );

const { createErrorNotice } = useDispatch( noticesStore );
async function onCreate( patternTitle, sync ) {
Expand Down
7 changes: 5 additions & 2 deletions packages/patterns/src/components/pattern-convert-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { store as noticesStore } from '@wordpress/notices';
*/
import { store as patternsStore } from '../store';
import CreatePatternModal from './create-pattern-modal';
import { unlock } from '../lock-unlock';

/**
* Menu control to convert block(s) to a pattern block.
Expand All @@ -32,7 +33,9 @@ import CreatePatternModal from './create-pattern-modal';
export default function PatternConvertButton( { clientIds, rootClientId } ) {
const { createSuccessNotice } = useDispatch( noticesStore );
const { replaceBlocks } = useDispatch( blockEditorStore );
const { __experimentalSetEditingPattern } = useDispatch( patternsStore );
// Ignore reason: false positive of the lint rule.
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
const { setEditingPattern } = unlock( useDispatch( patternsStore ) );
const [ isModalOpen, setIsModalOpen ] = useState( false );
const canConvert = useSelect(
( select ) => {
Expand Down Expand Up @@ -98,7 +101,7 @@ export default function PatternConvertButton( { clientIds, rootClientId } ) {
} );

replaceBlocks( clientIds, newBlock );
__experimentalSetEditingPattern( newBlock.clientId, true );
setEditingPattern( newBlock.clientId, true );

createSuccessNotice(
pattern.wp_pattern_sync_status === 'unsynced'
Expand Down
9 changes: 7 additions & 2 deletions packages/patterns/src/components/patterns-manage-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { store as coreStore } from '@wordpress/core-data';
/**
* Internal dependencies
*/
import { store as editorStore } from '../store';
import { store as patternsStore } from '../store';
import { unlock } from '../lock-unlock';

function PatternsManageButton( { clientId } ) {
const { canRemove, isVisible, innerBlockCount, managePatternsUrl } =
Expand Down Expand Up @@ -51,7 +52,11 @@ function PatternsManageButton( { clientId } ) {
[ clientId ]
);

const { convertSyncedPatternToStatic } = useDispatch( editorStore );
// Ignore reason: false positive of the lint rule.
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
const { convertSyncedPatternToStatic } = unlock(
useDispatch( patternsStore )
);

if ( ! isVisible ) {
return null;
Expand Down
5 changes: 3 additions & 2 deletions packages/patterns/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import reducer from './reducer';
import * as actions from './actions';
import { STORE_NAME } from './constants';
import * as selectors from './selectors';
import { unlock } from '../lock-unlock';

/**
* Post editor data store configuration.
Expand All @@ -20,8 +21,6 @@ import * as selectors from './selectors';
*/
export const storeConfig = {
reducer,
selectors,
actions,
};

/**
Expand All @@ -36,3 +35,5 @@ export const store = createReduxStore( STORE_NAME, {
} );

register( store );
unlock( store ).registerPrivateActions( actions );
unlock( store ).registerPrivateSelectors( selectors );

0 comments on commit 33dbc93

Please sign in to comment.