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.

107 lines
4.2 KiB

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 IconButton from './icon_button';
  6. import DisplayName from './display_name';
  7. import MediaGallery from './media_gallery';
  8. import VideoPlayer from './video_player';
  9. import { hashHistory } from 'react-router';
  10. const Status = React.createClass({
  11. propTypes: {
  12. status: ImmutablePropTypes.map.isRequired,
  13. wrapped: React.PropTypes.bool,
  14. onReply: React.PropTypes.func,
  15. onFavourite: React.PropTypes.func,
  16. onReblog: React.PropTypes.func
  17. },
  18. mixins: [PureRenderMixin],
  19. handleReplyClick () {
  20. this.props.onReply(this.props.status);
  21. },
  22. handleFavouriteClick () {
  23. this.props.onFavourite(this.props.status);
  24. },
  25. handleReblogClick () {
  26. this.props.onReblog(this.props.status);
  27. },
  28. handleClick () {
  29. const { status } = this.props;
  30. hashHistory.push(`/statuses/${status.getIn(['reblog', 'id'], status.get('id'))}`);
  31. },
  32. handleAccountClick (id, e) {
  33. if (e.button === 0) {
  34. e.preventDefault();
  35. hashHistory.push(`/accounts/${id}`);
  36. }
  37. e.stopPropagation();
  38. },
  39. render () {
  40. var content = { __html: this.props.status.get('content') };
  41. var media = '';
  42. var { status, ...other } = this.props;
  43. if (status.get('reblog') !== null) {
  44. return (
  45. <div style={{ cursor: 'pointer' }} onClick={this.handleClick}>
  46. <div style={{ marginLeft: '68px', color: '#616b86', padding: '8px 0', paddingBottom: '2px', fontSize: '14px', position: 'relative' }}>
  47. <div style={{ position: 'absolute', 'left': '-26px'}}><i className='fa fa-fw fa-retweet'></i></div>
  48. <a onClick={this.handleAccountClick.bind(this, status.getIn(['account', 'id']))} href={status.getIn(['account', 'url'])} className='status__display-name'><strong style={{ color: '#616b86'}}>{status.getIn(['account', 'display_name'])}</strong></a> reblogged
  49. </div>
  50. <Status {...other} wrapped={true} status={status.get('reblog')} />
  51. </div>
  52. );
  53. }
  54. if (status.get('media_attachments').size > 0) {
  55. if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
  56. media = <VideoPlayer media={status.getIn(['media_attachments', 0])} />;
  57. } else {
  58. media = <MediaGallery media={status.get('media_attachments')} />;
  59. }
  60. }
  61. return (
  62. <div style={{ padding: '8px 10px', paddingLeft: '68px', position: 'relative', minHeight: '48px', borderBottom: '1px solid #363c4b', cursor: 'pointer' }} onClick={this.handleClick}>
  63. <div style={{ fontSize: '15px' }}>
  64. <div style={{ float: 'right', fontSize: '14px' }}>
  65. <a href={status.get('url')} className='status__relative-time' style={{ color: '#616b86' }}><RelativeTimestamp timestamp={status.get('created_at')} /></a>
  66. </div>
  67. <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' }}>
  68. <div style={{ position: 'absolute', left: '10px', top: '10px', width: '48px', height: '48px' }}>
  69. <Avatar src={status.getIn(['account', 'avatar'])} size={48} />
  70. </div>
  71. <DisplayName account={status.get('account')} />
  72. </a>
  73. </div>
  74. <div className='status__content' dangerouslySetInnerHTML={content} />
  75. {media}
  76. <div style={{ marginTop: '10px', overflow: 'hidden' }}>
  77. <div style={{ float: 'left', marginRight: '10px'}}><IconButton title='Reply' icon='reply' onClick={this.handleReplyClick} /></div>
  78. <div style={{ float: 'left', marginRight: '10px'}}><IconButton active={status.get('reblogged')} title='Reblog' icon='retweet' onClick={this.handleReblogClick} /></div>
  79. <div style={{ float: 'left'}}><IconButton active={status.get('favourited')} title='Favourite' icon='star' onClick={this.handleFavouriteClick} /></div>
  80. </div>
  81. </div>
  82. );
  83. }
  84. });
  85. export default Status;