-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Post Editor: Port editor to use viewport module
- Loading branch information
Showing
14 changed files
with
61 additions
and
252 deletions.
There are no files selected for viewing
40 changes: 16 additions & 24 deletions
40
edit-post/components/header/fixed-toolbar-toggle/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,41 @@ | ||
/** | ||
* External Dependencies | ||
* WordPress Dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
|
||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { compose } from '@wordpress/element'; | ||
import { MenuItemsGroup, MenuItemsToggle, withInstanceId } from '@wordpress/components'; | ||
import { ifViewportMatches } from '@wordpress/viewport'; | ||
|
||
/** | ||
* Internal Dependencies | ||
*/ | ||
import { hasFixedToolbar, isMobile } from '../../../store/selectors'; | ||
import { toggleFeature } from '../../../store/actions'; | ||
|
||
function FeatureToggle( { onToggle, active, onMobile } ) { | ||
if ( onMobile ) { | ||
return null; | ||
} | ||
function FeatureToggle( { onToggle, isActive } ) { | ||
return ( | ||
<MenuItemsGroup | ||
label={ __( 'Settings' ) } | ||
filterName="editPost.MoreMenu.settings" | ||
> | ||
<MenuItemsToggle | ||
label={ __( 'Fix Toolbar to Top' ) } | ||
isSelected={ active } | ||
isSelected={ isActive } | ||
onClick={ onToggle } | ||
/> | ||
</MenuItemsGroup> | ||
); | ||
} | ||
|
||
export default connect( | ||
( state ) => ( { | ||
active: hasFixedToolbar( state ), | ||
onMobile: isMobile( state ), | ||
} ), | ||
( dispatch, ownProps ) => ( { | ||
export default compose( [ | ||
withSelect( ( select ) => ( { | ||
isActive: select( 'core/edit-post' ).isFeatureActive( 'fixedToolbar' ), | ||
} ) ), | ||
withDispatch( ( dispatch, ownProps ) => ( { | ||
onToggle() { | ||
dispatch( toggleFeature( 'fixedToolbar' ) ); | ||
dispatch( 'core/edit-post' ).toggleFeature( 'fixedToolbar' ); | ||
ownProps.onToggle(); | ||
}, | ||
} ), | ||
undefined, | ||
{ storeKey: 'edit-post' } | ||
)( withInstanceId( FeatureToggle ) ); | ||
} ) ), | ||
ifViewportMatches( 'medium' ), | ||
withInstanceId, | ||
] )( FeatureToggle ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
/** | ||
* WordPress Dependencies | ||
*/ | ||
import { registerReducer, withRehydratation, loadAndPersist } from '@wordpress/data'; | ||
import { | ||
registerStore, | ||
withRehydratation, | ||
loadAndPersist, | ||
subscribe, | ||
dispatch, | ||
} from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import reducer from './reducer'; | ||
import enhanceWithBrowserSize from './mobile'; | ||
import { BREAK_MEDIUM } from './constants'; | ||
import * as actions from './actions'; | ||
import * as selectors from './selectors'; | ||
|
||
/** | ||
* Module Constants | ||
*/ | ||
const STORAGE_KEY = `WP_EDIT_POST_PREFERENCES_${ window.userSettings.uid }`; | ||
const MODULE_KEY = 'core/edit-post'; | ||
|
||
const store = registerReducer( MODULE_KEY, withRehydratation( reducer, 'preferences', STORAGE_KEY ) ); | ||
const store = registerStore( 'core/edit-post', { | ||
reducer: withRehydratation( reducer, 'preferences', STORAGE_KEY ), | ||
actions, | ||
selectors, | ||
} ); | ||
|
||
loadAndPersist( store, reducer, 'preferences', STORAGE_KEY ); | ||
enhanceWithBrowserSize( store, BREAK_MEDIUM ); | ||
|
||
subscribe( 'core/viewport', [ 'isViewportMatch', '< medium' ], ( isSmall ) => { | ||
// Collapse sidebar when viewport shrinks. | ||
if ( isSmall ) { | ||
dispatch( 'core/edit-post' ).closeGeneralSidebar(); | ||
} | ||
} ); | ||
|
||
export default store; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.