I was wondering if there was a better way to do the loading ? Or would I always have to set it up like this for every component that would need it ?
protected loadingState = signal<LoadingState>({
isLoading: false,
error: undefined,
successMessage: '',
});
verifyEmail() {
console.log('Verifying email', this.otp.value);
this.loadingState.update((state) => ({ ...state, isLoading: true }));
const user = this.#userService.getUserInfo();
const otp = this.otp.value
if (otp.length === 6) {
console.log('User', user);
this.#authService
.verifyEmail({ code: otp, email: user.email })
.pipe(
tap((loggedInUser) => {
this.#userService.updateUser(loggedInUser);
this.loadingState.set({
isLoading: false,
successMessage: 'Verification successful',
error: undefined,
});
this.#authService.updateAuthStatus()
this.countDownTimer = '00:00'
this.#router.navigate(['/settings'], { replaceUrl: true })
}),
catchError((err) => {
this.loadingState.set({
isLoading: false,
successMessage: '',
error: getErrorMessage(err),
});
return EMPTY;
}),
takeUntilDestroyed(this.#destroyRef)
)
.subscribe();
}
}