From 4879f6899858e0da6622cc78473527549790374d Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Wed, 23 Jul 2025 10:36:45 +0200 Subject: [PATCH] refactor: simplify category data fetching logic in Content component by removing redundant cache checks and improving clarity in data handling --- src/components/Content.js | 46 +++------------------------------------ 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/src/components/Content.js b/src/components/Content.js index 61b94d2..ffccc5b 100644 --- a/src/components/Content.js +++ b/src/components/Content.js @@ -259,37 +259,12 @@ class Content extends Component { fetchCategoryData(categoryId) { - // Check if we have the category tree data in window.productCache - const hasCategoryTree = window.productCache && - window.productCache["categoryTree_209"] && - window.productCache["categoryTree_209"].categoryTree; - - // Check for specific category data in cache const cachedData = getCachedCategoryData(categoryId); - - // If we have the category tree data, use it and don't query socket.io - if (hasCategoryTree) { - console.log("Found category tree in cache"); - - if (cachedData) { - console.log("Using cached category data for", categoryId); - this.processDataWithCategoryTree(cachedData, categoryId); - return; - } else { - // If we have the category tree but not the specific category data, - // we can still use the category tree to get child categories - const emptyResponse = { - products: [], - attributes: [], - categoryName: this.getCategoryNameFromTree(categoryId) - }; - console.log("Using category tree data without products"); - this.processDataWithCategoryTree(emptyResponse, categoryId); - return; - } + if (cachedData) { + this.processDataWithCategoryTree(cachedData, categoryId); + return; } - // Only if we don't have the category tree in cache, proceed with socket.io query console.log(`productList:${categoryId}`); window.socketManager.off(`productList:${categoryId}`); @@ -409,21 +384,6 @@ class Content extends Component { return null; } - - // Helper function to get category name from tree - getCategoryNameFromTree = (categoryId) => { - if (!window.productCache || !window.productCache["categoryTree_209"] || - !window.productCache["categoryTree_209"].categoryTree) { - return null; - } - - // If categoryId is a string (SEO name), find by seoName, otherwise by ID - const category = typeof categoryId === 'string' - ? this.findCategoryBySeoName(window.productCache["categoryTree_209"].categoryTree, categoryId) - : this.findCategoryById(window.productCache["categoryTree_209"].categoryTree, categoryId); - - return category ? category.name : null; - } // Helper function to get current category ID from seoName getCurrentCategoryId = () => {