From 2ac9baada0a2b47dd876d763ff2bbd11b726acb1 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Sat, 9 Aug 2025 10:06:43 +0200 Subject: [PATCH] feat: enhance language support in data fetching across components - Updated Content, ProductDetailPage, and GrowTentKonfigurator to include current language context when emitting WebSocket requests for product and category data. - Improved caching logic to ensure fresh data loading based on language changes. - Enhanced localization by adding language parameters to data requests, improving user experience across different languages. --- src/components/Content.js | 10 ++++++++-- src/components/ProductDetailPage.js | 15 ++++----------- src/pages/GrowTentKonfigurator.js | 5 ++++- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/components/Content.js b/src/components/Content.js index ae255d9..abba0d9 100644 --- a/src/components/Content.js +++ b/src/components/Content.js @@ -282,7 +282,10 @@ class Content extends Component { } }); - window.socketManager.emit("getCategoryProducts", { categoryId: categoryId }, + const currentLanguage = this.props.languageContext?.currentLanguage || this.props.i18n?.language || 'de'; + window.socketManager.emit( + "getCategoryProducts", + { categoryId: categoryId, language: currentLanguage, requestTranslation: currentLanguage === 'de' ? false : true }, (response) => { console.log("getCategoryProducts stub response", response); // Only process stub response if we haven't received the full response yet @@ -348,7 +351,10 @@ class Content extends Component { } fetchSearchData(query) { - window.socketManager.emit("getSearchProducts", { query }, + const currentLanguage = this.props.languageContext?.currentLanguage || this.props.i18n?.language || 'de'; + window.socketManager.emit( + "getSearchProducts", + { query, language: currentLanguage, requestTranslation: currentLanguage === 'de' ? false : true }, (response) => { if (response && response.products) { this.processData(response); diff --git a/src/components/ProductDetailPage.js b/src/components/ProductDetailPage.js index 05d9a3d..c3524d5 100644 --- a/src/components/ProductDetailPage.js +++ b/src/components/ProductDetailPage.js @@ -181,17 +181,10 @@ class ProductDetailPage extends Component { if (prevLanguage !== currentLanguage) { console.log('Language changed from', prevLanguage, 'to', currentLanguage, '- reloading product data'); - // Clear relevant caches to force fresh socket calls with new language - if (window.productDetailCache) { - // Clear cache for current product - delete window.productDetailCache[this.props.seoName]; - - // Clear cache for any komponenten if they exist - if (this.state.komponenten && this.state.komponenten.length > 0) { - this.state.komponenten.forEach(komponent => { - delete window.productDetailCache[komponent.id]; - }); - } + // Clear caches globally to force fresh socket calls with new language + if (typeof window !== 'undefined') { + window.productCache = {}; + window.productDetailCache = {}; } // Reset component state and reload data diff --git a/src/pages/GrowTentKonfigurator.js b/src/pages/GrowTentKonfigurator.js index 46cec1d..744f3fe 100644 --- a/src/pages/GrowTentKonfigurator.js +++ b/src/pages/GrowTentKonfigurator.js @@ -151,7 +151,10 @@ class GrowTentKonfigurator extends Component { setCachedCategoryData(categoryId, response); }); - window.socketManager.emit("getCategoryProducts", { categoryId: categoryId }, + const currentLanguage = this.props.languageContext?.currentLanguage || this.props.i18n?.language || 'de'; + window.socketManager.emit( + "getCategoryProducts", + { categoryId: categoryId, language: currentLanguage, requestTranslation: currentLanguage === 'de' ? false : true }, (response) => { console.log("getCategoryProducts stub response", response); }