-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Small follow-ups to the distraction free mode PR #45151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,5 +242,4 @@ | |
position: absolute; | ||
z-index: 35; | ||
} | ||
|
||
} |
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'; | ||
|
@@ -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, | ||
|
@@ -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 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug fix where toggling distraction free would fail if the post was empty |
||
selectBlock( blocks[ 0 ].clientId ); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can probably get rid of all of these if we just not render them in distraction free mode (remove the inserter, remove list view, remove the sidebar) that way if you switch back to regular mode, they restore to their previous state. I didn't want to make that change here though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea commented to the original PR that this is the second option to this handler. It's a better way but it peppers the code with a lot of extra |
||
} ); | ||
}; | ||
|
||
const isLargeViewport = useViewportMatch( 'medium' ); | ||
|
@@ -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' ) } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,12 +124,6 @@ function Layout( { styles } ) { | |
documentLabel: postTypeLabel || _x( 'Document', 'noun' ), | ||
}; | ||
}, [] ); | ||
const [ distractionFree, setDistractionFree ] = | ||
useState( isDistractionFree ); | ||
|
||
useEffect( () => { | ||
setDistractionFree( isDistractionFree ); | ||
}, [ isDistractionFree ] ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK, this was useless local state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These bits of code are surprising. I wouldn't have added it for no reason :D 🤷🏻 Probably didnt remove it on iteration X when it wasn't needed anymore 🙇🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, sometimes it's hard to keep track of all the necessary/unnecessary bits as we iterate over feedback. |
||
|
||
const className = classnames( 'edit-post-layout', 'is-mode-' + mode, { | ||
'is-sidebar-opened': sidebarIsOpened, | ||
|
@@ -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 | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for prop passing from parent to children since we can access this here. The pro here is that the "Header" component becomes more reusable and if we remove the isDistractionFree selector from the parent it would result in a small perf optimization.