I have an app, where if an action fails (BiographyUpdate
), I'd like to give the user the option to retry the action using a toast. When the user dismisses the toast, it should retry the action if they accept:
@Effect()
public BiographyUpdate: Observable<any> = this._actions.pipe(
ofType(AuthActionTypes.BIOGRAPHY_UPDATE),
map((action: BiographyUpdate) => action.payload),
switchMap(biography => this._profile.updateBiography(`${Environment.Endpoint}/users/update`, biography)
.map(() => new BiographyUpdateSuccess())
.catch(() => Observable.of(new BiographyUpdateFailure(biography)))
)
);
@Effect({ dispatch: false })
public BiographyUpdateFailure: Observable<any> = this._actions.pipe(
ofType(AuthActionTypes.BIOGRAPHY_UPDATE_FAILURE),
map((action: BiographyUpdateFailure) => action.payload),
tap(payload => {
const toast = this._toast.create({
message: "Update failed.",
...ToastDefaults,
duration: 3000,
closeButtonText: 'Retry'
});
toast.onDidDismiss(() => new BiographyUpdate(payload));
toast.present();
})
);
Since the action is called through the UI's callback, I thought this way would work, but the action is never called again. Any suggestions?