Skip to content

Commit

Permalink
fix: prevent errors from null items returned in recommended loan query
Browse files Browse the repository at this point in the history
  • Loading branch information
mcstover committed Dec 1, 2021
1 parent b01e746 commit 18a97a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/components/Lightboxes/AddToBasketInterstitial.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</div>
</div>
</div>
<div class="lightbox-lyml-wrapper" v-if="loan.loan">
<div class="lightbox-lyml-wrapper" v-if="loan.loan && showLoansYouMightLike">
<div class="additional-loans">
<h2>Support more loans like {{ loan.loan.name }}</h2>
<l-y-m-l
Expand All @@ -74,6 +74,7 @@
:visible="showInterstitial"
@add-to-basket="handleAddToBasket"
@processing-add-to-basket="processingAddToBasket"
@no-rec-loans-found="showLoansYouMightLike = false"
/>
</div>
</div>
Expand Down Expand Up @@ -125,6 +126,7 @@ export default {
loanTotals: '0.00',
loading: true,
showInterstitial: false,
showLoansYouMightLike: true,
userPrefHideInterstitial: false,
};
},
Expand Down
18 changes: 12 additions & 6 deletions src/components/LoansYouMightLike/lymlContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,27 @@ export default {
}
},
parseLoansYouMightLike(loansYouMightLike) {
const withoutBasketedLoans = _filter(
loansYouMightLike || [],
loan => this.itemsInBasket.indexOf(loan.id) === -1
);
const filteredLoans = loansYouMightLike.filter(loan => {
// sometimes null comes back from the ml service
if (loan === null) return false;
return this.itemsInBasket.indexOf(loan.id) === -1;
});
// Pruning out duplicates among queried loan sets
const prunedLoansYouMightLike = _uniqBy(withoutBasketedLoans, 'id');
const prunedLoansYouMightLike = _uniqBy(filteredLoans, 'id');
// Randomize array order to be displayed in the front end
this.loansYouMightLike = _shuffle(prunedLoansYouMightLike);
// once we have loans flip the switch to show them
this.showLYML = true;
this.showLYML = prunedLoansYouMightLike.length > 0 || false;
this.loading = false;
// emit event signifying no recommended loans found
if (prunedLoansYouMightLike.length === 0) {
this.$emit('no-rec-loans-found');
}
this.fireExperimentTracking();
// update window width once loans are loaded
Expand Down

0 comments on commit 18a97a4

Please sign in to comment.