Updating badge for tasks that complete with no page refresh
This commit is contained in:
parent
3b28616640
commit
46d6e6dd3e
|
@ -25,6 +25,19 @@ export const Task: React.FC< TaskProps > = ( { query, task } ) => {
|
|||
optimisticallyCompleteTask,
|
||||
} = useDispatch( ONBOARDING_STORE_NAME );
|
||||
|
||||
const updateBadge = useCallback( () => {
|
||||
const badgeElement: HTMLElement | null = document.querySelector(
|
||||
'.toplevel_page_woocommerce .remaining-tasks-badge'
|
||||
);
|
||||
|
||||
if ( ! badgeElement ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentBadgeCount = Number( badgeElement.innerText );
|
||||
badgeElement.innerHTML = String( currentBadgeCount - 1 );
|
||||
}, [] );
|
||||
|
||||
const onComplete = useCallback(
|
||||
( options ) => {
|
||||
optimisticallyCompleteTask( id );
|
||||
|
@ -34,6 +47,7 @@ export const Task: React.FC< TaskProps > = ( { query, task } ) => {
|
|||
: getNewPath( {}, '/', {} )
|
||||
);
|
||||
invalidateResolutionForStoreSelector( 'getTaskLists' );
|
||||
updateBadge();
|
||||
},
|
||||
[ id ]
|
||||
);
|
||||
|
|
|
@ -507,7 +507,7 @@ class TaskLists {
|
|||
|
||||
foreach ( $submenu['woocommerce'] as $key => $menu_item ) {
|
||||
if ( 0 === strpos( $menu_item[0], _x( 'Home', 'Admin menu name', 'woocommerce' ) ) ) {
|
||||
$submenu['woocommerce'][ $key ][0] .= ' <span class="awaiting-mod update-plugins count-' . esc_attr( $tasks_count ) . '">' . number_format_i18n( $tasks_count ) . '</span>'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
$submenu['woocommerce'][ $key ][0] .= ' <span class="awaiting-mod update-plugins remaining-tasks-badge count-' . esc_attr( $tasks_count ) . '">' . number_format_i18n( $tasks_count ) . '</span>'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue