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.

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