You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import ImmutablePropTypes from 'react-immutable-proptypes';
  2. import Avatar from './avatar';
  3. import RelativeTimestamp from './relative_timestamp';
  4. import PureRenderMixin from 'react-addons-pure-render-mixin';
  5. import DisplayName from './display_name';
  6. import MediaGallery from './media_gallery';
  7. import VideoPlayer from './video_player';
  8. import StatusContent from './status_content';
  9. import StatusActionBar from './status_action_bar';
  10. const Status = React.createClass({
  11. contextTypes: {
  12. router: React.PropTypes.object
  13. },
  14. propTypes: {
  15. status: ImmutablePropTypes.map,
  16. wrapped: React.PropTypes.bool,
  17. onReply: React.PropTypes.func,
  18. onFavourite: React.PropTypes.func,
  19. onReblog: React.PropTypes.func,
  20. onDelete: React.PropTypes.func,
  21. onOpenMedia: React.PropTypes.func,
  22. me: React.PropTypes.number,
  23. now: React.PropTypes.any
  24. },
  25. mixins: [PureRenderMixin],
  26. handleClick () {
  27. const { status } = this.props;
  28. this.context.router.push(`/statuses/${status.getIn(['reblog', 'id'], status.get('id'))}`);
  29. },
  30. handleAccountClick (id, e) {
  31. if (e.button === 0) {
  32. e.preventDefault();
  33. this.context.router.push(`/accounts/${id}`);
  34. }
  35. },
  36. render () {
  37. let media = '';
  38. const { status, now, ...other } = this.props;
  39. if (status === null) {
  40. return <div />;
  41. }
  42. if (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object') {
  43. let displayName = status.getIn(['account', 'display_name']);
  44. if (displayName.length === 0) {
  45. displayName = status.getIn(['account', 'username']);
  46. }
  47. return (
  48. <div style={{ cursor: 'default' }}>
  49. <div style={{ marginLeft: '68px', color: '#616b86', padding: '8px 0', paddingBottom: '2px', fontSize: '14px', position: 'relative' }}>
  50. <div style={{ position: 'absolute', 'left': '-26px'}}><i className='fa fa-fw fa-retweet'></i></div>
  51. <a onClick={this.handleAccountClick.bind(this, status.getIn(['account', 'id']))} href={status.getIn(['account', 'url'])} className='status__display-name'><strong style={{ color: '#616b86'}}>{displayName}</strong></a> reblogged
  52. </div>
  53. <Status {...other} wrapped={true} status={status.get('reblog')} />
  54. </div>
  55. );
  56. }
  57. if (status.get('media_attachments').size > 0) {
  58. if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  59. media = <VideoPlayer media={status.getIn(['media_attachments', 0])} />;
  60. } else {
  61. media = <MediaGallery media={status.get('media_attachments')} height={110} onOpenMedia={this.props.onOpenMedia} />;
  62. }
  63. }
  64. return (
  65. <div style={{ padding: '8px 10px', paddingLeft: '68px', position: 'relative', minHeight: '48px', borderBottom: '1px solid #363c4b', cursor: 'default' }}>
  66. <div style={{ fontSize: '15px' }}>
  67. <div style={{ float: 'right', fontSize: '14px' }}>
  68. <a href={status.get('url')} className='status__relative-time' style={{ color: '#616b86' }} target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} now={now} /></a>
  69. </div>
  70. <a onClick={this.handleAccountClick.bind(this, status.getIn(['account', 'id']))} href={status.getIn(['account', 'url'])} className='status__display-name' style={{ display: 'block', maxWidth: '100%', paddingRight: '25px', color: '#616b86' }}>
  71. <div style={{ position: 'absolute', left: '10px', top: '10px', width: '48px', height: '48px' }}>
  72. <Avatar src={status.getIn(['account', 'avatar'])} size={48} />
  73. </div>
  74. <DisplayName account={status.get('account')} />
  75. </a>
  76. </div>
  77. <StatusContent status={status} onClick={this.handleClick} />
  78. {media}
  79. <StatusActionBar {...this.props} />
  80. </div>
  81. );
  82. }
  83. });
  84. export default Status;