Skip to content

Commit

Permalink
Wait for pattern on new course, else show right away
Browse files Browse the repository at this point in the history
  • Loading branch information
Imran92 committed Dec 15, 2023
1 parent e84c62a commit f749ad7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions assets/js/admin/first-course-creation-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const handleFirstCourseCreationHelperNotice = () => {
firstCourseNoticeDismissedKey
);
const noticeId = 'course-outline-block-setup-incomplete';
const isNewCourse = window?.sensei?.isNewCourse;

let noticeCreated = false;
let noticeRemoved = false;
Expand All @@ -139,7 +140,6 @@ export const handleFirstCourseCreationHelperNotice = () => {

subscribe( () => {
if (
isSenseiPatternSelected() &&
noticeCreated &&
! noticeRemoved &&
hasOutlineBlock() &&
Expand All @@ -150,9 +150,9 @@ export const handleFirstCourseCreationHelperNotice = () => {
removeNotice( noticeId );

Check warning on line 150 in assets/js/admin/first-course-creation-notice.js

View check run for this annotation

Codecov / codecov/patch

assets/js/admin/first-course-creation-notice.js#L148-L150

Added lines #L148 - L150 were not covered by tests
}

// If the user selects a Sensei pattern, and the notice hasn't been created, and notice hasn't been dismissed, and either the course outline block hasn't been created OR there are no published lessons in the outline, create the notice.
// If the user selects a Sensei pattern or editing an existing Course, and the notice hasn't been created, and notice hasn't been dismissed, and either the course outline block hasn't been created OR there are no published lessons in the outline, create the notice.
if (
isSenseiPatternSelected() &&
( isNewCourse ? isSenseiPatternSelected() : true ) &&
! noticeCreated &&
! isFirstCourseNoticeDismissed &&
! (
Expand Down
14 changes: 13 additions & 1 deletion includes/class-sensei-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,12 @@ private function display_courses_navigation( WP_Screen $screen, array $tabs ) {
/**
* Register and enqueue scripts and styles that are needed in the backend.
*
* @param string $hook_suffix The current admin page.
*
* @access private
* @since 2.1.0
*/
public function register_admin_scripts() {
public function register_admin_scripts( $hook_suffix ) {

Check warning on line 456 in includes/class-sensei-course.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-course.php#L456

Added line #L456 was not covered by tests
$screen = get_current_screen();
if ( ! $screen ) {
return;
Expand Down Expand Up @@ -494,6 +496,16 @@ public function register_admin_scripts() {
$has_lessons_with_courses = count( $user_lessons_query->posts ) > 0;

Check warning on line 496 in includes/class-sensei-course.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-course.php#L495-L496

Added lines #L495 - L496 were not covered by tests

if ( ! $has_lessons_with_courses ) {
$post_id = get_the_ID();
$new_post = $post_id && get_post_meta( $post_id, '_new_post', true );
$is_new_post = 'post-new.php' === $hook_suffix || $new_post;

Check warning on line 501 in includes/class-sensei-course.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-course.php#L498-L501

Added lines #L498 - L501 were not covered by tests

wp_add_inline_script(
'sensei-admin-course-edit',
sprintf( 'window.sensei = window.sensei || {}; window.sensei.isNewCourse = %s;', ( $is_new_post ? 'true' : 'false' ) ),
'before'
);

Check warning on line 507 in includes/class-sensei-course.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-course.php#L503-L507

Added lines #L503 - L507 were not covered by tests

Sensei()->assets->enqueue( 'sensei-admin-first-course-creation-notice', 'js/admin/first-course-creation-notice.js', [ 'sensei-admin-course-edit' ], true );

Check warning on line 509 in includes/class-sensei-course.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-course.php#L509

Added line #L509 was not covered by tests
}
}
Expand Down

0 comments on commit f749ad7

Please sign in to comment.