闭社主体 forked from https://github.com/tootsuite/mastodon
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.

106 lines
2.8 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. const UI = React.createClass({
  17. propTypes: {
  18. dispatch: React.PropTypes.func.isRequired,
  19. children: React.PropTypes.node
  20. },
  21. getInitialState () {
  22. return {
  23. width: window.innerWidth
  24. };
  25. },
  26. mixins: [PureRenderMixin],
  27. @debounce(500)
  28. handleResize () {
  29. this.setState({ width: window.innerWidth });
  30. },
  31. handleDragOver (e) {
  32. e.preventDefault();
  33. e.stopPropagation();
  34. e.dataTransfer.dropEffect = 'copy';
  35. if (e.dataTransfer.effectAllowed === 'all' || e.dataTransfer.effectAllowed === 'uninitialized') {
  36. //
  37. }
  38. },
  39. handleDrop (e) {
  40. e.preventDefault();
  41. if (e.dataTransfer && e.dataTransfer.files.length === 1) {
  42. this.props.dispatch(uploadCompose(e.dataTransfer.files));
  43. }
  44. },
  45. componentWillMount () {
  46. window.addEventListener('resize', this.handleResize, { passive: true });
  47. window.addEventListener('dragover', this.handleDragOver);
  48. window.addEventListener('drop', this.handleDrop);
  49. this.props.dispatch(refreshTimeline('home'));
  50. this.props.dispatch(refreshNotifications());
  51. },
  52. componentWillUnmount () {
  53. window.removeEventListener('resize', this.handleResize);
  54. window.removeEventListener('dragover', this.handleDragOver);
  55. window.removeEventListener('drop', this.handleDrop);
  56. },
  57. render () {
  58. let mountedColumns;
  59. if (isMobile(this.state.width)) {
  60. mountedColumns = (
  61. <ColumnsArea>
  62. {this.props.children}
  63. </ColumnsArea>
  64. );
  65. } else {
  66. mountedColumns = (
  67. <ColumnsArea>
  68. <Compose withHeader={true} />
  69. <HomeTimeline trackScroll={false} />
  70. <Notifications trackScroll={false} />
  71. {this.props.children}
  72. </ColumnsArea>
  73. );
  74. }
  75. return (
  76. <div className='ui'>
  77. <TabsBar />
  78. {mountedColumns}
  79. <NotificationsContainer />
  80. <LoadingBarContainer style={{ backgroundColor: '#2b90d9', left: '0', top: '0' }} />
  81. <ModalContainer />
  82. </div>
  83. );
  84. }
  85. });
  86. export default connect()(UI);