Updating badge for tasks that complete with no page refresh

This commit is contained in:
Joel T 2022-04-25 15:13:44 -07:00
parent 3b28616640
commit 46d6e6dd3e
2 changed files with 15 additions and 1 deletions

View File

@ -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 ]
);

View File

@ -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;
}
}