2021-10-08 11:12:38 -07:00
|
|
|
import PropTypes from 'prop-types';
|
2022-01-10 14:17:52 -08:00
|
|
|
import React from 'react';
|
2021-10-08 11:12:38 -07:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2022-01-10 14:17:52 -08:00
|
|
|
import { connect } from 'react-redux';
|
2021-10-08 11:12:38 -07:00
|
|
|
import { openModal } from 'soapbox/actions/modal';
|
|
|
|
import Bundle from 'soapbox/features/ui/components/bundle';
|
2022-01-10 14:17:52 -08:00
|
|
|
import { MediaGallery } from 'soapbox/features/ui/util/async-components';
|
2021-10-08 11:12:38 -07:00
|
|
|
|
|
|
|
export default @connect()
|
|
|
|
class AttachmentThumbs extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
media: ImmutablePropTypes.list.isRequired,
|
2021-10-09 10:33:08 -07:00
|
|
|
onClick: PropTypes.func,
|
2021-10-08 11:12:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
renderLoading() {
|
|
|
|
return <div className='media-gallery--compact' />;
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpenMedia = (media, index) => {
|
|
|
|
this.props.dispatch(openModal('MEDIA', { media, index }));
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-10-09 10:33:08 -07:00
|
|
|
const { media, onClick } = this.props;
|
2021-10-08 11:12:38 -07:00
|
|
|
|
|
|
|
return (
|
2021-10-09 10:33:08 -07:00
|
|
|
<div className='attachment-thumbs'>
|
|
|
|
<Bundle fetchComponent={MediaGallery} loading={this.renderLoading}>
|
|
|
|
{Component => (
|
|
|
|
<Component
|
|
|
|
media={media}
|
|
|
|
onOpenMedia={this.onOpenMedia}
|
|
|
|
height={50}
|
|
|
|
compact
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Bundle>
|
|
|
|
{onClick && (
|
|
|
|
<div className='attachment-thumbs__clickable-region' onClick={onClick} />
|
2021-10-08 11:12:38 -07:00
|
|
|
)}
|
2021-10-09 10:33:08 -07:00
|
|
|
</div>
|
2021-10-08 11:12:38 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|