Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mylife: smoother achievement summary (fixes #7469) #7470

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix the achievement addition error && cleanup on resources removal
  • Loading branch information
Mutugiii committed May 28, 2024
commit 70dfa4be8c1963e858f964bfd50f92940d022998
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ export class UsersAchievementsUpdateComponent implements OnInit, OnDestroy {
if (formValue === undefined) {
return;
}
if (formValue.resources) {
formValue.resources.sort((a, b) => a.title.toLowerCase() > b.title.toLowerCase() ? 1 : -1);
}
this.updateFormArray(formArray, formGroup, index);
};
}
Expand Down Expand Up @@ -237,8 +234,4 @@ export class UsersAchievementsUpdateComponent implements OnInit, OnDestroy {
this.router.navigate([ '..' ], { relativeTo: this.route });
}

removeResource(achievement: FormControl, resource) {
achievement.setValue({ ...achievement.value, resources: achievement.value.resources.filter(({ _id }) => _id !== resource._id) });
}

}
21 changes: 1 addition & 20 deletions src/app/users/users-achievements/users-achievements.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Injectable } from '@angular/core';
import { CouchService } from '../../shared/couchdb.service';
import { forkJoin } from 'rxjs';
import { map, first } from 'rxjs/operators';
import { ResourcesService } from '../../resources/resources.service';

@Injectable({
providedIn: 'root'
Expand All @@ -14,26 +11,10 @@ export class UsersAchievementsService {

constructor(
private couchService: CouchService,
private resourcesService: ResourcesService
) {}


getAchievements(id) {
this.resourcesService.requestResourcesUpdate(this.parent);
return forkJoin([
this.couchService.get(this.dbName + '/' + id),
this.resourcesService.resourcesListener(this.parent).pipe(first())
]).pipe(
map(([ userAchievements, resources ]: any[]) => {
const resourceIds = resources.map((res: any) => res._id);
userAchievements.achievements.forEach((achievement: any) => {
if (achievement.resources.length !== 0) {
achievement.resources = achievement.resources.filter(res => resourceIds.indexOf(res._id) !== -1);
}
});
return userAchievements;
})
);
return this.couchService.get(this.dbName + '/' + id);
}

isEmpty(achievement) {
Expand Down
Loading