index.jsx 3.7 KB

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