Skip to content

Commit

Permalink
Pass setting to block editor settings via Edit Site store
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jul 13, 2023
1 parent e0379fb commit 6bc1af6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
24 changes: 7 additions & 17 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { useRef, useState, useEffect } from '@wordpress/element';
import { focus } from '@wordpress/dom';
import { ENTER } from '@wordpress/keycodes';
import { isShallowEqualObjects } from '@wordpress/is-shallow-equal';
import { store as preferencesStore } from '@wordpress/preferences';
import { useSelect } from '@wordpress/data';

/**
Expand All @@ -26,6 +25,7 @@ import useCreatePage from './use-create-page';
import useInternalValue from './use-internal-value';
import { ViewerFill } from './viewer-slot';
import { DEFAULT_LINK_SETTINGS } from './constants';
import { store as blockEditorStore } from '../../store';

/**
* Default properties associated with a link control value.
Expand Down Expand Up @@ -135,22 +135,12 @@ function LinkControl( {
withCreateSuggestion = true;
}

const { settingsDrawerStatePreference } = useSelect( ( select ) => {
const prefsStore = select( preferencesStore );

const postEditorEnabled =
prefsStore.get( 'core/edit-post', 'linkControlSettingsDrawer' ) ??
false;

const siteEditorEnabled =
prefsStore.get( 'core/edit-site', 'linkControlSettingsDrawer' ) ??
false;

return {
settingsDrawerStatePreference:
postEditorEnabled || siteEditorEnabled,
};
}, [] );
const settingsDrawerStatePreference = useSelect(
( select ) =>
select( blockEditorStore ).getSettings()
.linkControlAdvancedSettingsPreference,
[]
);

const isMounting = useRef( true );
const wrapperNode = useRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { store as coreStore } from '@wordpress/core-data';
import { store as editSiteStore } from '../../store';
import { unlock } from '../../lock-unlock';
import inserterMediaCategories from './inserter-media-categories';
import { store as preferencesStore } from '@wordpress/preferences';

export default function useSiteEditorSettings( templateType ) {
const { storedSettings, canvasMode } = useSelect( ( select ) => {
Expand All @@ -22,6 +23,18 @@ export default function useSiteEditorSettings( templateType ) {
};
}, [] );

const { linkControlAdvancedSettingsPreference } = useSelect( ( select ) => {
const prefsStore = select( preferencesStore );

return {
linkControlAdvancedSettingsPreference:
prefsStore.get(
'core/edit-site',
'linkControlSettingsDrawer'
) ?? false,
};
}, [] );

const settingsBlockPatterns =
storedSettings.__experimentalAdditionalBlockPatterns ?? // WP 6.0
storedSettings.__experimentalBlockPatterns; // WP 5.9
Expand Down Expand Up @@ -82,6 +95,13 @@ export default function useSiteEditorSettings( templateType ) {
__experimentalBlockPatterns: blockPatterns,
__experimentalBlockPatternCategories: blockPatternCategories,
focusMode: canvasMode === 'view' && focusMode ? false : focusMode,
linkControlAdvancedSettingsPreference,
};
}, [ storedSettings, blockPatterns, blockPatternCategories, canvasMode ] );
}, [
storedSettings,
blockPatterns,
blockPatternCategories,
canvasMode,
linkControlAdvancedSettingsPreference,
] );
}

0 comments on commit 6bc1af6

Please sign in to comment.