2022-02-09 01:17:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 16:38:10 +02:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2022-02-09 01:17:07 +01:00
|
|
|
import { FormattedMessage, injectIntl } from 'react-intl';
|
2023-05-28 16:38:10 +02:00
|
|
|
|
2022-02-09 01:17:07 +01:00
|
|
|
import { connect } from 'react-redux';
|
2023-05-28 16:38:10 +02:00
|
|
|
|
2022-02-09 01:17:07 +01:00
|
|
|
import { openModal } from 'flavours/glitch/actions/modal';
|
2023-05-28 16:38:10 +02:00
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
2022-02-09 01:17:07 +01:00
|
|
|
import InlineAccount from 'flavours/glitch/components/inline_account';
|
2023-05-28 16:38:10 +02:00
|
|
|
import { RelativeTimestamp } from 'flavours/glitch/components/relative_timestamp';
|
|
|
|
|
|
|
|
import DropdownMenu from './containers/dropdown_menu_container';
|
2022-02-09 01:17:07 +01:00
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch, { statusId }) => ({
|
|
|
|
|
|
|
|
onItemClick (index) {
|
|
|
|
dispatch(openModal('COMPARE_HISTORY', { index, statusId }));
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2023-05-28 14:18:23 +02:00
|
|
|
class EditedTimestamp extends PureComponent {
|
2022-02-09 01:17:07 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
statusId: PropTypes.string.isRequired,
|
|
|
|
timestamp: PropTypes.string.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onItemClick: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleItemClick = (item, i) => {
|
|
|
|
const { onItemClick } = this.props;
|
|
|
|
onItemClick(i);
|
|
|
|
};
|
|
|
|
|
|
|
|
renderHeader = items => {
|
|
|
|
return (
|
2023-04-24 08:07:19 +02:00
|
|
|
<FormattedMessage id='status.edited_x_times' defaultMessage='Edited {count, plural, one {# time} other {# times}}' values={{ count: items.size - 1 }} />
|
2022-02-09 01:17:07 +01:00
|
|
|
);
|
2023-02-03 20:52:07 +01:00
|
|
|
};
|
2022-02-09 01:17:07 +01:00
|
|
|
|
|
|
|
renderItem = (item, index, { onClick, onKeyPress }) => {
|
|
|
|
const formattedDate = <RelativeTimestamp timestamp={item.get('created_at')} short={false} />;
|
|
|
|
const formattedName = <InlineAccount accountId={item.get('account')} />;
|
|
|
|
|
|
|
|
const label = item.get('original') ? (
|
|
|
|
<FormattedMessage id='status.history.created' defaultMessage='{name} created {date}' values={{ name: formattedName, date: formattedDate }} />
|
|
|
|
) : (
|
|
|
|
<FormattedMessage id='status.history.edited' defaultMessage='{name} edited {date}' values={{ name: formattedName, date: formattedDate }} />
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li className='dropdown-menu__item edited-timestamp__history__item' key={item.get('created_at')}>
|
|
|
|
<button data-index={index} onClick={onClick} onKeyPress={onKeyPress}>{label}</button>
|
|
|
|
</li>
|
|
|
|
);
|
2023-02-03 20:52:07 +01:00
|
|
|
};
|
2022-02-09 01:17:07 +01:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { timestamp, intl, statusId } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DropdownMenu statusId={statusId} renderItem={this.renderItem} scrollable renderHeader={this.renderHeader} onItemClick={this.handleItemClick}>
|
|
|
|
<button className='dropdown-menu__text-button'>
|
|
|
|
<FormattedMessage id='status.edited' defaultMessage='Edited {date}' values={{ date: intl.formatDate(timestamp, { hour12: false, month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }) }} /> <Icon id='caret-down' />
|
|
|
|
</button>
|
|
|
|
</DropdownMenu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 23:15:25 +01:00
|
|
|
|
|
|
|
export default connect(null, mapDispatchToProps)(injectIntl(EditedTimestamp));
|