Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add preference and use as initial state for drawer open/closed
  • Loading branch information
getdave committed Jul 5, 2023
commit 230c8edb42b4529e0ad0cd98bbd2eee16e016d7b
23 changes: 22 additions & 1 deletion packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ 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';

/**
* Internal dependencies
Expand Down Expand Up @@ -133,14 +135,33 @@ 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,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value should be determined based on which editor we are currently within. Else. setting from post editro will apply in Site Editor (and vice versa).

Any ideas or prior art on this. Maybe @talldan will know as he was the architect of the prefs store? 🙏

}, [] );

const isMounting = useRef( true );
const wrapperNode = useRef();
const textInputRef = useRef();
const isEndingEditWithFocus = useRef( false );

const settingsKeys = settings.map( ( { id } ) => id );

const [ settingsOpen, setSettingsOpen ] = useState( false );
const [ settingsOpen, setSettingsOpen ] = useState(
settingsDrawerStatePreference
);

const [
internalControlValue,
Expand Down
22 changes: 18 additions & 4 deletions packages/edit-post/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { __ } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
import { useSelect, useDispatch } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
import { useMemo, useCallback } from '@wordpress/element';
import {
PostTaxonomies,
PostExcerptCheck,
Expand Down Expand Up @@ -69,12 +69,17 @@ export default function EditPostPreferencesModal() {

const { set: setPreference } = useDispatch( preferencesStore );

const toggleDistractionFree = () => {
const toggleDistractionFree = useCallback( () => {
setPreference( 'core/edit-post', 'fixedToolbar', false );
setIsInserterOpened( false );
setIsListViewOpened( false );
closeGeneralSidebar();
};
}, [
closeGeneralSidebar,
setIsInserterOpened,
setIsListViewOpened,
setPreference,
] );

const sections = useMemo(
() => [
Expand Down Expand Up @@ -152,6 +157,15 @@ export default function EditPostPreferencesModal() {
label={ __( 'Display block breadcrumbs' ) }
/>
) }
<EnableFeature
featureName="linkControlSettingsDrawer"
help={ __(
`Toggle's default open/closed state of the link creation interface's settings drawer.`
) }
label={ __(
'Always open Link UI Settings Drawer'
) }
/>
</PreferencesModalSection>
</>
),
Expand Down Expand Up @@ -252,7 +266,7 @@ export default function EditPostPreferencesModal() {
),
},
],
[ isLargeViewport, showBlockBreadcrumbsOption ]
[ isLargeViewport, showBlockBreadcrumbsOption, toggleDistractionFree ]
);

if ( ! isModalActive ) {
Expand Down
13 changes: 10 additions & 3 deletions packages/edit-site/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
PreferencesModalSection,
store as interfaceStore,
} from '@wordpress/interface';
import { useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';
Expand Down Expand Up @@ -41,7 +40,7 @@ export default function EditSitePreferencesModal() {
} );
};

const sections = useMemo( () => [
const sections = [
{
name: 'general',
tabLabel: __( 'General' ),
Expand Down Expand Up @@ -86,6 +85,13 @@ export default function EditSitePreferencesModal() {
) }
label={ __( 'Display block breadcrumbs' ) }
/>
<EnableFeature
featureName="linkControlSettingsDrawer"
help={ __(
`Toggle's default open/closed state of the link creation interface's settings drawer.`
) }
label={ __( 'Always open Link UI Settings Drawer' ) }
/>
</PreferencesModalSection>
),
},
Expand All @@ -109,7 +115,8 @@ export default function EditSitePreferencesModal() {
</PreferencesModalSection>
),
},
] );
];

if ( ! isModalActive ) {
return null;
}
Expand Down