闭社主体 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.

111 lines
4.9 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import React from 'react';
  2. import ComposeFormContainer from './containers/compose_form_container';
  3. import NavigationContainer from './containers/navigation_container';
  4. import PropTypes from 'prop-types';
  5. import ImmutablePropTypes from 'react-immutable-proptypes';
  6. import { connect } from 'react-redux';
  7. import { mountCompose, unmountCompose } from '../../actions/compose';
  8. import Link from 'react-router-dom/Link';
  9. import { injectIntl, defineMessages } from 'react-intl';
  10. import SearchContainer from './containers/search_container';
  11. import Motion from 'react-motion/lib/Motion';
  12. import spring from 'react-motion/lib/spring';
  13. import SearchResultsContainer from './containers/search_results_container';
  14. import { changeComposing } from '../../actions/compose';
  15. const messages = defineMessages({
  16. start: { id: 'getting_started.heading', defaultMessage: 'Getting started' },
  17. home_timeline: { id: 'tabs_bar.home', defaultMessage: 'Home' },
  18. notifications: { id: 'tabs_bar.notifications', defaultMessage: 'Notifications' },
  19. public: { id: 'navigation_bar.public_timeline', defaultMessage: 'Federated timeline' },
  20. community: { id: 'navigation_bar.community_timeline', defaultMessage: 'Local timeline' },
  21. preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' },
  22. logout: { id: 'navigation_bar.logout', defaultMessage: 'Logout' },
  23. });
  24. const mapStateToProps = state => ({
  25. columns: state.getIn(['settings', 'columns']),
  26. showSearch: state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']),
  27. });
  28. @connect(mapStateToProps)
  29. @injectIntl
  30. export default class Compose extends React.PureComponent {
  31. static propTypes = {
  32. dispatch: PropTypes.func.isRequired,
  33. columns: ImmutablePropTypes.list.isRequired,
  34. multiColumn: PropTypes.bool,
  35. showSearch: PropTypes.bool,
  36. intl: PropTypes.object.isRequired,
  37. };
  38. componentDidMount () {
  39. this.props.dispatch(mountCompose());
  40. }
  41. componentWillUnmount () {
  42. this.props.dispatch(unmountCompose());
  43. }
  44. onFocus = () => {
  45. this.props.dispatch(changeComposing(true));
  46. }
  47. onBlur = () => {
  48. this.props.dispatch(changeComposing(false));
  49. }
  50. render () {
  51. const { multiColumn, showSearch, intl } = this.props;
  52. let header = '';
  53. if (multiColumn) {
  54. const { columns } = this.props;
  55. header = (
  56. <nav className='drawer__header'>
  57. <Link to='/getting-started' className='drawer__tab' title={intl.formatMessage(messages.start)} aria-label={intl.formatMessage(messages.start)}><i role='img' className='fa fa-fw fa-asterisk' /></Link>
  58. {!columns.some(column => column.get('id') === 'HOME') && (
  59. <Link to='/timelines/home' className='drawer__tab' title={intl.formatMessage(messages.home_timeline)} aria-label={intl.formatMessage(messages.home_timeline)}><i role='img' className='fa fa-fw fa-home' /></Link>
  60. )}
  61. {!columns.some(column => column.get('id') === 'NOTIFICATIONS') && (
  62. <Link to='/notifications' className='drawer__tab' title={intl.formatMessage(messages.notifications)} aria-label={intl.formatMessage(messages.notifications)}><i role='img' className='fa fa-fw fa-bell' /></Link>
  63. )}
  64. {!columns.some(column => column.get('id') === 'COMMUNITY') && (
  65. <Link to='/timelines/public/local' className='drawer__tab' title={intl.formatMessage(messages.community)} aria-label={intl.formatMessage(messages.community)}><i role='img' className='fa fa-fw fa-users' /></Link>
  66. )}
  67. {!columns.some(column => column.get('id') === 'PUBLIC') && (
  68. <Link to='/timelines/public' className='drawer__tab' title={intl.formatMessage(messages.public)} aria-label={intl.formatMessage(messages.public)}><i role='img' className='fa fa-fw fa-globe' /></Link>
  69. )}
  70. <a href='/settings/preferences' className='drawer__tab' title={intl.formatMessage(messages.preferences)} aria-label={intl.formatMessage(messages.preferences)}><i role='img' className='fa fa-fw fa-cog' /></a>
  71. <a href='/auth/sign_out' className='drawer__tab' data-method='delete' title={intl.formatMessage(messages.logout)} aria-label={intl.formatMessage(messages.logout)}><i role='img' className='fa fa-fw fa-sign-out' /></a>
  72. </nav>
  73. );
  74. }
  75. return (
  76. <div className='drawer'>
  77. {header}
  78. <SearchContainer />
  79. <div className='drawer__pager'>
  80. <div className='drawer__inner' onFocus={this.onFocus}>
  81. <NavigationContainer onClose={this.onBlur} />
  82. <ComposeFormContainer />
  83. </div>
  84. <Motion defaultStyle={{ x: -100 }} style={{ x: spring(showSearch ? 0 : -100, { stiffness: 210, damping: 20 }) }}>
  85. {({ x }) =>
  86. <div className='drawer__inner darker' style={{ transform: `translateX(${x}%)`, visibility: x === -100 ? 'hidden' : 'visible' }}>
  87. <SearchResultsContainer />
  88. </div>
  89. }
  90. </Motion>
  91. </div>
  92. </div>
  93. );
  94. }
  95. }