feat: Enhance ProductFilters to load manufacturer images and display them in the Filter component
This commit is contained in:
@@ -296,6 +296,13 @@ class Filter extends Component {
|
|||||||
const event = { target: { name: option.id, checked: !options[option.id] } };
|
const event = { target: { name: option.id, checked: !options[option.id] } };
|
||||||
this.handleOptionChange(event);
|
this.handleOptionChange(event);
|
||||||
}}>
|
}}>
|
||||||
|
{this.props.filterType === 'manufacturer' && this.props.manufacturerImages?.get(option.id) && (
|
||||||
|
<img
|
||||||
|
src={this.props.manufacturerImages.get(option.id)}
|
||||||
|
alt=""
|
||||||
|
style={{ height: '24px', width: 'auto', marginRight: '6px', verticalAlign: 'middle', objectFit: 'contain' }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{option.name}
|
{option.name}
|
||||||
</td>
|
</td>
|
||||||
<td style={countCellStyle}>
|
<td style={countCellStyle}>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { withTranslation } from 'react-i18next';
|
|||||||
import { withLanguage } from '../i18n/withTranslation.js';
|
import { withLanguage } from '../i18n/withTranslation.js';
|
||||||
|
|
||||||
const ITEM_WIDTH = 140 + 16; // 140px width + 16px gap
|
const ITEM_WIDTH = 140 + 16; // 140px width + 16px gap
|
||||||
const AUTO_SCROLL_SPEED = 0.4;
|
const AUTO_SCROLL_SPEED = 1.0;
|
||||||
|
|
||||||
class ManufacturerCarousel extends React.Component {
|
class ManufacturerCarousel extends React.Component {
|
||||||
_isMounted = false;
|
_isMounted = false;
|
||||||
@@ -89,7 +89,7 @@ class ManufacturerCarousel extends React.Component {
|
|||||||
if (!items || items.length === 0) return null;
|
if (!items || items.length === 0) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ mt: 4 }}>
|
<Box sx={{ mt: 4, mb: 4 }}>
|
||||||
<Typography
|
<Typography
|
||||||
variant="h4"
|
variant="h4"
|
||||||
component="div"
|
component="div"
|
||||||
|
|||||||
@@ -36,17 +36,39 @@ class ProductFilters extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
availabilityValues,
|
availabilityValues,
|
||||||
uniqueManufacturerArray,
|
uniqueManufacturerArray,
|
||||||
attributeGroups
|
attributeGroups,
|
||||||
|
manufacturerImages: new Map(), // id (number) → object URL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._manufacturerImageUrls = []; // track for cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// Measure the available space dynamically
|
|
||||||
this.adjustPaperHeight();
|
this.adjustPaperHeight();
|
||||||
// Add event listener for window resize
|
|
||||||
window.addEventListener('resize', this.adjustPaperHeight);
|
window.addEventListener('resize', this.adjustPaperHeight);
|
||||||
|
this._loadManufacturerImages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
window.removeEventListener('resize', this.adjustPaperHeight);
|
||||||
|
this._manufacturerImageUrls.forEach(url => URL.revokeObjectURL(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
_loadManufacturerImages = () => {
|
||||||
|
window.socketManager.emit('getHerstellerImages', {}, (res) => {
|
||||||
|
if (!res?.success || !res.manufacturers?.length) return;
|
||||||
|
const map = new Map();
|
||||||
|
for (const m of res.manufacturers) {
|
||||||
|
if (!m.imageBuffer) continue;
|
||||||
|
const blob = new Blob([m.imageBuffer], { type: 'image/avif' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
map.set(m.id, url);
|
||||||
|
this._manufacturerImageUrls.push(url);
|
||||||
|
}
|
||||||
|
this.setState({ manufacturerImages: map });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
// Regenerate values when products, attributes, or language changes
|
// Regenerate values when products, attributes, or language changes
|
||||||
const productsChanged = this.props.products !== prevProps.products;
|
const productsChanged = this.props.products !== prevProps.products;
|
||||||
@@ -82,10 +104,6 @@ class ProductFilters extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
// Remove event listener when component unmounts
|
|
||||||
window.removeEventListener('resize', this.adjustPaperHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
adjustPaperHeight = () => {
|
adjustPaperHeight = () => {
|
||||||
// Skip height adjustment on xs screens
|
// Skip height adjustment on xs screens
|
||||||
@@ -265,6 +283,7 @@ class ProductFilters extends Component {
|
|||||||
products={this.props.products}
|
products={this.props.products}
|
||||||
filteredProducts={this.props.filteredProducts}
|
filteredProducts={this.props.filteredProducts}
|
||||||
attributes={this.props.attributes}
|
attributes={this.props.attributes}
|
||||||
|
manufacturerImages={this.state.manufacturerImages}
|
||||||
onFilterChange={(msg)=>{
|
onFilterChange={(msg)=>{
|
||||||
if(msg.value) {
|
if(msg.value) {
|
||||||
setSessionSetting(`filter_${msg.type}_${msg.name}`, 'true');
|
setSessionSetting(`filter_${msg.type}_${msg.name}`, 'true');
|
||||||
|
|||||||
Reference in New Issue
Block a user