logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

onboarding_modal.js (12140B)


  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  6. import ReactSwipeableViews from 'react-swipeable-views';
  7. import classNames from 'classnames';
  8. import Permalink from '../../../components/permalink';
  9. import ComposeForm from '../../compose/components/compose_form';
  10. import Search from '../../compose/components/search';
  11. import NavigationBar from '../../compose/components/navigation_bar';
  12. import ColumnHeader from './column_header';
  13. import { List as ImmutableList } from 'immutable';
  14. import { me } from '../../../initial_state';
  15. const noop = () => { };
  16. const messages = defineMessages({
  17. home_title: { id: 'column.home', defaultMessage: 'Home' },
  18. notifications_title: { id: 'column.notifications', defaultMessage: 'Notifications' },
  19. local_title: { id: 'column.community', defaultMessage: 'Local timeline' },
  20. federated_title: { id: 'column.public', defaultMessage: 'Federated timeline' },
  21. });
  22. const PageOne = ({ acct, domain }) => (
  23. <div className='onboarding-modal__page onboarding-modal__page-one'>
  24. <div className='onboarding-modal__page-one__lead'>
  25. <h1><FormattedMessage id='onboarding.page_one.welcome' defaultMessage='Welcome to Mastodon!' /></h1>
  26. <p><FormattedMessage id='onboarding.page_one.federation' defaultMessage='Mastodon is a network of independent servers joining up to make one larger social network. We call these servers instances.' /></p>
  27. </div>
  28. <div className='onboarding-modal__page-one__extra'>
  29. <div className='display-case'>
  30. <div className='display-case__label'>
  31. <FormattedMessage id='onboarding.page_one.full_handle' defaultMessage='Your full handle' />
  32. </div>
  33. <div className='display-case__case'>
  34. @{acct}@{domain}
  35. </div>
  36. </div>
  37. <p><FormattedMessage id='onboarding.page_one.handle_hint' defaultMessage='This is what you would tell your friends to search for.' /></p>
  38. </div>
  39. </div>
  40. );
  41. PageOne.propTypes = {
  42. acct: PropTypes.string.isRequired,
  43. domain: PropTypes.string.isRequired,
  44. };
  45. const PageTwo = ({ myAccount }) => (
  46. <div className='onboarding-modal__page onboarding-modal__page-two'>
  47. <div className='figure non-interactive'>
  48. <div className='pseudo-drawer'>
  49. <NavigationBar account={myAccount} />
  50. <ComposeForm
  51. text='Awoo! #introductions'
  52. suggestions={ImmutableList()}
  53. mentionedDomains={[]}
  54. spoiler={false}
  55. onChange={noop}
  56. onSubmit={noop}
  57. onPaste={noop}
  58. onPickEmoji={noop}
  59. onChangeSpoilerText={noop}
  60. onClearSuggestions={noop}
  61. onFetchSuggestions={noop}
  62. onSuggestionSelected={noop}
  63. showSearch
  64. />
  65. </div>
  66. </div>
  67. <p><FormattedMessage id='onboarding.page_two.compose' defaultMessage='Write posts from the compose column. You can upload images, change privacy settings, and add content warnings with the icons below.' /></p>
  68. </div>
  69. );
  70. PageTwo.propTypes = {
  71. myAccount: ImmutablePropTypes.map.isRequired,
  72. };
  73. const PageThree = ({ myAccount }) => (
  74. <div className='onboarding-modal__page onboarding-modal__page-three'>
  75. <div className='figure non-interactive'>
  76. <Search
  77. value=''
  78. onChange={noop}
  79. onSubmit={noop}
  80. onClear={noop}
  81. onShow={noop}
  82. />
  83. <div className='pseudo-drawer'>
  84. <NavigationBar account={myAccount} />
  85. </div>
  86. </div>
  87. <p><FormattedMessage id='onboarding.page_three.search' defaultMessage='Use the search bar to find people and look at hashtags, such as {illustration} and {introductions}. To look for a person who is not on this instance, use their full handle.' values={{ illustration: <Permalink to='/timelines/tag/illustration' href='/tags/illustration'>#illustration</Permalink>, introductions: <Permalink to='/timelines/tag/introductions' href='/tags/introductions'>#introductions</Permalink> }} /></p>
  88. <p><FormattedMessage id='onboarding.page_three.profile' defaultMessage='Edit your profile to change your avatar, bio, and display name. There, you will also find other preferences.' /></p>
  89. </div>
  90. );
  91. PageThree.propTypes = {
  92. myAccount: ImmutablePropTypes.map.isRequired,
  93. };
  94. const PageFour = ({ domain, intl }) => (
  95. <div className='onboarding-modal__page onboarding-modal__page-four'>
  96. <div className='onboarding-modal__page-four__columns'>
  97. <div className='row'>
  98. <div>
  99. <div className='figure non-interactive'><ColumnHeader icon='home' type={intl.formatMessage(messages.home_title)} /></div>
  100. <p><FormattedMessage id='onboarding.page_four.home' defaultMessage='The home timeline shows posts from people you follow.' /></p>
  101. </div>
  102. <div>
  103. <div className='figure non-interactive'><ColumnHeader icon='bell' type={intl.formatMessage(messages.notifications_title)} /></div>
  104. <p><FormattedMessage id='onboarding.page_four.notifications' defaultMessage='The notifications column shows when someone interacts with you.' /></p>
  105. </div>
  106. </div>
  107. <div className='row'>
  108. <div>
  109. <div className='figure non-interactive' style={{ marginBottom: 0 }}><ColumnHeader icon='users' type={intl.formatMessage(messages.local_title)} /></div>
  110. </div>
  111. <div>
  112. <div className='figure non-interactive' style={{ marginBottom: 0 }}><ColumnHeader icon='globe' type={intl.formatMessage(messages.federated_title)} /></div>
  113. </div>
  114. </div>
  115. <p><FormattedMessage id='onboarding.page_five.public_timelines' defaultMessage='The local timeline shows public posts from everyone on {domain}. The federated timeline shows public posts from everyone who people on {domain} follow. These are the Public Timelines, a great way to discover new people.' values={{ domain }} /></p>
  116. </div>
  117. </div>
  118. );
  119. PageFour.propTypes = {
  120. domain: PropTypes.string.isRequired,
  121. intl: PropTypes.object.isRequired,
  122. };
  123. const PageSix = ({ admin, domain }) => {
  124. let adminSection = '';
  125. if (admin) {
  126. adminSection = (
  127. <p>
  128. <FormattedMessage id='onboarding.page_six.admin' defaultMessage="Your instance's admin is {admin}." values={{ admin: <Permalink href={admin.get('url')} to={`/accounts/${admin.get('id')}`}>@{admin.get('acct')}</Permalink> }} />
  129. <br />
  130. <FormattedMessage id='onboarding.page_six.read_guidelines' defaultMessage="Please read {domain}'s {guidelines}!" values={{ domain, guidelines: <a href='/about/more' target='_blank'><FormattedMessage id='onboarding.page_six.guidelines' defaultMessage='community guidelines' /></a> }} />
  131. </p>
  132. );
  133. }
  134. return (
  135. <div className='onboarding-modal__page onboarding-modal__page-six'>
  136. <h1><FormattedMessage id='onboarding.page_six.almost_done' defaultMessage='Almost done...' /></h1>
  137. {adminSection}
  138. <p><FormattedMessage id='onboarding.page_six.github' defaultMessage='Mastodon is free open-source software. You can report bugs, request features, or contribute to the code on {github}.' values={{ github: <a href='https://github.com/tootsuite/mastodon' target='_blank' rel='noopener'>GitHub</a> }} /></p>
  139. <p><FormattedMessage id='onboarding.page_six.apps_available' defaultMessage='There are {apps} available for iOS, Android and other platforms.' values={{ apps: <a href='https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/Apps.md' target='_blank' rel='noopener'><FormattedMessage id='onboarding.page_six.various_app' defaultMessage='mobile apps' /></a> }} /></p>
  140. <p><em><FormattedMessage id='onboarding.page_six.appetoot' defaultMessage='Bon Appetoot!' /></em></p>
  141. </div>
  142. );
  143. };
  144. PageSix.propTypes = {
  145. admin: ImmutablePropTypes.map,
  146. domain: PropTypes.string.isRequired,
  147. };
  148. const mapStateToProps = state => ({
  149. myAccount: state.getIn(['accounts', me]),
  150. admin: state.getIn(['accounts', state.getIn(['meta', 'admin'])]),
  151. domain: state.getIn(['meta', 'domain']),
  152. });
  153. @connect(mapStateToProps)
  154. @injectIntl
  155. export default class OnboardingModal extends React.PureComponent {
  156. static propTypes = {
  157. onClose: PropTypes.func.isRequired,
  158. intl: PropTypes.object.isRequired,
  159. myAccount: ImmutablePropTypes.map.isRequired,
  160. domain: PropTypes.string.isRequired,
  161. admin: ImmutablePropTypes.map,
  162. };
  163. state = {
  164. currentIndex: 0,
  165. };
  166. componentWillMount() {
  167. const { myAccount, admin, domain, intl } = this.props;
  168. this.pages = [
  169. <PageOne acct={myAccount.get('acct')} domain={domain} />,
  170. <PageTwo myAccount={myAccount} />,
  171. <PageThree myAccount={myAccount} />,
  172. <PageFour domain={domain} intl={intl} />,
  173. <PageSix admin={admin} domain={domain} />,
  174. ];
  175. };
  176. componentDidMount() {
  177. window.addEventListener('keyup', this.handleKeyUp);
  178. }
  179. componentWillUnmount() {
  180. window.addEventListener('keyup', this.handleKeyUp);
  181. }
  182. handleSkip = (e) => {
  183. e.preventDefault();
  184. this.props.onClose();
  185. }
  186. handleDot = (e) => {
  187. const i = Number(e.currentTarget.getAttribute('data-index'));
  188. e.preventDefault();
  189. this.setState({ currentIndex: i });
  190. }
  191. handlePrev = () => {
  192. this.setState(({ currentIndex }) => ({
  193. currentIndex: Math.max(0, currentIndex - 1),
  194. }));
  195. }
  196. handleNext = () => {
  197. const { pages } = this;
  198. this.setState(({ currentIndex }) => ({
  199. currentIndex: Math.min(currentIndex + 1, pages.length - 1),
  200. }));
  201. }
  202. handleSwipe = (index) => {
  203. this.setState({ currentIndex: index });
  204. }
  205. handleKeyUp = ({ key }) => {
  206. switch (key) {
  207. case 'ArrowLeft':
  208. this.handlePrev();
  209. break;
  210. case 'ArrowRight':
  211. this.handleNext();
  212. break;
  213. }
  214. }
  215. handleClose = () => {
  216. this.props.onClose();
  217. }
  218. render () {
  219. const { pages } = this;
  220. const { currentIndex } = this.state;
  221. const hasMore = currentIndex < pages.length - 1;
  222. const nextOrDoneBtn = hasMore ? (
  223. <button onClick={this.handleNext} className='onboarding-modal__nav onboarding-modal__next shake-bottom'>
  224. <FormattedMessage id='onboarding.next' defaultMessage='Next' /> <i className='fa fa-fw fa-chevron-right' />
  225. </button>
  226. ) : (
  227. <button onClick={this.handleClose} className='onboarding-modal__nav onboarding-modal__done shake-bottom'>
  228. <FormattedMessage id='onboarding.done' defaultMessage='Done' /> <i className='fa fa-fw fa-check' />
  229. </button>
  230. );
  231. return (
  232. <div className='modal-root__modal onboarding-modal'>
  233. <ReactSwipeableViews index={currentIndex} onChangeIndex={this.handleSwipe} className='onboarding-modal__pager'>
  234. {pages.map((page, i) => {
  235. const className = classNames('onboarding-modal__page__wrapper', `onboarding-modal__page__wrapper-${i}`, {
  236. 'onboarding-modal__page__wrapper--active': i === currentIndex,
  237. });
  238. return (
  239. <div key={i} className={className}>{page}</div>
  240. );
  241. })}
  242. </ReactSwipeableViews>
  243. <div className='onboarding-modal__paginator'>
  244. <div>
  245. <button
  246. onClick={this.handleSkip}
  247. className='onboarding-modal__nav onboarding-modal__skip'
  248. >
  249. <FormattedMessage id='onboarding.skip' defaultMessage='Skip' />
  250. </button>
  251. </div>
  252. <div className='onboarding-modal__dots'>
  253. {pages.map((_, i) => {
  254. const className = classNames('onboarding-modal__dot', {
  255. active: i === currentIndex,
  256. });
  257. return (
  258. <div
  259. key={`dot-${i}`}
  260. role='button'
  261. tabIndex='0'
  262. data-index={i}
  263. onClick={this.handleDot}
  264. className={className}
  265. />
  266. );
  267. })}
  268. </div>
  269. <div>
  270. {nextOrDoneBtn}
  271. </div>
  272. </div>
  273. </div>
  274. );
  275. }
  276. }