Enhance category data fetching by adding full response handling and improving socket communication in Content component
This commit is contained in:
@@ -39,7 +39,7 @@ const fetchCategoryProducts = (socket, categoryId) => {
|
|||||||
|
|
||||||
socket.emit(
|
socket.emit(
|
||||||
"getCategoryProducts",
|
"getCategoryProducts",
|
||||||
{ categoryId: parseInt(categoryId) },
|
{ full:true, categoryId: parseInt(categoryId) },
|
||||||
(response) => {
|
(response) => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
if (response && response.products !== undefined) {
|
if (response && response.products !== undefined) {
|
||||||
|
|||||||
@@ -238,6 +238,8 @@ class Content extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fetchCategoryData(categoryId) {
|
fetchCategoryData(categoryId) {
|
||||||
const cachedData = getCachedCategoryData(categoryId);
|
const cachedData = getCachedCategoryData(categoryId);
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
@@ -251,14 +253,36 @@ class Content extends Component {
|
|||||||
console.log("Socket not connected yet, waiting for connection to fetch category data");
|
console.log("Socket not connected yet, waiting for connection to fetch category data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log(`productList:${categoryId}`);
|
||||||
|
this.props.socket.off(`productList:${categoryId}`);
|
||||||
|
|
||||||
|
// Track if we've received the full response to ignore stub response if needed
|
||||||
|
let receivedFullResponse = false;
|
||||||
|
|
||||||
|
this.props.socket.on(`productList:${categoryId}`,(response) => {
|
||||||
|
console.log("getCategoryProducts full response", response);
|
||||||
|
receivedFullResponse = true;
|
||||||
|
setCachedCategoryData(categoryId, response);
|
||||||
|
if (response && response.products !== undefined) {
|
||||||
|
this.processDataWithCategoryTree(response, categoryId);
|
||||||
|
} else {
|
||||||
|
console.log("fetchCategoryData in Content failed", response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.props.socket.emit("getCategoryProducts", { categoryId: categoryId },
|
this.props.socket.emit("getCategoryProducts", { categoryId: categoryId },
|
||||||
(response) => {
|
(response) => {
|
||||||
setCachedCategoryData(categoryId, response);
|
console.log("getCategoryProducts stub response", response);
|
||||||
if (response && response.products !== undefined) {
|
// Only process stub response if we haven't received the full response yet
|
||||||
this.processDataWithCategoryTree(response, categoryId);
|
if (!receivedFullResponse) {
|
||||||
|
setCachedCategoryData(categoryId, response);
|
||||||
|
if (response && response.products !== undefined) {
|
||||||
|
this.processDataWithCategoryTree(response, categoryId);
|
||||||
|
} else {
|
||||||
|
console.log("fetchCategoryData in Content failed", response);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("fetchCategoryData in Content failed", response);
|
console.log("Ignoring stub response - full response already received");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user