From ec53a0d6b8167b2b279053f90bbd7fa6bc4928d0 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 5 Jul 2024 13:00:18 +0530 Subject: [PATCH] FIX: add a fix for cases where ad record is not found (#214) --- assets/javascripts/discourse/components/house-ad.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/components/house-ad.js b/assets/javascripts/discourse/components/house-ad.js index 399295c..0a63bc5 100644 --- a/assets/javascripts/discourse/components/house-ad.js +++ b/assets/javascripts/discourse/components/house-ad.js @@ -76,8 +76,9 @@ export default AdComponent.extend({ const filteredAds = adNames.filter((adName) => { const ad = houseAds.creatives[adName]; return ( - !ad.category_ids?.length || - ad.category_ids.includes(this.currentCategoryId) + ad && + (!ad.category_ids?.length || + ad.category_ids.includes(this.currentCategoryId)) ); }); if (filteredAds.length > 0) { @@ -129,8 +130,9 @@ export default AdComponent.extend({ const filteredAds = adNames.filter((adName) => { const ad = houseAds.creatives[adName]; return ( - !ad.category_ids?.length || - ad.category_ids.includes(this.currentCategoryId) + ad && + (!ad.category_ids?.length || + ad.category_ids.includes(this.currentCategoryId)) ); }); adIndex[placement] = Math.floor(Math.random() * filteredAds.length);