Optimize Settings logic to avoid duplicate service calls

This commit is contained in:
aditya.chandel
2025-05-27 21:46:36 -07:00
committed by Aditya Chandel
parent 9acd062634
commit b9ad85857a
16 changed files with 42 additions and 62 deletions
@@ -100,12 +100,12 @@ export class UserService {
private rxStompService?: RxStompService;
private userDataSubject = new BehaviorSubject<User | null>(null);
userData$ = this.userDataSubject.asObservable();
private userStateSubject = new BehaviorSubject<User | null>(null);
userState$ = this.userStateSubject.asObservable();
constructor() {
this.getMyself().subscribe(user => {
this.userDataSubject.next(user);
this.userStateSubject.next(user);
this.startWebSocket();
});
}
@@ -165,11 +165,11 @@ export class UserService {
headers: {'Content-Type': 'application/json'},
responseType: 'text' as 'json'
}).subscribe(() => {
const currentUser = this.userDataSubject.getValue();
const currentUser = this.userStateSubject.getValue();
if (currentUser) {
const updatedSettings = {...currentUser.userSettings, [key]: value};
const updatedUser = {...currentUser, settings: updatedSettings};
this.userDataSubject.next(updatedUser);
this.userStateSubject.next(updatedUser);
}
});
}