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
2.9 KiB

  1. import ColumnsArea from './components/columns_area';
  2. import NotificationsContainer from './containers/notifications_container';
  3. import PureRenderMixin from 'react-addons-pure-render-mixin';
  4. import LoadingBarContainer from './containers/loading_bar_container';
  5. import HomeTimeline from '../home_timeline';
  6. import MentionsTimeline from '../mentions_timeline';
  7. import Compose from '../compose';
  8. import TabsBar from './components/tabs_bar';
  9. import ModalContainer from './containers/modal_container';
  10. import Notifications from '../notifications';
  11. import { connect } from 'react-redux';
  12. import { isMobile } from '../../is_mobile';
  13. import { debounce } from 'react-decoration';
  14. import { uploadCompose } from '../../actions/compose';
  15. import { refreshTimeline } from '../../actions/timelines';
  16. import { refreshNotifications } from '../../actions/notifications';
  17. const UI = React.createClass({
  18. propTypes: {
  19. dispatch: React.PropTypes.func.isRequired,
  20. children: React.PropTypes.node
  21. },
  22. getInitialState () {
  23. return {
  24. width: window.innerWidth
  25. };
  26. },
  27. mixins: [PureRenderMixin],
  28. @debounce(500)
  29. handleResize () {
  30. this.setState({ width: window.innerWidth });
  31. },
  32. handleDragOver (e) {
  33. e.preventDefault();
  34. e.stopPropagation();
  35. e.dataTransfer.dropEffect = 'copy';
  36. if (e.dataTransfer.effectAllowed === 'all' || e.dataTransfer.effectAllowed === 'uninitialized') {
  37. //
  38. }
  39. },
  40. handleDrop (e) {
  41. e.preventDefault();
  42. if (e.dataTransfer && e.dataTransfer.files.length === 1) {
  43. this.props.dispatch(uploadCompose(e.dataTransfer.files));
  44. }
  45. },
  46. componentWillMount () {
  47. window.addEventListener('resize', this.handleResize, { passive: true });
  48. window.addEventListener('dragover', this.handleDragOver);
  49. window.addEventListener('drop', this.handleDrop);
  50. this.props.dispatch(refreshTimeline('home'));
  51. this.props.dispatch(refreshNotifications());
  52. },
  53. componentWillUnmount () {
  54. window.removeEventListener('resize', this.handleResize);
  55. window.removeEventListener('dragover', this.handleDragOver);
  56. window.removeEventListener('drop', this.handleDrop);
  57. },
  58. render () {
  59. let mountedColumns;
  60. if (isMobile(this.state.width)) {
  61. mountedColumns = (
  62. <ColumnsArea>
  63. {this.props.children}
  64. </ColumnsArea>
  65. );
  66. } else {
  67. mountedColumns = (
  68. <ColumnsArea>
  69. <Compose withHeader={true} />
  70. <HomeTimeline trackScroll={false} />
  71. <Notifications trackScroll={false} />
  72. {this.props.children}
  73. </ColumnsArea>
  74. );
  75. }
  76. return (
  77. <div style={{ flex: '0 0 auto', display: 'flex', flexDirection: 'column', width: '100%', height: '100%', background: '#1a1c23' }}>
  78. <TabsBar />
  79. {mountedColumns}
  80. <NotificationsContainer />
  81. <LoadingBarContainer style={{ backgroundColor: '#2b90d9', left: '0', top: '0' }} />
  82. <ModalContainer />
  83. </div>
  84. );
  85. }
  86. });
  87. export default connect()(UI);