Topic: Calendar shows appointments from the previously selected team
pixelharbor31
priority
asked 1 week ago
Our calendar reloads appointments whenever the team selector changes. Switching between teams slowly works, but switching twice on a slow connection sometimes displays appointments from the first team under the second team's heading.
Each selector change starts an HTTP request and its subscription assigns the response to events. The endpoint returns the correct team ID in every response. Should we clear the calendar before loading, or do we need to coordinate the requests?
Arkadiusz Idzikowski
staff
answered 1 week ago
Clearing events changes what is visible while loading, but it does not prevent an earlier request from finishing last. Associate each response with the selection that started it and discard the response if that selection is no longer current.
With HttpClient observables, switchMap is another way to replace the previous request when the selection changes. Keep the loading and error state associated with that same active request. Please share the selector subscription if the response is already guarded but the wrong appointments still appear.
latestRequestId = 0;
loadTeam(teamId: string) {
const requestId = ++this.latestRequestId;
this.api.loadEvents(teamId).subscribe(events => {
if (requestId !== this.latestRequestId) return;
this.events = events;
});
}
https://mdbootstrap.com/docs/angular/plugins/calendar/
pixelharbor31 priority commented 1 week ago
The request guard fixed it. I tested rapid team changes with network throttling and the old response is now ignored. We also made the loading indicator follow the active request, so a stale completion no longer hides it while the current team is still loading.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Priority
- Premium support: Yes
- Technology: MDB Angular
- MDB Version: MDB5 9.1.0
- Device: Desktop
- Browser: Chrome
- OS: Windows 11
- Provided sample code: No
- Provided link: No