parent
101f519d4b
commit
30983571b1
@ -0,0 +1,85 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { FormattedMessage, injectIntl } from 'react-intl';
|
||||
import { connect } from 'react-redux';
|
||||
import { getAccountGallery } from 'soapbox/selectors';
|
||||
import { openModal } from 'soapbox/actions/modal';
|
||||
import { expandAccountMediaTimeline } from '../../../actions/timelines';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import MediaItem from '../../account_gallery/components/media_item';
|
||||
import Icon from 'soapbox/components/icon';
|
||||
|
||||
class ProfileMediaPanel extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
account: ImmutablePropTypes.map,
|
||||
attachments: ImmutablePropTypes.list,
|
||||
dispatch: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
state = {
|
||||
width: 255,
|
||||
};
|
||||
|
||||
handleOpenMedia = attachment => {
|
||||
if (attachment.get('type') === 'video') {
|
||||
this.props.dispatch(openModal('VIDEO', { media: attachment, status: attachment.get('status') }));
|
||||
} else {
|
||||
const media = attachment.getIn(['status', 'media_attachments']);
|
||||
const index = media.findIndex(x => x.get('id') === attachment.get('id'));
|
||||
|
||||
this.props.dispatch(openModal('MEDIA', { media, index, status: attachment.get('status'), account: attachment.get('account') }));
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { account } = this.props;
|
||||
const accountId = account.get('id');
|
||||
this.props.dispatch(expandAccountMediaTimeline(accountId));
|
||||
}
|
||||
|
||||
render() {
|
||||
const { attachments } = this.props;
|
||||
const { width } = this.state;
|
||||
const nineAttachments = attachments.slice(0, 9);
|
||||
|
||||
if (attachments.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='media-panel'>
|
||||
<div className='media-panel-header'>
|
||||
<Icon id='camera' className='media-panel-header__icon' />
|
||||
<span className='media-panel-header__label'>
|
||||
<FormattedMessage id='media_panel.title' defaultMessage='Media' />
|
||||
</span>
|
||||
</div>
|
||||
<div className='media-panel__content'>
|
||||
<div className='media-panel__list'>
|
||||
{nineAttachments.map((attachment, index) => (
|
||||
<MediaItem
|
||||
key={`${attachment.getIn(['status', 'id'])}+${attachment.get('id')}`}
|
||||
attachment={attachment}
|
||||
displayWidth={width}
|
||||
onOpenMedia={this.handleOpenMedia}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
const mapStateToProps = (state, { account }) => ({
|
||||
attachments: getAccountGallery(state, account.get('id')),
|
||||
});
|
||||
|
||||
export default injectIntl(
|
||||
connect(mapStateToProps, null, null, {
|
||||
forwardRef: true,
|
||||
}
|
||||
)(ProfileMediaPanel));
|
@ -0,0 +1,48 @@
|
||||
.media-panel {
|
||||
@include standard-panel-shadow;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
border-radius: 10px;
|
||||
flex-direction: column;
|
||||
height: auto;
|
||||
box-sizing: border-box;
|
||||
background: var(--foreground-color);
|
||||
|
||||
&:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
&:not(:last-of-type) {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.media-panel-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
margin-bottom: 10px;
|
||||
padding: 15px 15px 0;
|
||||
|
||||
&__icon {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
&__label {
|
||||
flex: 1 1;
|
||||
color: var(--primary-text-color);
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
line-height: 19px;
|
||||
}
|
||||
}
|
||||
|
||||
&__content {
|
||||
width: 100%;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
&__list {
|
||||
padding: 0 5px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue