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.
This commit is contained in:
sebseb7
2025-08-09 10:06:43 +02:00
parent d40e311b51
commit 2ac9baada0
3 changed files with 16 additions and 14 deletions

View File

@@ -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) => { (response) => {
console.log("getCategoryProducts stub response", response); console.log("getCategoryProducts stub response", response);
// Only process stub response if we haven't received the full response yet // Only process stub response if we haven't received the full response yet
@@ -348,7 +351,10 @@ class Content extends Component {
} }
fetchSearchData(query) { 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) => { (response) => {
if (response && response.products) { if (response && response.products) {
this.processData(response); this.processData(response);

View File

@@ -181,17 +181,10 @@ class ProductDetailPage extends Component {
if (prevLanguage !== currentLanguage) { if (prevLanguage !== currentLanguage) {
console.log('Language changed from', prevLanguage, 'to', currentLanguage, '- reloading product data'); console.log('Language changed from', prevLanguage, 'to', currentLanguage, '- reloading product data');
// Clear relevant caches to force fresh socket calls with new language // Clear caches globally to force fresh socket calls with new language
if (window.productDetailCache) { if (typeof window !== 'undefined') {
// Clear cache for current product window.productCache = {};
delete window.productDetailCache[this.props.seoName]; window.productDetailCache = {};
// 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];
});
}
} }
// Reset component state and reload data // Reset component state and reload data

View File

@@ -151,7 +151,10 @@ class GrowTentKonfigurator extends Component {
setCachedCategoryData(categoryId, response); 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) => { (response) => {
console.log("getCategoryProducts stub response", response); console.log("getCategoryProducts stub response", response);
} }