[Glitch] Use real container width in MediaGallery srcSet

Port 765a8dad9a to glitch-soc
th-downstream
Thibaut Girka 7 years ago
parent 4e5afb1c41
commit df3fa2cb78

@ -40,6 +40,7 @@ class Item extends React.PureComponent {
size: PropTypes.number.isRequired,
letterbox: PropTypes.bool,
onClick: PropTypes.func.isRequired,
displayWidth: PropTypes.number,
};
static defaultProps = {
@ -78,7 +79,7 @@ class Item extends React.PureComponent {
}
render () {
const { attachment, index, size, standalone, letterbox } = this.props;
const { attachment, index, size, standalone, letterbox, displayWidth } = this.props;
let width = 50;
let height = 100;
@ -141,7 +142,7 @@ class Item extends React.PureComponent {
const hasSize = typeof originalWidth === 'number' && typeof previewWidth === 'number';
const srcSet = hasSize ? `${originalUrl} ${originalWidth}w, ${previewUrl} ${previewWidth}w` : null;
const sizes = hasSize ? `(min-width: 1025px) ${320 * (width / 100)}px, ${width}vw` : null;
const sizes = hasSize ? `${displayWidth * (width / 100)}px` : null;
const focusX = attachment.getIn(['meta', 'focus', 'x']) || 0;
const focusY = attachment.getIn(['meta', 'focus', 'y']) || 0;
@ -272,9 +273,9 @@ export default class MediaGallery extends React.PureComponent {
);
} else {
if (this.isStandaloneEligible()) {
children = <Item standalone attachment={media.get(0)} onClick={this.handleClick} />;
children = <Item standalone attachment={media.get(0)} onClick={this.handleClick} displayWidth={width} />;
} else {
children = media.take(4).map((attachment, i) => <Item key={attachment.get('id')} onClick={this.handleClick} attachment={attachment} index={i} size={size} letterbox={letterbox} />);
children = media.take(4).map((attachment, i) => <Item key={attachment.get('id')} onClick={this.handleClick} attachment={attachment} index={i} size={size} letterbox={letterbox} displayWidth={width} />);
}
}

Loading…
Cancel
Save