Skip to content

Commit

Permalink
Turn off DFM for style book and style editing (#52117)
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu authored and tellthemachines committed Jul 7, 2023
1 parent 2930ef4 commit 859112d
Showing 1 changed file with 47 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,27 @@ export function SidebarNavigationItemGlobalStyles( props ) {
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
const { createNotice } = useDispatch( noticesStore );
const { set: setPreference } = useDispatch( preferencesStore );
const { hasGlobalStyleVariations, isDistractionFree } = useSelect(
( select ) => ( {
hasGlobalStyleVariations:
!! select(
coreStore
).__experimentalGetCurrentThemeGlobalStylesVariations()?.length,
isDistractionFree: select( preferencesStore ).get(
editSiteStore.name,
'distractionFree'
),
} ),
const { get: getPrefference } = useSelect( preferencesStore );

const turnOffDistractionFreeMode = useCallback( () => {
const isDistractionFree = getPrefference(
editSiteStore.name,
'distractionFree'
);
if ( ! isDistractionFree ) {
return;
}
setPreference( editSiteStore.name, 'distractionFree', false );
createNotice( 'info', __( 'Distraction free mode turned off' ), {
isDismissible: true,
type: 'snackbar',
} );
}, [ createNotice, setPreference, getPrefference ] );
const hasGlobalStyleVariations = useSelect(
( select ) =>
!! select(
coreStore
).__experimentalGetCurrentThemeGlobalStylesVariations()?.length,
[]
);
if ( hasGlobalStyleVariations ) {
Expand All @@ -63,19 +73,7 @@ export function SidebarNavigationItemGlobalStyles( props ) {
<SidebarNavigationItem
{ ...props }
onClick={ () => {
// Disable distraction free mode.
if ( isDistractionFree ) {
setPreference(
editSiteStore.name,
'distractionFree',
false
);
createNotice(
'info',
__( 'Distraction free mode turned off.' ),
{ type: 'snackbar' }
);
}
turnOffDistractionFreeMode();
// Switch to edit mode.
setCanvasMode( 'edit' );
// Open global styles sidebar.
Expand Down Expand Up @@ -170,6 +168,9 @@ export default function SidebarNavigationScreenGlobalStyles() {
const { setCanvasMode, setEditorCanvasContainerView } = unlock(
useDispatch( editSiteStore )
);
const { createNotice } = useDispatch( noticesStore );
const { set: setPreference } = useDispatch( preferencesStore );
const { get: getPrefference } = useSelect( preferencesStore );

const isStyleBookOpened = useSelect(
( select ) =>
Expand All @@ -178,14 +179,28 @@ export default function SidebarNavigationScreenGlobalStyles() {
[]
);

const openGlobalStyles = useCallback(
async () =>
Promise.all( [
setCanvasMode( 'edit' ),
openGeneralSidebar( 'edit-site/global-styles' ),
] ),
[ setCanvasMode, openGeneralSidebar ]
);
const turnOffDistractionFreeMode = useCallback( () => {
const isDistractionFree = getPrefference(
editSiteStore.name,
'distractionFree'
);
if ( ! isDistractionFree ) {
return;
}
setPreference( editSiteStore.name, 'distractionFree', false );
createNotice( 'info', __( 'Distraction free mode turned off' ), {
isDismissible: true,
type: 'snackbar',
} );
}, [ createNotice, setPreference, getPrefference ] );

const openGlobalStyles = useCallback( async () => {
turnOffDistractionFreeMode();
return Promise.all( [
setCanvasMode( 'edit' ),
openGeneralSidebar( 'edit-site/global-styles' ),
] );
}, [ setCanvasMode, openGeneralSidebar, turnOffDistractionFreeMode ] );

const openStyleBook = useCallback( async () => {
await openGlobalStyles();
Expand Down

0 comments on commit 859112d

Please sign in to comment.