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.

189 lines
8.6 KiB

  1. import React from 'react';
  2. import Column from 'flavours/glitch/features/ui/components/column';
  3. import ColumnLink from 'flavours/glitch/features/ui/components/column_link';
  4. import ColumnSubheading from 'flavours/glitch/features/ui/components/column_subheading';
  5. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  6. import { connect } from 'react-redux';
  7. import { openModal } from 'flavours/glitch/actions/modal';
  8. import PropTypes from 'prop-types';
  9. import ImmutablePropTypes from 'react-immutable-proptypes';
  10. import ImmutablePureComponent from 'react-immutable-pure-component';
  11. import { me } from 'flavours/glitch/util/initial_state';
  12. import { fetchFollowRequests } from 'flavours/glitch/actions/accounts';
  13. import { List as ImmutableList } from 'immutable';
  14. import { createSelector } from 'reselect';
  15. import { fetchLists } from 'flavours/glitch/actions/lists';
  16. const messages = defineMessages({
  17. heading: { id: 'getting_started.heading', defaultMessage: 'Getting started' },
  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. navigation_subheading: { id: 'column_subheading.navigation', defaultMessage: 'Navigation' },
  22. settings_subheading: { id: 'column_subheading.settings', defaultMessage: 'Settings' },
  23. community_timeline: { id: 'navigation_bar.community_timeline', defaultMessage: 'Local timeline' },
  24. direct: { id: 'navigation_bar.direct', defaultMessage: 'Direct messages' },
  25. preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' },
  26. settings: { id: 'navigation_bar.app_settings', defaultMessage: 'App settings' },
  27. follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
  28. sign_out: { id: 'navigation_bar.logout', defaultMessage: 'Logout' },
  29. lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' },
  30. keyboard_shortcuts: { id: 'navigation_bar.keyboard_shortcuts', defaultMessage: 'Keyboard shortcuts' },
  31. lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' },
  32. lists_subheading: { id: 'column_subheading.lists', defaultMessage: 'Lists' },
  33. misc: { id: 'navigation_bar.misc', defaultMessage: 'Misc' },
  34. });
  35. const makeMapStateToProps = () => {
  36. const getOrderedLists = createSelector([state => state.get('lists')], lists => {
  37. if (!lists) {
  38. return lists;
  39. }
  40. return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title')));
  41. });
  42. const mapStateToProps = state => ({
  43. lists: getOrderedLists(state),
  44. myAccount: state.getIn(['accounts', me]),
  45. columns: state.getIn(['settings', 'columns']),
  46. unreadFollowRequests: state.getIn(['user_lists', 'follow_requests', 'items'], ImmutableList()).size,
  47. unreadNotifications: state.getIn(['notifications', 'unread']),
  48. });
  49. return mapStateToProps;
  50. };
  51. const mapDispatchToProps = dispatch => ({
  52. fetchFollowRequests: () => dispatch(fetchFollowRequests()),
  53. fetchLists: () => dispatch(fetchLists()),
  54. openSettings: () => dispatch(openModal('SETTINGS', {})),
  55. });
  56. const badgeDisplay = (number, limit) => {
  57. if (number === 0) {
  58. return undefined;
  59. } else if (limit && number >= limit) {
  60. return `${limit}+`;
  61. } else {
  62. return number;
  63. }
  64. };
  65. @connect(makeMapStateToProps, mapDispatchToProps)
  66. @injectIntl
  67. export default class GettingStarted extends ImmutablePureComponent {
  68. static propTypes = {
  69. intl: PropTypes.object.isRequired,
  70. myAccount: ImmutablePropTypes.map.isRequired,
  71. columns: ImmutablePropTypes.list,
  72. multiColumn: PropTypes.bool,
  73. fetchFollowRequests: PropTypes.func.isRequired,
  74. unreadFollowRequests: PropTypes.number,
  75. unreadNotifications: PropTypes.number,
  76. lists: ImmutablePropTypes.list,
  77. fetchLists: PropTypes.func.isRequired,
  78. openSettings: PropTypes.func.isRequired,
  79. };
  80. componentWillMount () {
  81. this.props.fetchLists();
  82. }
  83. componentDidMount () {
  84. const { myAccount, fetchFollowRequests } = this.props;
  85. if (myAccount.get('locked')) {
  86. fetchFollowRequests();
  87. }
  88. }
  89. render () {
  90. const { intl, myAccount, columns, multiColumn, unreadFollowRequests, unreadNotifications, lists, openSettings } = this.props;
  91. const navItems = [];
  92. let listItems = [];
  93. if (multiColumn) {
  94. if (!columns.find(item => item.get('id') === 'HOME')) {
  95. navItems.push(<ColumnLink key='0' icon='home' text={intl.formatMessage(messages.home_timeline)} to='/timelines/home' />);
  96. }
  97. if (!columns.find(item => item.get('id') === 'NOTIFICATIONS')) {
  98. navItems.push(<ColumnLink key='1' icon='bell' text={intl.formatMessage(messages.notifications)} badge={badgeDisplay(unreadNotifications)} to='/notifications' />);
  99. }
  100. if (!columns.find(item => item.get('id') === 'COMMUNITY')) {
  101. navItems.push(<ColumnLink key='2' icon='users' text={intl.formatMessage(messages.community_timeline)} to='/timelines/public/local' />);
  102. }
  103. if (!columns.find(item => item.get('id') === 'PUBLIC')) {
  104. navItems.push(<ColumnLink key='3' icon='globe' text={intl.formatMessage(messages.public_timeline)} to='/timelines/public' />);
  105. }
  106. }
  107. if (!multiColumn || !columns.find(item => item.get('id') === 'DIRECT')) {
  108. navItems.push(<ColumnLink key='4' icon='envelope' text={intl.formatMessage(messages.direct)} to='/timelines/direct' />);
  109. }
  110. if (myAccount.get('locked')) {
  111. navItems.push(<ColumnLink key='5' icon='users' text={intl.formatMessage(messages.follow_requests)} badge={badgeDisplay(unreadFollowRequests, 40)} to='/follow_requests' />);
  112. }
  113. navItems.push(<ColumnLink key='6' icon='ellipsis-h' text={intl.formatMessage(messages.misc)} to='/getting-started-misc' />);
  114. listItems = listItems.concat([
  115. <div key='7'>
  116. <ColumnLink key='8' icon='bars' text={intl.formatMessage(messages.lists)} to='/lists' />
  117. {lists.map(list =>
  118. <ColumnLink key={(8 + Number(list.get('id'))).toString()} to={`/timelines/list/${list.get('id')}`} icon='list-ul' text={list.get('title')} />
  119. )}
  120. </div>,
  121. ]);
  122. return (
  123. <Column name='getting-started' icon='asterisk' heading={intl.formatMessage(messages.heading)} hideHeadingOnMobile>
  124. <div className='scrollable optionally-scrollable'>
  125. <div className='getting-started__wrapper'>
  126. <ColumnSubheading text={intl.formatMessage(messages.navigation_subheading)} />
  127. {navItems}
  128. <ColumnSubheading text={intl.formatMessage(messages.lists_subheading)} />
  129. {listItems}
  130. <ColumnSubheading text={intl.formatMessage(messages.settings_subheading)} />
  131. <ColumnLink icon='cog' text={intl.formatMessage(messages.preferences)} href='/settings/preferences' />
  132. <ColumnLink icon='cogs' text={intl.formatMessage(messages.settings)} onClick={openSettings} />
  133. <ColumnLink icon='sign-out' text={intl.formatMessage(messages.sign_out)} href='/auth/sign_out' method='delete' />
  134. </div>
  135. <div className='getting-started__footer'>
  136. <div className='static-content getting-started'>
  137. <p>
  138. <a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/FAQ.md' rel='noopener' target='_blank'>
  139. <FormattedMessage id='getting_started.faq' defaultMessage='FAQ' />
  140. </a>&nbsp;&nbsp;
  141. <a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/User-guide.md' rel='noopener' target='_blank'>
  142. <FormattedMessage id='getting_started.userguide' defaultMessage='User Guide' />
  143. </a>&nbsp;&nbsp;
  144. <a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/Apps.md' rel='noopener' target='_blank'>
  145. <FormattedMessage id='getting_started.appsshort' defaultMessage='Apps' />
  146. </a>
  147. </p>
  148. <p>
  149. <FormattedMessage
  150. id='getting_started.open_source_notice'
  151. defaultMessage='Glitchsoc is open source software, a friendly fork of {Mastodon}. You can contribute or report issues on GitHub at {github}.'
  152. values={{
  153. github: <a href='https://github.com/glitch-soc/mastodon' rel='noopener' target='_blank'>glitch-soc/mastodon</a>,
  154. Mastodon: <a href='https://github.com/tootsuite/mastodon' rel='noopener' target='_blank'>Mastodon</a>,
  155. }}
  156. />
  157. </p>
  158. </div>
  159. </div>
  160. </div>
  161. </Column>
  162. );
  163. }
  164. }