refactor: enhance category data fetching in CategoryList to support language context updates and improve state management
This commit is contained in:
@@ -25,7 +25,7 @@ class CategoryList extends Component {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (!this.state.categories || this.state.categories.length === 0) {
|
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);
|
console.log("response", response);
|
||||||
if (response.children && response.children.length > 0) {
|
if (response.children && response.children.length > 0) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -43,7 +43,23 @@ class CategoryList extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
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) {
|
if (prevProps.activeCategoryId !== this.props.activeCategoryId) {
|
||||||
//detect path here
|
//detect path here
|
||||||
console.log("activeCategoryId updated", this.props.activeCategoryId);
|
console.log("activeCategoryId updated", this.props.activeCategoryId);
|
||||||
|
|||||||
Reference in New Issue
Block a user