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.

178 lines
6.9 KiB

  1. import React from 'react';
  2. import Column from '../ui/components/column';
  3. import ColumnLink from '../ui/components/column_link';
  4. import ColumnSubheading from '../ui/components/column_subheading';
  5. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  6. import { connect } from 'react-redux';
  7. import PropTypes from 'prop-types';
  8. import ImmutablePropTypes from 'react-immutable-proptypes';
  9. import ImmutablePureComponent from 'react-immutable-pure-component';
  10. import { me, profile_directory, showTrends } from '../../initial_state';
  11. import { fetchFollowRequests } from 'mastodon/actions/accounts';
  12. import { List as ImmutableList } from 'immutable';
  13. import NavigationBar from '../compose/components/navigation_bar';
  14. import Icon from 'mastodon/components/icon';
  15. import LinkFooter from 'mastodon/features/ui/components/link_footer';
  16. import TrendsContainer from './containers/trends_container';
  17. const messages = defineMessages({
  18. home_timeline: { id: 'tabs_bar.home', defaultMessage: 'Home' },
  19. notifications: { id: 'tabs_bar.notifications', defaultMessage: 'Notifications' },
  20. public_timeline: { id: 'navigation_bar.public_timeline', defaultMessage: 'Federated timeline' },
  21. settings_subheading: { id: 'column_subheading.settings', defaultMessage: 'Settings' },
  22. community_timeline: { id: 'navigation_bar.community_timeline', defaultMessage: 'Local timeline' },
  23. direct: { id: 'navigation_bar.direct', defaultMessage: 'Direct messages' },
  24. bookmarks: { id: 'navigation_bar.bookmarks', defaultMessage: 'Bookmarks' },
  25. preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' },
  26. follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
  27. favourites: { id: 'navigation_bar.favourites', defaultMessage: 'Favourites' },
  28. blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' },
  29. domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' },
  30. mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' },
  31. pins: { id: 'navigation_bar.pins', defaultMessage: 'Pinned toots' },
  32. lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' },
  33. discover: { id: 'navigation_bar.discover', defaultMessage: 'Discover' },
  34. personal: { id: 'navigation_bar.personal', defaultMessage: 'Personal' },
  35. security: { id: 'navigation_bar.security', defaultMessage: 'Security' },
  36. menu: { id: 'getting_started.heading', defaultMessage: 'Getting started' },
  37. profile_directory: { id: 'getting_started.directory', defaultMessage: 'Profile directory' },
  38. });
  39. const mapStateToProps = state => ({
  40. myAccount: state.getIn(['accounts', me]),
  41. unreadFollowRequests: state.getIn(['user_lists', 'follow_requests', 'items'], ImmutableList()).size,
  42. });
  43. const mapDispatchToProps = dispatch => ({
  44. fetchFollowRequests: () => dispatch(fetchFollowRequests()),
  45. });
  46. const badgeDisplay = (number, limit) => {
  47. if (number === 0) {
  48. return undefined;
  49. } else if (limit && number >= limit) {
  50. return `${limit}+`;
  51. } else {
  52. return number;
  53. }
  54. };
  55. const NAVIGATION_PANEL_BREAKPOINT = 600 + (285 * 2) + (10 * 2);
  56. export default @connect(mapStateToProps, mapDispatchToProps)
  57. @injectIntl
  58. class GettingStarted extends ImmutablePureComponent {
  59. static contextTypes = {
  60. router: PropTypes.object.isRequired,
  61. };
  62. static propTypes = {
  63. intl: PropTypes.object.isRequired,
  64. myAccount: ImmutablePropTypes.map.isRequired,
  65. columns: ImmutablePropTypes.list,
  66. multiColumn: PropTypes.bool,
  67. fetchFollowRequests: PropTypes.func.isRequired,
  68. unreadFollowRequests: PropTypes.number,
  69. unreadNotifications: PropTypes.number,
  70. };
  71. componentDidMount () {
  72. const { fetchFollowRequests, multiColumn } = this.props;
  73. if (!multiColumn && window.innerWidth >= NAVIGATION_PANEL_BREAKPOINT) {
  74. this.context.router.history.replace('/timelines/home');
  75. return;
  76. }
  77. fetchFollowRequests();
  78. }
  79. render () {
  80. const { intl, myAccount, multiColumn, unreadFollowRequests } = this.props;
  81. const navItems = [];
  82. let i = 1;
  83. let height = (multiColumn) ? 0 : 60;
  84. if (multiColumn) {
  85. navItems.push(
  86. <ColumnSubheading key={i++} text={intl.formatMessage(messages.discover)} />,
  87. <ColumnLink key={i++} icon='users' text={intl.formatMessage(messages.community_timeline)} to='/timelines/public/local' />,
  88. <ColumnLink key={i++} icon='globe' text={intl.formatMessage(messages.public_timeline)} to='/timelines/public' />,
  89. );
  90. height += 34 + 48*2;
  91. if (profile_directory) {
  92. navItems.push(
  93. <ColumnLink key={i++} icon='address-book' text={intl.formatMessage(messages.profile_directory)} to='/directory' />
  94. );
  95. height += 48;
  96. }
  97. navItems.push(
  98. <ColumnSubheading key={i++} text={intl.formatMessage(messages.personal)} />
  99. );
  100. height += 34;
  101. } else if (profile_directory) {
  102. navItems.push(
  103. <ColumnLink key={i++} icon='address-book' text={intl.formatMessage(messages.profile_directory)} to='/directory' />
  104. );
  105. height += 48;
  106. }
  107. navItems.push(
  108. <ColumnLink key={i++} icon='envelope' text={intl.formatMessage(messages.direct)} to='/timelines/direct' />,
  109. <ColumnLink key={i++} icon='bookmark' text={intl.formatMessage(messages.bookmarks)} to='/bookmarks' />,
  110. <ColumnLink key={i++} icon='star' text={intl.formatMessage(messages.favourites)} to='/favourites' />,
  111. <ColumnLink key={i++} icon='list-ul' text={intl.formatMessage(messages.lists)} to='/lists' />
  112. );
  113. height += 48*4;
  114. if (myAccount.get('locked') || unreadFollowRequests > 0) {
  115. navItems.push(<ColumnLink key={i++} icon='user-plus' text={intl.formatMessage(messages.follow_requests)} badge={badgeDisplay(unreadFollowRequests, 40)} to='/follow_requests' />);
  116. height += 48;
  117. }
  118. if (!multiColumn) {
  119. navItems.push(
  120. <ColumnSubheading key={i++} text={intl.formatMessage(messages.settings_subheading)} />,
  121. <ColumnLink key={i++} icon='gears' text={intl.formatMessage(messages.preferences)} href='/settings/preferences' />,
  122. );
  123. height += 34 + 48;
  124. }
  125. return (
  126. <Column bindToDocument={!multiColumn} label={intl.formatMessage(messages.menu)}>
  127. {multiColumn && <div className='column-header__wrapper'>
  128. <h1 className='column-header'>
  129. <button>
  130. <Icon id='bars' className='column-header__icon' fixedWidth />
  131. <FormattedMessage id='getting_started.heading' defaultMessage='Getting started' />
  132. </button>
  133. </h1>
  134. </div>}
  135. <div className='getting-started'>
  136. <div className='getting-started__wrapper' style={{ height }}>
  137. {!multiColumn && <NavigationBar account={myAccount} />}
  138. {navItems}
  139. </div>
  140. {!multiColumn && <div className='flex-spacer' />}
  141. <LinkFooter withHotkeys={multiColumn} />
  142. </div>
  143. {multiColumn && showTrends && <TrendsContainer />}
  144. </Column>
  145. );
  146. }
  147. }