Skip to content

Commit bf23df6

Browse files
authored
Merge pull request #512 from ProgressPlanner/filip/v16/more-celebration-tweaks
More celebration tweaks
2 parents 8eb6be0 + 1a6ec1f commit bf23df6

3 files changed

Lines changed: 37 additions & 44 deletions

File tree

assets/js/widgets/suggested-tasks.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,34 @@ const prplSuggestedTasksWidget = {
4444
per_page: prplSuggestedTask.maxItemsPerCategory[ category ],
4545
} );
4646

47-
// Inject pending celebration tasks.
48-
celebrationPromises.push(
49-
prplSuggestedTask
50-
.injectItemsFromCategory( {
51-
category,
52-
status: [ 'pending' ],
53-
per_page: 100,
54-
} )
55-
.then( ( data ) => {
56-
// If there were pending tasks.
57-
if ( data.length ) {
58-
// Set post status to trash.
59-
data.forEach( ( task ) => {
60-
const post =
61-
new wp.api.models.Prpl_recommendations( {
62-
id: task.id,
63-
} );
64-
// Destroy the post, without the force parameter.
65-
post.destroy( { url: post.url() } );
66-
} );
67-
}
68-
} )
69-
);
47+
// We trigger celebration only on Progress Planner dashboard page.
48+
if ( ! prplSuggestedTask.delayCelebration ) {
49+
// Inject pending celebration tasks.
50+
celebrationPromises.push(
51+
prplSuggestedTask
52+
.injectItemsFromCategory( {
53+
category,
54+
status: [ 'pending' ],
55+
per_page: 100,
56+
} )
57+
.then( ( data ) => {
58+
// If there were pending tasks.
59+
if ( data.length ) {
60+
// Set post status to trash.
61+
data.forEach( ( task ) => {
62+
const post =
63+
new wp.api.models.Prpl_recommendations(
64+
{
65+
id: task.id,
66+
}
67+
);
68+
// Destroy the post, without the force parameter.
69+
post.destroy( { url: post.url() } );
70+
} );
71+
}
72+
} )
73+
);
74+
}
7075
}
7176

7277
// Trigger celebration once, for all categories.

classes/admin/class-enqueue.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ public function localize_script( $handle, $localize_data = [] ) {
219219
if ( isset( $max_items_per_category['user'] ) ) {
220220
$max_items_per_category['user'] = 100;
221221
}
222+
223+
// Celebrate only on the Progress Planner Dashboard page.
224+
$delay_celebration = true;
225+
if ( \progress_planner()->is_on_progress_planner_dashboard_page() ) {
226+
// should_show_upgrade_popover() also checks if we're on the Progress Planner Dashboard page - but let's be explicit since that method might change in the future.
227+
$delay_celebration = \progress_planner()->get_plugin_upgrade_tasks()->should_show_upgrade_popover();
228+
}
229+
222230
$localize_data = [
223231
'name' => 'prplSuggestedTask',
224232
'data' => [
@@ -228,6 +236,7 @@ public function localize_script( $handle, $localize_data = [] ) {
228236
'snoozeIcon' => constant( 'PROGRESS_PLANNER_URL' ) . '/assets/images/icon_snooze.svg',
229237
],
230238
'maxItemsPerCategory' => apply_filters( 'progress_planner_suggested_tasks_max_items_per_category', $max_items_per_category ),
239+
'delayCelebration' => $delay_celebration,
231240
],
232241
];
233242
break;

classes/admin/widgets/class-suggested-tasks.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,6 @@ public function get_score() {
4949
* @return void
5050
*/
5151
public function enqueue_scripts() {
52-
// Celebrate only on the Progress Planner Dashboard page.
53-
$delay_celebration = false;
54-
if ( \progress_planner()->is_on_progress_planner_dashboard_page() ) {
55-
// should_show_upgrade_popover() also checks if we're on the Progress Planner Dashboard page - but let's be explicit since that method might change in the future.
56-
$delay_celebration = \progress_planner()->get_plugin_upgrade_tasks()->should_show_upgrade_popover();
57-
}
58-
59-
// Enqueue the script.
60-
\progress_planner()->get_admin__enqueue()->enqueue_script(
61-
'widgets/suggested-tasks',
62-
[
63-
'name' => 'prplSuggestedTasks',
64-
'data' => [
65-
'ajaxUrl' => \admin_url( 'admin-ajax.php' ),
66-
'nonce' => \wp_create_nonce( 'progress_planner' ),
67-
'tasks' => [], // This is set in the JS file.
68-
'delayCelebration' => $delay_celebration,
69-
],
70-
]
71-
);
72-
7352
// Enqueue the badge scroller script.
7453
\progress_planner()->get_admin__enqueue()->enqueue_script(
7554
'widgets/suggested-tasks-badge-scroller',

0 commit comments

Comments
 (0)