index.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React from 'react';
  2. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  3. import { connect } from 'react-redux';
  4. import PropTypes from 'prop-types';
  5. import Column from 'mastodon/components/column';
  6. import ColumnHeader from 'mastodon/components/column_header';
  7. import { NavLink, Switch, Route } from 'react-router-dom';
  8. import Links from './links';
  9. import Tags from './tags';
  10. import Statuses from './statuses';
  11. import Suggestions from './suggestions';
  12. import Search from 'mastodon/features/compose/containers/search_container';
  13. import SearchResults from './results';
  14. import { Helmet } from 'react-helmet';
  15. import { showTrends } from 'mastodon/initial_state';
  16. const messages = defineMessages({
  17. title: { id: 'explore.title', defaultMessage: 'Explore' },
  18. searchResults: { id: 'explore.search_results', defaultMessage: 'Search results' },
  19. });
  20. const mapStateToProps = state => ({
  21. layout: state.getIn(['meta', 'layout']),
  22. isSearching: state.getIn(['search', 'submitted']) || !showTrends,
  23. });
  24. export default @connect(mapStateToProps)
  25. @injectIntl
  26. class Explore extends React.PureComponent {
  27. static contextTypes = {
  28. router: PropTypes.object,
  29. identity: PropTypes.object,
  30. };
  31. static propTypes = {
  32. intl: PropTypes.object.isRequired,
  33. multiColumn: PropTypes.bool,
  34. isSearching: PropTypes.bool,
  35. };
  36. handleHeaderClick = () => {
  37. this.column.scrollTop();
  38. }
  39. setRef = c => {
  40. this.column = c;
  41. }
  42. render () {
  43. const { intl, multiColumn, isSearching } = this.props;
  44. const { signedIn } = this.context.identity;
  45. return (
  46. <Column bindToDocument={!multiColumn} ref={this.setRef} label={intl.formatMessage(messages.title)}>
  47. <ColumnHeader
  48. icon={isSearching ? 'search' : 'hashtag'}
  49. title={intl.formatMessage(isSearching ? messages.searchResults : messages.title)}
  50. onClick={this.handleHeaderClick}
  51. multiColumn={multiColumn}
  52. />
  53. <div className='explore__search-header'>
  54. <Search />
  55. </div>
  56. <div className='scrollable scrollable--flex'>
  57. {isSearching ? (
  58. <SearchResults />
  59. ) : (
  60. <React.Fragment>
  61. <div className='account__section-headline'>
  62. <NavLink exact to='/explore'><FormattedMessage id='explore.trending_statuses' defaultMessage='Posts' /></NavLink>
  63. <NavLink exact to='/explore/tags'><FormattedMessage id='explore.trending_tags' defaultMessage='Hashtags' /></NavLink>
  64. <NavLink exact to='/explore/links'><FormattedMessage id='explore.trending_links' defaultMessage='News' /></NavLink>
  65. {signedIn && <NavLink exact to='/explore/suggestions'><FormattedMessage id='explore.suggested_follows' defaultMessage='For you' /></NavLink>}
  66. </div>
  67. <Switch>
  68. <Route path='/explore/tags' component={Tags} />
  69. <Route path='/explore/links' component={Links} />
  70. <Route path='/explore/suggestions' component={Suggestions} />
  71. <Route exact path={['/explore', '/explore/posts', '/search']} component={Statuses} componentParams={{ multiColumn }} />
  72. </Switch>
  73. <Helmet>
  74. <title>{intl.formatMessage(messages.title)}</title>
  75. <meta name='robots' content={isSearching ? 'noindex' : 'all'} />
  76. </Helmet>
  77. </React.Fragment>
  78. )}
  79. </div>
  80. </Column>
  81. );
  82. }
  83. }