The code powering m.abunchtell.com https://m.abunchtell.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

119 строки
3.1 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 Compose from '../compose';
  7. import TabsBar from './components/tabs_bar';
  8. import ModalContainer from './containers/modal_container';
  9. import Notifications from '../notifications';
  10. import { connect } from 'react-redux';
  11. import { isMobile } from '../../is_mobile';
  12. import { debounce } from 'react-decoration';
  13. import { uploadCompose } from '../../actions/compose';
  14. import { refreshTimeline } from '../../actions/timelines';
  15. import { refreshNotifications } from '../../actions/notifications';
  16. import UploadArea from './components/upload_area';
  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. draggingOver: false
  26. };
  27. },
  28. mixins: [PureRenderMixin],
  29. @debounce(500)
  30. handleResize () {
  31. this.setState({ width: window.innerWidth });
  32. },
  33. handleDragOver (e) {
  34. e.preventDefault();
  35. e.stopPropagation();
  36. e.dataTransfer.dropEffect = 'copy';
  37. if (e.dataTransfer.effectAllowed === 'all' || e.dataTransfer.effectAllowed === 'uninitialized') {
  38. this.setState({ draggingOver: true });
  39. }
  40. },
  41. handleDrop (e) {
  42. e.preventDefault();
  43. this.setState({ draggingOver: false });
  44. if (e.dataTransfer && e.dataTransfer.files.length === 1) {
  45. this.props.dispatch(uploadCompose(e.dataTransfer.files));
  46. }
  47. },
  48. handleDragLeave () {
  49. this.setState({ draggingOver: false });
  50. },
  51. componentWillMount () {
  52. window.addEventListener('resize', this.handleResize, { passive: true });
  53. window.addEventListener('dragover', this.handleDragOver);
  54. window.addEventListener('drop', this.handleDrop);
  55. this.props.dispatch(refreshTimeline('home'));
  56. this.props.dispatch(refreshNotifications());
  57. },
  58. componentWillUnmount () {
  59. window.removeEventListener('resize', this.handleResize);
  60. window.removeEventListener('dragover', this.handleDragOver);
  61. window.removeEventListener('drop', this.handleDrop);
  62. },
  63. render () {
  64. const { width, draggingOver } = this.state;
  65. const { children } = this.props;
  66. let mountedColumns;
  67. if (isMobile(width)) {
  68. mountedColumns = (
  69. <ColumnsArea>
  70. {children}
  71. </ColumnsArea>
  72. );
  73. } else {
  74. mountedColumns = (
  75. <ColumnsArea>
  76. <Compose withHeader={true} />
  77. <HomeTimeline trackScroll={false} />
  78. <Notifications trackScroll={false} />
  79. {children}
  80. </ColumnsArea>
  81. );
  82. }
  83. return (
  84. <div className='ui' onDragLeave={this.handleDragLeave}>
  85. <TabsBar />
  86. {mountedColumns}
  87. <NotificationsContainer />
  88. <LoadingBarContainer style={{ backgroundColor: '#2b90d9', left: '0', top: '0' }} />
  89. <ModalContainer />
  90. <UploadArea active={draggingOver} />
  91. </div>
  92. );
  93. }
  94. });
  95. export default connect()(UI);