feat: enhance image loading and socket handling in Product and Images components, and update prerender logic in App and ProductDetailPage
This commit is contained in:
@@ -12,7 +12,7 @@ import LoupeIcon from '@mui/icons-material/Loupe';
|
||||
class Images extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { mainPic:0,pics:[]};
|
||||
this.state = { mainPic:0,pics:[], needsSocketRetry: false };
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
@@ -22,6 +22,15 @@ class Images extends Component {
|
||||
if (prevProps.fullscreenOpen !== this.props.fullscreenOpen) {
|
||||
this.updatePics();
|
||||
}
|
||||
|
||||
// Retry loading images if socket just became available
|
||||
const wasConnected = prevProps.socketB && prevProps.socketB.connected;
|
||||
const isNowConnected = this.props.socketB && this.props.socketB.connected;
|
||||
|
||||
if (!wasConnected && isNowConnected && this.state.needsSocketRetry) {
|
||||
this.setState({ needsSocketRetry: false });
|
||||
this.updatePics();
|
||||
}
|
||||
}
|
||||
|
||||
updatePics = (newMainPic = this.state.mainPic) => {
|
||||
@@ -49,10 +58,10 @@ class Images extends Component {
|
||||
pics.push(window.smallPicCache[bildId]);
|
||||
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
|
||||
}else if(window.tinyPicCache[bildId]){
|
||||
pics.push(bildId);
|
||||
pics.push(window.tinyPicCache[bildId]);
|
||||
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
|
||||
}else{
|
||||
pics.push(bildId);
|
||||
pics.push(`/assets/images/prod${bildId}.jpg`);
|
||||
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
|
||||
}
|
||||
}else{
|
||||
@@ -67,7 +76,8 @@ class Images extends Component {
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('pics',pics);
|
||||
console.log('DEBUG: pics array contents:', pics);
|
||||
console.log('DEBUG: pics array types:', pics.map(p => typeof p + ': ' + p));
|
||||
this.setState({ pics, mainPic: newMainPic });
|
||||
}else{
|
||||
if(this.state.pics.length > 0) this.setState({ pics:[], mainPic: newMainPic });
|
||||
@@ -75,6 +85,13 @@ class Images extends Component {
|
||||
}
|
||||
|
||||
loadPic = (size,bildId,index) => {
|
||||
// Check if socketB is available and connected before emitting
|
||||
if (!this.props.socketB || !this.props.socketB.connected) {
|
||||
console.log("Images: socketB not available, will retry when connected");
|
||||
this.setState({ needsSocketRetry: true });
|
||||
return;
|
||||
}
|
||||
|
||||
this.props.socketB.emit('getPic', { bildId, size }, (res) => {
|
||||
if(res.success){
|
||||
const url = URL.createObjectURL(new Blob([res.imageBuffer], { type: 'image/jpeg' }));
|
||||
|
||||
Reference in New Issue
Block a user