Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #430 from victoriadanyelcortes/iss400
Browse files Browse the repository at this point in the history
Issue #400
  • Loading branch information
Bad-Science authored Apr 10, 2019
2 parents 4c8fb7e + 518c292 commit 1376fb2
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions web/src/app/sidebar/interested-courses/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,31 @@ export class InterestedCoursesComponent implements OnInit {
.includes('sections.listing')
.includes('course')
.includes('course.subject')
.all().then((listings) => {
this.listings = listings.data;
.all().then((newListings) => {
// Create sets from the ids of the two arrays to check for memebership
// This allows the runtime to be linear
let oldListingsSet = new Set(this.listings.map((listing) => listing.id));
let newListingsSet = new Set(newListings.data.map((newListing) => newListing.id));

// Iterate over new listings, and add each new listing if it is not already
// present in the current listings
newListings.data.forEach((newListing) => {
let inCurList: boolean = oldListingsSet.has(newListing.id);

if (!inCurList) {
this.listings.push(newListing);
}
});

// Remove listings that are not in the array of new listings
this.listings.forEach((listing, index) => {
let removeCurList: boolean = !newListingsSet.has(listing.id);

if (removeCurList) {
this.listings.splice(index, 1);
}
});

this.conflictsService.populateConflictsCache(this.listings);
this.isLoaded = true;
});
Expand Down

0 comments on commit 1376fb2

Please sign in to comment.