Skip to content

Commit

Permalink
Small follow-ups to the distraction free mode PR (#45151)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 24, 2022
1 parent 67cdd8c commit 27b8374
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
5 changes: 4 additions & 1 deletion packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import MainDashboardButton from './main-dashboard-button';
import { store as editPostStore } from '../../store';
import TemplateTitle from './template-title';

function Header( { setEntitiesSavedStatesCallback, isDistractionFree } ) {
function Header( { setEntitiesSavedStatesCallback } ) {
const {
hasActiveMetaboxes,
isPublishSidebarOpened,
isSaving,
showIconLabels,
isDistractionFree,
} = useSelect(
( select ) => ( {
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
Expand All @@ -38,6 +39,8 @@ function Header( { setEntitiesSavedStatesCallback, isDistractionFree } ) {
isSaving: select( editPostStore ).isSavingMetaBoxes(),
showIconLabels:
select( editPostStore ).isFeatureActive( 'showIconLabels' ),
isDistractionFree:
select( editPostStore ).isFeatureActive( 'distractionFree' ),
} ),
[]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const MoreMenu = ( { showIconLabels } ) => {
scope="core/edit-post"
/>
) }
<WritingMenu onClose={ onClose } />
<WritingMenu />
<ModeSwitcher />
<ActionItem.Slot
name="core/edit-post/plugin-more-menu"
Expand Down
1 change: 0 additions & 1 deletion packages/edit-post/src/components/header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,4 @@
position: absolute;
z-index: 35;
}

}
24 changes: 13 additions & 11 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 } from '@wordpress/data';
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
import { MenuGroup } from '@wordpress/components';
import { __, _x } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
Expand All @@ -17,7 +17,8 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
*/
import { store as postEditorStore } from '../../../store';

function WritingMenu( { onClose } ) {
function WritingMenu() {
const registry = useRegistry();
const isDistractionFree = useSelect(
( select ) =>
select( blockEditorStore ).getSettings().isDistractionFree,
Expand All @@ -36,14 +37,15 @@ function WritingMenu( { onClose } ) {
const { selectBlock } = useDispatch( blockEditorStore );

const toggleDistractionFree = () => {
setPreference( 'core/edit-post', 'fixedToolbar', false );
setIsInserterOpened( false );
setIsListViewOpened( false );
closeGeneralSidebar();
onClose();
if ( ! isDistractionFree ) {
selectBlock( blocks[ 0 ].clientId );
}
registry.batch( () => {
setPreference( 'core/edit-post', 'fixedToolbar', false );
setIsInserterOpened( false );
setIsListViewOpened( false );
closeGeneralSidebar();
if ( ! isDistractionFree && !! blocks.length ) {
selectBlock( blocks[ 0 ].clientId );
}
} );
};

const isLargeViewport = useViewportMatch( 'medium' );
Expand Down Expand Up @@ -84,7 +86,7 @@ function WritingMenu( { onClose } ) {
<PreferenceToggleMenuItem
scope="core/edit-post"
name="distractionFree"
toggleHandler={ toggleDistractionFree }
onToggle={ toggleDistractionFree }
label={ __( 'Distraction free' ) }
info={ __( 'Write with calmness' ) }
messageActivated={ __( 'Distraction free mode activated' ) }
Expand Down
9 changes: 1 addition & 8 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ function Layout( { styles } ) {
documentLabel: postTypeLabel || _x( 'Document', 'noun' ),
};
}, [] );
const [ distractionFree, setDistractionFree ] =
useState( isDistractionFree );

useEffect( () => {
setDistractionFree( isDistractionFree );
}, [ isDistractionFree ] );

const className = classnames( 'edit-post-layout', 'is-mode-' + mode, {
'is-sidebar-opened': sidebarIsOpened,
Expand Down Expand Up @@ -207,15 +201,14 @@ function Layout( { styles } ) {
<EditorKeyboardShortcutsRegister />
<SettingsSidebar />
<InterfaceSkeleton
isDistractionFree={ distractionFree }
isDistractionFree={ isDistractionFree }
className={ className }
labels={ {
...interfaceLabels,
secondarySidebar: secondarySidebarLabel,
} }
header={
<Header
isDistractionFree={ distractionFree }
setEntitiesSavedStatesCallback={
setEntitiesSavedStatesCallback
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function PreferenceToggleMenuItem( {
messageActivated,
messageDeactivated,
shortcut,
toggleHandler = () => null,
onToggle = () => null,
disabled = false,
} ) {
const isActive = useSelect(
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function PreferenceToggleMenuItem( {
icon={ isActive && check }
isSelected={ isActive }
onClick={ () => {
toggleHandler();
onToggle();
toggle( scope, name );
speakMessage();
} }
Expand Down

0 comments on commit 27b8374

Please sign in to comment.