refactor: enhance category data fetching in CategoryList to support language context updates and improve state management

This commit is contained in:
sebseb7
2025-07-31 04:16:23 +02:00
parent 14787cbd74
commit b29b946aaf

View File

@@ -25,7 +25,7 @@ class CategoryList extends Component {
componentDidMount() {
if (!this.state.categories || this.state.categories.length === 0) {
window.categoryService.get(209).then((response) => {
window.categoryService.get(209,this.props.languageContext?.currentLanguage || this.props.i18n.language).then((response) => {
console.log("response", response);
if (response.children && response.children.length > 0) {
this.setState({
@@ -43,7 +43,23 @@ class CategoryList extends Component {
}
componentDidUpdate(prevProps) {
console.log("componentDidUpdate", this.props.activeCategoryId);
console.log("componentDidUpdate", prevProps.languageContext?.currentLanguage, this.props.languageContext?.currentLanguage);
if(prevProps.languageContext?.currentLanguage !== this.props.languageContext?.currentLanguage) {
this.setState({
categories: [],
activeCategoryId: null
},() => {
window.categoryService.get(209,this.props.languageContext?.currentLanguage || this.props.i18n.language).then((response) => {
console.log("response", response);
if (response.children && response.children.length > 0) {
this.setState({
categories: response.children,
activeCategoryId: this.setLevel1CategoryId(this.props.activeCategoryId)
});
}
});
});
}
if (prevProps.activeCategoryId !== this.props.activeCategoryId) {
//detect path here
console.log("activeCategoryId updated", this.props.activeCategoryId);