refactor: unify category data fetching across components to support language context and improve state management

This commit is contained in:
sebseb7
2025-07-31 08:26:10 +02:00
parent 9b38ed6f2a
commit 42fa46f2f9
5 changed files with 103 additions and 47 deletions

View File

@@ -305,7 +305,8 @@ class Content extends Component {
// Get child categories from the cached category tree
let childCategories = [];
try {
const categoryTreeCache = window.categoryService.getSync(209);
const currentLanguage = this.props.languageContext?.currentLanguage || this.props.i18n?.language || 'de';
const categoryTreeCache = window.categoryService.getSync(209, currentLanguage);
if (categoryTreeCache) {
// If categoryId is a string (SEO name), find by seoName, otherwise by ID
const targetCategory = typeof categoryId === 'string'
@@ -391,7 +392,8 @@ class Content extends Component {
const seoName = this.props.params.categoryId;
// Get the category tree from cache
const categoryTreeCache = window.categoryService.getSync(209);
const currentLanguage = this.props.languageContext?.currentLanguage || this.props.i18n?.language || 'de';
const categoryTreeCache = window.categoryService.getSync(209, currentLanguage);
// Find the category by seoName
const category = this.findCategoryBySeoName(categoryTreeCache, seoName);
@@ -403,7 +405,8 @@ class Content extends Component {
if (!currentCategoryId) return null;
// Get the category tree from cache
const categoryTreeCache = window.categoryService.getSync(209);
const currentLanguage = this.props.languageContext?.currentLanguage || this.props.i18n?.language || 'de';
const categoryTreeCache = window.categoryService.getSync(209, currentLanguage);
// Find the current category in the tree
const currentCategory = this.findCategoryById(categoryTreeCache, currentCategoryId);