I have two list to refresh for two different event (one post, one delete). The issue is that when delete is called, It calls also the post method. So I delete someting, but the post re-post it :p
The lists to refresh are the profileUser$ and the ptofileListDistinct$
What I have tried:
Initialization:
export class UserEditComponent implements OnInit {
userId: string = "";
currentUser$!: Observable<User>;
profileUser$!: Observable<ProfileUser[]>;
profileListDistinc$!: Observable<Profile[]>;
constructor(
private activatedRoute: ActivatedRoute,
private router: Router,
private userService: UserService,
private profileService: ProfileService,
private reloadProfile: SearchEmitterService,
private confirmDialogService: ConfirmDialogService
) { }
ngOnInit(): void {
const id = this.activatedRoute.snapshot.paramMap.get('id');
this.userId = id ? id : "";
this.currentUser$ = this.userService.getUser(this.userId);
this.profileUser$ = this.reloadProfile.reloadprofileUserBehavior$.pipe(
switchMap(
x => this.profileService.getProfilesForUser(this.userId)));
this.profileListDistinc$ = this.reloadProfile.reloadProfileListDisctincBehavior$.pipe(
switchMap(x => this.profileService.getProfilesDisctinc(this.userId)));
}
Post Method:
onAddProfileUser(profileId: string, userId: string) {
let newProfileUser: ProfileUserCreate = {
profileId: profileId,
userId: userId
}
this.profileService.addProfileForUser(newProfileUser)
.subscribe(x => {
this.reloadProfile.reloadprofileUserBehavior$.next(null);
this.reloadProfile.reloadProfileListDisctincBehavior$.next(null);
});
}
Delete Method:
onDeleteProfileUser(profileUser: ProfileUser): void {
this.profileService.deleteProfileForUser(profileUser)
.subscribe(x => {
this.reloadProfile.reloadProfileListDisctincBehavior$.next(null);
this.reloadProfile.reloadprofileUserBehavior$.next(null);
});
}
Reload Service:
export class SearchEmitterService {
reloadProfileListDisctincBehavior$: BehaviorSubject<any> = new BehaviorSubject<any>(null);
reloadprofileUserBehavior$: BehaviorSubject<any> = new BehaviorSubject<any>(null);
constructor() { }