logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

index.js (5316B)


  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import StatusListContainer from '../ui/containers/status_list_container';
  6. import Column from '../../components/column';
  7. import ColumnHeader from '../../components/column_header';
  8. import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
  9. import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';
  10. import { connectListStream } from '../../actions/streaming';
  11. import { expandListTimeline } from '../../actions/timelines';
  12. import { fetchList, deleteList } from '../../actions/lists';
  13. import { openModal } from '../../actions/modal';
  14. import MissingIndicator from '../../components/missing_indicator';
  15. import LoadingIndicator from '../../components/loading_indicator';
  16. const messages = defineMessages({
  17. deleteMessage: { id: 'confirmations.delete_list.message', defaultMessage: 'Are you sure you want to permanently delete this list?' },
  18. deleteConfirm: { id: 'confirmations.delete_list.confirm', defaultMessage: 'Delete' },
  19. });
  20. const mapStateToProps = (state, props) => ({
  21. list: state.getIn(['lists', props.params.id]),
  22. hasUnread: state.getIn(['timelines', `list:${props.params.id}`, 'unread']) > 0,
  23. });
  24. @connect(mapStateToProps)
  25. @injectIntl
  26. export default class ListTimeline extends React.PureComponent {
  27. static contextTypes = {
  28. router: PropTypes.object,
  29. };
  30. static propTypes = {
  31. params: PropTypes.object.isRequired,
  32. dispatch: PropTypes.func.isRequired,
  33. columnId: PropTypes.string,
  34. hasUnread: PropTypes.bool,
  35. multiColumn: PropTypes.bool,
  36. list: PropTypes.oneOfType([ImmutablePropTypes.map, PropTypes.bool]),
  37. intl: PropTypes.object.isRequired,
  38. };
  39. handlePin = () => {
  40. const { columnId, dispatch } = this.props;
  41. if (columnId) {
  42. dispatch(removeColumn(columnId));
  43. } else {
  44. dispatch(addColumn('LIST', { id: this.props.params.id }));
  45. this.context.router.history.push('/');
  46. }
  47. }
  48. handleMove = (dir) => {
  49. const { columnId, dispatch } = this.props;
  50. dispatch(moveColumn(columnId, dir));
  51. }
  52. handleHeaderClick = () => {
  53. this.column.scrollTop();
  54. }
  55. componentDidMount () {
  56. const { dispatch } = this.props;
  57. const { id } = this.props.params;
  58. dispatch(fetchList(id));
  59. dispatch(expandListTimeline(id));
  60. this.disconnect = dispatch(connectListStream(id));
  61. }
  62. componentWillUnmount () {
  63. if (this.disconnect) {
  64. this.disconnect();
  65. this.disconnect = null;
  66. }
  67. }
  68. setRef = c => {
  69. this.column = c;
  70. }
  71. handleLoadMore = maxId => {
  72. const { id } = this.props.params;
  73. this.props.dispatch(expandListTimeline(id, { maxId }));
  74. }
  75. handleEditClick = () => {
  76. this.props.dispatch(openModal('LIST_EDITOR', { listId: this.props.params.id }));
  77. }
  78. handleDeleteClick = () => {
  79. const { dispatch, columnId, intl } = this.props;
  80. const { id } = this.props.params;
  81. dispatch(openModal('CONFIRM', {
  82. message: intl.formatMessage(messages.deleteMessage),
  83. confirm: intl.formatMessage(messages.deleteConfirm),
  84. onConfirm: () => {
  85. dispatch(deleteList(id));
  86. if (!!columnId) {
  87. dispatch(removeColumn(columnId));
  88. } else {
  89. this.context.router.history.push('/lists');
  90. }
  91. },
  92. }));
  93. }
  94. render () {
  95. const { hasUnread, columnId, multiColumn, list } = this.props;
  96. const { id } = this.props.params;
  97. const pinned = !!columnId;
  98. const title = list ? list.get('title') : id;
  99. if (typeof list === 'undefined') {
  100. return (
  101. <Column>
  102. <div className='scrollable'>
  103. <LoadingIndicator />
  104. </div>
  105. </Column>
  106. );
  107. } else if (list === false) {
  108. return (
  109. <Column>
  110. <div className='scrollable'>
  111. <MissingIndicator />
  112. </div>
  113. </Column>
  114. );
  115. }
  116. return (
  117. <Column ref={this.setRef}>
  118. <ColumnHeader
  119. icon='bars'
  120. active={hasUnread}
  121. title={title}
  122. onPin={this.handlePin}
  123. onMove={this.handleMove}
  124. onClick={this.handleHeaderClick}
  125. pinned={pinned}
  126. multiColumn={multiColumn}
  127. >
  128. <div className='column-header__links'>
  129. <button className='text-btn column-header__setting-btn' tabIndex='0' onClick={this.handleEditClick}>
  130. <i className='fa fa-pencil' /> <FormattedMessage id='lists.edit' defaultMessage='Edit list' />
  131. </button>
  132. <button className='text-btn column-header__setting-btn' tabIndex='0' onClick={this.handleDeleteClick}>
  133. <i className='fa fa-trash' /> <FormattedMessage id='lists.delete' defaultMessage='Delete list' />
  134. </button>
  135. </div>
  136. <hr />
  137. </ColumnHeader>
  138. <StatusListContainer
  139. trackScroll={!pinned}
  140. scrollKey={`list_timeline-${columnId}`}
  141. timelineId={`list:${id}`}
  142. onLoadMore={this.handleLoadMore}
  143. emptyMessage={<FormattedMessage id='empty_column.list' defaultMessage='There is nothing in this list yet. When members of this list post new statuses, they will appear here.' />}
  144. />
  145. </Column>
  146. );
  147. }
  148. }