diff --git a/src/core/features/siteplugins/classes/call-ws-directive.ts b/src/core/features/siteplugins/classes/call-ws-directive.ts index 978f1af25..58f9b73ab 100644 --- a/src/core/features/siteplugins/classes/call-ws-directive.ts +++ b/src/core/features/siteplugins/classes/call-ws-directive.ts @@ -74,7 +74,8 @@ export class CoreSitePluginsCallWSBaseDirective implements OnInit, OnDestroy { this.onSuccess.emit(result); - return this.wsCallSuccess(result); + // Don't block the promise with the success function. + this.wsCallSuccess(result); } catch (error) { this.onError.emit(error); this.logger.error(`Error calling WS ${this.name}`, error); @@ -108,9 +109,10 @@ export class CoreSitePluginsCallWSBaseDirective implements OnInit, OnDestroy { * Function called when the WS call is successful. * * @param result Result of the WS call. + * @return If async, promise resolved when done. */ // eslint-disable-next-line @typescript-eslint/no-unused-vars - protected wsCallSuccess(result: unknown): void { + protected wsCallSuccess(result: unknown): void | Promise { // Function to be overridden. } diff --git a/src/core/features/siteplugins/directives/call-ws.ts b/src/core/features/siteplugins/directives/call-ws.ts index 71c5f82c3..e2b2226a4 100644 --- a/src/core/features/siteplugins/directives/call-ws.ts +++ b/src/core/features/siteplugins/directives/call-ws.ts @@ -65,17 +65,17 @@ export class CoreSitePluginsCallWSDirective extends CoreSitePluginsCallWSOnClick /** * @inheritdoc */ - protected wsCallSuccess(): void { + protected async wsCallSuccess(): Promise { + if (CoreUtils.isTrueOrOne(this.goBackOnSuccess)) { + await CoreNavigator.back(); + } else if (CoreUtils.isTrueOrOne(this.refreshOnSuccess) && this.parentContent) { + this.parentContent.refreshContent(true); + } + if (typeof this.successMessage != 'undefined') { // Display the success message. CoreDomUtils.showToast(this.successMessage || Translate.instant('core.success')); } - - if (CoreUtils.isTrueOrOne(this.goBackOnSuccess)) { - CoreNavigator.back(); - } else if (CoreUtils.isTrueOrOne(this.refreshOnSuccess) && this.parentContent) { - this.parentContent.refreshContent(true); - } } }