Skip to content

Commit

Permalink
Suppress the template part hint for all themes
Browse files Browse the repository at this point in the history
  • Loading branch information
okmttdhr committed Dec 6, 2023
1 parent 9f799d4 commit 999ed05
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions apps/wpcom-block-editor/src/wpcom/features/live-preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const LivePreviewNotice: FC< {
previewingThemeName?: string;
} > = ( { previewingThemeName } ) => {
const { createWarningNotice, removeNotice } = useDispatch( 'core/notices' );
const { set: setPreferences } = useDispatch( 'core/preferences' );

const siteEditorStore = useSelect( ( select ) => select( 'core/edit-site' ), [] );
const dashboardLink =
Expand All @@ -39,10 +38,6 @@ const LivePreviewNotice: FC< {
return;
}

// Suppress the "Looking for template parts?" notice in the Site Editor sidebar.
// The preference name is defined in https://github.com/WordPress/gutenberg/blob/d47419499cd58e20db25c370cdbf02ddf7cffce0/packages/edit-site/src/components/sidebar-navigation-screen-main/template-part-hint.js#L9.
setPreferences( 'core', 'isTemplatePartMoveHintVisible', false );

createWarningNotice(
sprintf(
// translators: %s: theme name
Expand All @@ -65,22 +60,30 @@ const LivePreviewNotice: FC< {
}
);
return () => removeNotice( NOTICE_ID );
}, [
siteEditorStore,
dashboardLink,
setPreferences,
createWarningNotice,
removeNotice,
previewingThemeName,
] );
}, [ siteEditorStore, dashboardLink, createWarningNotice, removeNotice, previewingThemeName ] );
return null;
};

const LivePreviewNoticePlugin = () => {
const siteEditorStore = useSelect( ( select ) => select( 'core/edit-site' ), [] );
const previewingTheme = usePreviewingTheme();
const { canPreviewButNeedUpgrade, upgradePlan } = useCanPreviewButNeedUpgrade( {
previewingTheme,
} );

const { set: setPreferences } = useDispatch( 'core/preferences' );
useEffect( () => {
if ( ! siteEditorStore ) {
return;
}
if ( ! previewingTheme.name ) {
return;
}
// Suppress the "Looking for template parts?" notice in the Site Editor sidebar.
// The preference name is defined in https://github.com/WordPress/gutenberg/blob/d47419499cd58e20db25c370cdbf02ddf7cffce0/packages/edit-site/src/components/sidebar-navigation-screen-main/template-part-hint.js#L9.
setPreferences( 'core', 'isTemplatePartMoveHintVisible', false );
}, [ previewingTheme.name, setPreferences, siteEditorStore ] );

if ( canPreviewButNeedUpgrade ) {
return <LivePreviewUpgradeNotice { ...{ previewingTheme, upgradePlan } } />;
}
Expand Down

0 comments on commit 999ed05

Please sign in to comment.