Merge pull request #2732 from dpalou/MOBILE-3623

MOBILE-3623 plugins: Wait to display success message if goBackOnSuccess
main
Pau Ferrer Ocaña 2021-05-03 11:20:54 +02:00 committed by GitHub
commit 0eab7f5bef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -74,7 +74,8 @@ export class CoreSitePluginsCallWSBaseDirective implements OnInit, OnDestroy {
this.onSuccess.emit(result); this.onSuccess.emit(result);
return this.wsCallSuccess(result); // Don't block the promise with the success function.
this.wsCallSuccess(result);
} catch (error) { } catch (error) {
this.onError.emit(error); this.onError.emit(error);
this.logger.error(`Error calling WS ${this.name}`, 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. * Function called when the WS call is successful.
* *
* @param result Result of the WS call. * @param result Result of the WS call.
* @return If async, promise resolved when done.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
protected wsCallSuccess(result: unknown): void { protected wsCallSuccess(result: unknown): void | Promise<void> {
// Function to be overridden. // Function to be overridden.
} }

View File

@ -65,17 +65,17 @@ export class CoreSitePluginsCallWSDirective extends CoreSitePluginsCallWSOnClick
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected wsCallSuccess(): void { protected async wsCallSuccess(): Promise<void> {
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') { if (typeof this.successMessage != 'undefined') {
// Display the success message. // Display the success message.
CoreDomUtils.showToast(this.successMessage || Translate.instant('core.success')); 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);
}
} }
} }