Skip to content

Commit

Permalink
make top toolbar and distraction free work in tandem across editors a…
Browse files Browse the repository at this point in the history
…nd preference UIs
  • Loading branch information
draganescu committed Nov 28, 2023
1 parent fee46cf commit 5082611
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 47 deletions.
34 changes: 16 additions & 18 deletions packages/edit-post/src/components/header/writing-menu/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import { useDispatch, useRegistry } from '@wordpress/data';
import { MenuGroup } from '@wordpress/components';
import { __, _x } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
Expand All @@ -10,7 +10,6 @@ import {
PreferenceToggleMenuItem,
store as preferencesStore,
} from '@wordpress/preferences';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -19,11 +18,6 @@ import { store as postEditorStore } from '../../../store';

function WritingMenu() {
const registry = useRegistry();
const isDistractionFree = useSelect(
( select ) =>
select( blockEditorStore ).getSettings().isDistractionFree,
[]
);

const { setIsInserterOpened, setIsListViewOpened, closeGeneralSidebar } =
useDispatch( postEditorStore );
Expand All @@ -38,6 +32,10 @@ function WritingMenu() {
} );
};

const turnOffDistractionFree = () => {
setPreference( 'core/edit-post', 'distractionFree', false );
};

const isLargeViewport = useViewportMatch( 'medium' );
if ( ! isLargeViewport ) {
return null;
Expand All @@ -47,15 +45,25 @@ function WritingMenu() {
<MenuGroup label={ _x( 'View', 'noun' ) }>
<PreferenceToggleMenuItem
scope="core/edit-post"
disabled={ isDistractionFree }
name="fixedToolbar"
onToggle={ turnOffDistractionFree }
label={ __( 'Top toolbar' ) }
info={ __(
'Access all block and document tools in a single place'
) }
messageActivated={ __( 'Top toolbar activated' ) }
messageDeactivated={ __( 'Top toolbar deactivated' ) }
/>
<PreferenceToggleMenuItem
scope="core/edit-post"
name="distractionFree"
onToggle={ toggleDistractionFree }
label={ __( 'Distraction free' ) }
info={ __( 'Write with calmness' ) }
messageActivated={ __( 'Distraction free mode activated' ) }
messageDeactivated={ __( 'Distraction free mode deactivated' ) }
shortcut={ displayShortcut.primaryShift( '\\' ) }
/>
<PreferenceToggleMenuItem
scope="core/edit-post"
name="focusMode"
Expand All @@ -73,16 +81,6 @@ function WritingMenu() {
messageDeactivated={ __( 'Fullscreen mode deactivated' ) }
shortcut={ displayShortcut.secondary( 'f' ) }
/>
<PreferenceToggleMenuItem
scope="core/edit-post"
name="distractionFree"
onToggle={ toggleDistractionFree }
label={ __( 'Distraction free' ) }
info={ __( 'Write with calmness' ) }
messageActivated={ __( 'Distraction free mode activated' ) }
messageDeactivated={ __( 'Distraction free mode deactivated' ) }
shortcut={ displayShortcut.primaryShift( '\\' ) }
/>
</MenuGroup>
);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/edit-post/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export default function EditPostPreferencesModal() {
closeGeneralSidebar();
};

const turnOffDistractionFree = () => {
setPreference( 'core/edit-post', 'distractionFree', false );
};

const sections = useMemo(
() => [
{
Expand Down Expand Up @@ -171,6 +175,7 @@ export default function EditPostPreferencesModal() {
>
<EnableFeature
featureName="fixedToolbar"
onToggle={ turnOffDistractionFree }
help={ __(
'Access all block and document tools in a single place.'
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import { useDispatch, useRegistry } from '@wordpress/data';
import { displayShortcut } from '@wordpress/keycodes';
import { external } from '@wordpress/icons';
import { MenuGroup, MenuItem, VisuallyHidden } from '@wordpress/components';
Expand Down Expand Up @@ -36,14 +36,6 @@ import { store as siteEditorStore } from '../../../store';

export default function MoreMenu( { showIconLabels } ) {
const registry = useRegistry();
const isDistractionFree = useSelect(
( select ) =>
select( preferencesStore ).get(
'core/edit-site',
'distractionFree'
),
[]
);

const { setIsInserterOpened, setIsListViewOpened, closeGeneralSidebar } =
useDispatch( siteEditorStore );
Expand All @@ -59,6 +51,10 @@ export default function MoreMenu( { showIconLabels } ) {
} );
};

const turnOffDistractionFree = () => {
setPreference( 'core/edit-site', 'distractionFree', false );
};

return (
<>
<MoreMenuDropdown
Expand All @@ -73,7 +69,7 @@ export default function MoreMenu( { showIconLabels } ) {
<PreferenceToggleMenuItem
scope="core/edit-site"
name="fixedToolbar"
disabled={ isDistractionFree }
onToggle={ turnOffDistractionFree }
label={ __( 'Top toolbar' ) }
info={ __(
'Access all block and document tools in a single place'
Expand All @@ -85,18 +81,6 @@ export default function MoreMenu( { showIconLabels } ) {
'Top toolbar deactivated'
) }
/>
<PreferenceToggleMenuItem
scope="core/edit-site"
name="focusMode"
label={ __( 'Spotlight mode' ) }
info={ __( 'Focus on one block at a time' ) }
messageActivated={ __(
'Spotlight mode activated'
) }
messageDeactivated={ __(
'Spotlight mode deactivated'
) }
/>
<PreferenceToggleMenuItem
scope="core/edit-site"
name="distractionFree"
Expand All @@ -113,6 +97,18 @@ export default function MoreMenu( { showIconLabels } ) {
'\\'
) }
/>
<PreferenceToggleMenuItem
scope="core/edit-site"
name="focusMode"
label={ __( 'Spotlight mode' ) }
info={ __( 'Focus on one block at a time' ) }
messageActivated={ __(
'Spotlight mode activated'
) }
messageDeactivated={ __(
'Spotlight mode deactivated'
) }
/>
</MenuGroup>
<ModeSwitcher />
<ActionItem.Slot
Expand Down
12 changes: 5 additions & 7 deletions packages/edit-site/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default function EditSitePreferencesModal() {
} );
};

const turnOffDistractionFree = () => {
setPreference( 'core/edit-site', 'distractionFree', false );
};

const sections = useMemo( () => [
{
name: 'general',
Expand Down Expand Up @@ -76,6 +80,7 @@ export default function EditSitePreferencesModal() {
>
<EnableFeature
featureName="fixedToolbar"
onToggle={ turnOffDistractionFree }
help={ __(
'Access all block and document tools in a single place.'
) }
Expand All @@ -96,13 +101,6 @@ export default function EditSitePreferencesModal() {
) }
label={ __( 'Spotlight mode' ) }
/>
<EnableFeature
featureName="showBlockBreadcrumbs"
help={ __(
'Shows block breadcrumbs at the bottom of the editor.'
) }
label={ __( 'Display block breadcrumbs' ) }
/>
</PreferencesModalSection>
),
},
Expand Down

0 comments on commit 5082611

Please sign in to comment.