Skip to content

Commit

Permalink
Merge pull request #7511 from Automattic/fix/patterns-flicker-on-wpcom
Browse files Browse the repository at this point in the history
Fix patterns flicker on WPCOM
  • Loading branch information
renatho authored Mar 1, 2024
2 parents 934e47d + e550666 commit 9b96aee
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
25 changes: 2 additions & 23 deletions assets/admin/editor-wizard/editor-wizard-modal.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* WordPress dependencies
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { useDispatch } from '@wordpress/data';
import { Modal } from '@wordpress/components';
import { useEffect, useState } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { store as editorStore } from '@wordpress/editor';

/**
Expand Down Expand Up @@ -47,27 +47,6 @@ const EditorWizardModal = () => {
onWizardCompletion();
};

const { setShowWelcomeGuide } =
useDispatch( 'automattic/wpcom-welcome-guide' ) ?? {};

const { isShowWelcomeGuide } = useSelect( ( select ) => {
const { isWelcomeGuideShown } =
select( 'automattic/wpcom-welcome-guide' ) ?? {};
return {
isShowWelcomeGuide: isWelcomeGuideShown
? isWelcomeGuideShown()
: false,
};
}, [] );

useEffect( () => {
if ( setShowWelcomeGuide && isShowWelcomeGuide ) {
setShowWelcomeGuide( undefined, {
onlyLocal: true,
} );
}
}, [ setShowWelcomeGuide, isShowWelcomeGuide ] );

return (
open && (
<Modal
Expand Down
8 changes: 8 additions & 0 deletions assets/admin/editor-wizard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
* WordPress dependencies
*/
import { registerPlugin } from '@wordpress/plugins';
import { addFilter } from '@wordpress/hooks';

/**
* Internal dependencies
*/
import EditorWizardModal from './editor-wizard-modal';

// Hide welcome tour from WPCOM.
addFilter(
'a8c.WpcomBlockEditorWelcomeTour.show',
'sensei-lms/editor-wizard',
() => false
);

registerPlugin( 'sensei-editor-wizard-plugin', {
render: EditorWizardModal,
icon: null,
Expand Down
4 changes: 4 additions & 0 deletions changelog/fix-patterns-flicker-on-wpcom
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Address the issue of patterns flickering in the editor wizard on WPCOM sites
20 changes: 17 additions & 3 deletions includes/admin/class-sensei-editor-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public static function instance() {
*/
public function init() {
add_action( 'init', [ $this, 'register_post_metas' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
// Priority 9 to make sure it will run before the block editor nux on WPCOM. While this code is written, it uses priority 100.
add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_editor_wizard_assets' ], 9 );
}

/**
Expand Down Expand Up @@ -76,13 +77,26 @@ public function register_post_metas() {
* @param string $hook_suffix The current admin page.
*
* @access private
*
* @deprecated $$next-version$$ use Sensei_Editor_Wizard::enqueue_editor_wizard_assets instead.
*/
public function enqueue_admin_scripts( $hook_suffix ) {
public function enqueue_admin_scripts( $hook_suffix ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
_deprecated_function( __METHOD__, '$$next-version$$', 'Sensei_Editor_Wizard::enqueue_editor_wizard_assets' );

$this->enqueue_editor_wizard_assets();
}

/**
* Enqueue editor wizard assets.
*/
public function enqueue_editor_wizard_assets() {
global $pagenow;

$post_type = get_post_type();
$post_id = get_the_ID();
$new_post = get_post_meta( $post_id, '_new_post', true );
$post_types = [ 'course', 'lesson' ];
$is_new_post = 'post-new.php' === $hook_suffix || $new_post;
$is_new_post = 'post-new.php' === $pagenow || $new_post;

if ( $is_new_post && in_array( $post_type, $post_types, true ) ) {
Sensei()->assets->enqueue( 'sensei-editor-wizard-script', 'admin/editor-wizard/index.js' );
Expand Down

0 comments on commit 9b96aee

Please sign in to comment.