Skip to content
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

Turn off DFM for style book and style editing #52117

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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( () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably have a hook to reuse the identical code, like useTurnOffDistractionFreeMode or something.

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