2019-06-09 13:07:23 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 17:38:10 +03:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2019-06-09 13:07:23 +03:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2023-11-15 13:01:51 +02:00
|
|
|
import { autoPlayGif } from '../initial_state';
|
2019-06-09 13:07:23 +03:00
|
|
|
|
2023-05-28 15:18:23 +03:00
|
|
|
export default class AvatarComposite extends PureComponent {
|
2019-06-09 13:07:23 +03:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
accounts: ImmutablePropTypes.list.isRequired,
|
|
|
|
animate: PropTypes.bool,
|
|
|
|
size: PropTypes.number.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
animate: autoPlayGif,
|
|
|
|
};
|
|
|
|
|
|
|
|
renderItem (account, size, index) {
|
|
|
|
const { animate } = this.props;
|
|
|
|
|
|
|
|
let width = 50;
|
|
|
|
let height = 100;
|
|
|
|
let top = 'auto';
|
|
|
|
let left = 'auto';
|
|
|
|
let bottom = 'auto';
|
|
|
|
let right = 'auto';
|
|
|
|
|
|
|
|
if (size === 1) {
|
|
|
|
width = 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size === 4 || (size === 3 && index > 0)) {
|
|
|
|
height = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size === 2) {
|
|
|
|
if (index === 0) {
|
2019-09-21 21:01:16 +03:00
|
|
|
right = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
} else {
|
2019-09-21 21:01:16 +03:00
|
|
|
left = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
}
|
|
|
|
} else if (size === 3) {
|
|
|
|
if (index === 0) {
|
2019-09-21 21:01:16 +03:00
|
|
|
right = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
} else if (index > 0) {
|
2019-09-21 21:01:16 +03:00
|
|
|
left = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (index === 1) {
|
2019-09-21 21:01:16 +03:00
|
|
|
bottom = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
} else if (index > 1) {
|
2019-09-21 21:01:16 +03:00
|
|
|
top = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
}
|
|
|
|
} else if (size === 4) {
|
|
|
|
if (index === 0 || index === 2) {
|
2019-09-21 21:01:16 +03:00
|
|
|
right = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (index === 1 || index === 3) {
|
2019-09-21 21:01:16 +03:00
|
|
|
left = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (index < 2) {
|
2019-09-21 21:01:16 +03:00
|
|
|
bottom = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
} else {
|
2019-09-21 21:01:16 +03:00
|
|
|
top = '1px';
|
2019-06-09 13:07:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const style = {
|
|
|
|
left: left,
|
|
|
|
top: top,
|
|
|
|
right: right,
|
|
|
|
bottom: bottom,
|
|
|
|
width: `${width}%`,
|
|
|
|
height: `${height}%`,
|
|
|
|
backgroundSize: 'cover',
|
|
|
|
backgroundImage: `url(${account.get(animate ? 'avatar' : 'avatar_static')})`,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-05-18 00:24:27 +03:00
|
|
|
<div key={account.get('id')} style={style} data-avatar-of={`@${account.get('acct')}`} />
|
2019-06-09 13:07:23 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { accounts, size } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='account__avatar-composite' style={{ width: `${size}px`, height: `${size}px` }}>
|
2019-09-21 21:01:16 +03:00
|
|
|
{accounts.take(4).map((account, i) => this.renderItem(account, Math.min(accounts.size, 4), i))}
|
|
|
|
|
|
|
|
{accounts.size > 4 && (
|
|
|
|
<span className='account__avatar-composite__label'>
|
|
|
|
+{accounts.size - 4}
|
|
|
|
</span>
|
|
|
|
)}
|
2019-06-09 13:07:23 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|