The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

93 lines
2.4 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import Column from '../../components/column';
  5. import ColumnHeader from '../../components/column_header';
  6. import { expandConversations } from '../../actions/conversations';
  7. import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
  8. import { defineMessages, injectIntl } from 'react-intl';
  9. import { connectDirectStream } from '../../actions/streaming';
  10. import ConversationsListContainer from './containers/conversations_list_container';
  11. const messages = defineMessages({
  12. title: { id: 'column.direct', defaultMessage: 'Direct messages' },
  13. });
  14. export default @connect()
  15. @injectIntl
  16. class DirectTimeline extends React.PureComponent {
  17. static propTypes = {
  18. dispatch: PropTypes.func.isRequired,
  19. shouldUpdateScroll: PropTypes.func,
  20. columnId: PropTypes.string,
  21. intl: PropTypes.object.isRequired,
  22. hasUnread: PropTypes.bool,
  23. multiColumn: PropTypes.bool,
  24. };
  25. handlePin = () => {
  26. const { columnId, dispatch } = this.props;
  27. if (columnId) {
  28. dispatch(removeColumn(columnId));
  29. } else {
  30. dispatch(addColumn('DIRECT', {}));
  31. }
  32. }
  33. handleMove = (dir) => {
  34. const { columnId, dispatch } = this.props;
  35. dispatch(moveColumn(columnId, dir));
  36. }
  37. handleHeaderClick = () => {
  38. this.column.scrollTop();
  39. }
  40. componentDidMount () {
  41. const { dispatch } = this.props;
  42. dispatch(expandConversations());
  43. this.disconnect = dispatch(connectDirectStream());
  44. }
  45. componentWillUnmount () {
  46. if (this.disconnect) {
  47. this.disconnect();
  48. this.disconnect = null;
  49. }
  50. }
  51. setRef = c => {
  52. this.column = c;
  53. }
  54. handleLoadMore = maxId => {
  55. this.props.dispatch(expandConversations({ maxId }));
  56. }
  57. render () {
  58. const { intl, hasUnread, columnId, multiColumn, shouldUpdateScroll } = this.props;
  59. const pinned = !!columnId;
  60. return (
  61. <Column ref={this.setRef} label={intl.formatMessage(messages.title)}>
  62. <ColumnHeader
  63. icon='envelope'
  64. active={hasUnread}
  65. title={intl.formatMessage(messages.title)}
  66. onPin={this.handlePin}
  67. onMove={this.handleMove}
  68. onClick={this.handleHeaderClick}
  69. pinned={pinned}
  70. multiColumn={multiColumn}
  71. />
  72. <ConversationsListContainer shouldUpdateScroll={shouldUpdateScroll} />
  73. </Column>
  74. );
  75. }
  76. }