This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 5a4ae100 authored by Daniel Crazzolara's avatar Daniel Crazzolara
Browse files

Fixed race condition

parent 36a10ccd
3 merge requests!166Deploying Februrar 23 Release,!155disabled watchlist if not logged in,!146Put the sonar-analyze job into a separate stage
......@@ -31,21 +31,12 @@ export class BookmarkToggleComponent implements OnInit {
handleForCurrentWatchlist(): void {
if (!this.isLoadingBookmark) {
this.isLoadingBookmark = true;
this.watchlistManager.handleCheckForCurrentWatchlist(this.exercise!)?.subscribe({
next: () => {
this.isBookmarked = !this.isBookmarked;
this.exercise!.numberOfWatchlistEntries = !this.isBookmarked
? this.exercise!.numberOfWatchlistEntries--
: this.exercise!.numberOfWatchlistEntries++;
},
error: err => {
this.jhiAlertService.addAlert({
type: 'danger',
message: err,
});
this.isLoadingBookmark = false;
},
complete: () => (this.isLoadingBookmark = false),
this.watchlistManager.handleCheckForCurrentWatchlist(this.exercise!)?.then(() => {
this.isBookmarked = !this.isBookmarked;
this.exercise!.numberOfWatchlistEntries = !this.isBookmarked
? this.exercise!.numberOfWatchlistEntries--
: this.exercise!.numberOfWatchlistEntries++;
this.isLoadingBookmark = false;
});
}
}
......
......@@ -111,31 +111,35 @@ export class WatchlistManager implements OnDestroy {
return this.currentWatchlist;
}
public handleCheckForCurrentWatchlist(e: Exercise): Observable<HttpResponse<any>> | undefined {
let handling;
if (this.currentWatchlist) {
if (!this.isExerciseOnCurrentWatchlist(e)) {
console.log('adding');
// add
const watchListEntry: IWatchListEntry = {
exerciseId: e.originalResult.exerciseId,
exerciseName: e.originalResult.metadata.title,
watchlistId: this.currentWatchlist.userWatchList.id,
};
// reload watchlist
handling = this.watchListEntryService.createForCurrentUser(watchListEntry);
} else {
// delete
handling = this.watchListEntryService.deleteForCurrentUser(this.currentWatchlist.userWatchList.id!, e.originalResult.exerciseId);
public handleCheckForCurrentWatchlist(e: Exercise): Promise<void> {
return new Promise<void>((resolve, reject) => {
let handling;
if (this.currentWatchlist) {
if (!this.isExerciseOnCurrentWatchlist(e)) {
// add
const watchListEntry: IWatchListEntry = {
exerciseId: e.originalResult.exerciseId,
exerciseName: e.originalResult.metadata.title,
watchlistId: this.currentWatchlist.userWatchList.id,
};
// reload watchlist
handling = this.watchListEntryService.createForCurrentUser(watchListEntry);
} else {
// delete
handling = this.watchListEntryService.deleteForCurrentUser(this.currentWatchlist.userWatchList.id!, e.originalResult.exerciseId);
}
handling.subscribe({
next: () => {
if (this.currentWatchlist) this.loadCurrentWatchList(this.currentWatchlist.userWatchList);
resolve();
},
error: err => {
reject(err);
},
});
}
handling.subscribe(() => {
console.log('Running');
if (this.currentWatchlist) this.loadCurrentWatchList(this.currentWatchlist.userWatchList);
});
return handling.pipe();
}
return;
});
}
public createForCurrentUser(userWatchList: IUserWatchList): Observable<EntityResponseType> {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment