The code powering m.abunchtell.com https://m.abunchtell.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

319 lines
12 KiB

  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 style={{ flex: '0 0 auto' }}>
  25. <div className='onboarding-modal__page-one__elephant-friend' />
  26. </div>
  27. <div>
  28. <h1><FormattedMessage id='onboarding.page_one.welcome' defaultMessage='Welcome to Mastodon!' /></h1>
  29. <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>
  30. <p><FormattedMessage id='onboarding.page_one.handle' defaultMessage='You are on {domain}, so your full handle is {handle}' values={{ domain, handle: <strong>@{acct}@{domain}</strong> }} /></p>
  31. </div>
  32. </div>
  33. );
  34. PageOne.propTypes = {
  35. acct: PropTypes.string.isRequired,
  36. domain: PropTypes.string.isRequired,
  37. };
  38. const PageTwo = ({ myAccount }) => (
  39. <div className='onboarding-modal__page onboarding-modal__page-two'>
  40. <div className='figure non-interactive'>
  41. <div className='pseudo-drawer'>
  42. <NavigationBar account={myAccount} />
  43. </div>
  44. <ComposeForm
  45. text='Awoo! #introductions'
  46. suggestions={ImmutableList()}
  47. mentionedDomains={[]}
  48. spoiler={false}
  49. onChange={noop}
  50. onSubmit={noop}
  51. onPaste={noop}
  52. onPickEmoji={noop}
  53. onChangeSpoilerText={noop}
  54. onClearSuggestions={noop}
  55. onFetchSuggestions={noop}
  56. onSuggestionSelected={noop}
  57. showSearch
  58. />
  59. </div>
  60. <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>
  61. </div>
  62. );
  63. PageTwo.propTypes = {
  64. myAccount: ImmutablePropTypes.map.isRequired,
  65. };
  66. const PageThree = ({ myAccount }) => (
  67. <div className='onboarding-modal__page onboarding-modal__page-three'>
  68. <div className='figure non-interactive'>
  69. <Search
  70. value=''
  71. onChange={noop}
  72. onSubmit={noop}
  73. onClear={noop}
  74. onShow={noop}
  75. />
  76. <div className='pseudo-drawer'>
  77. <NavigationBar account={myAccount} />
  78. </div>
  79. </div>
  80. <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>
  81. <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>
  82. </div>
  83. );
  84. PageThree.propTypes = {
  85. myAccount: ImmutablePropTypes.map.isRequired,
  86. };
  87. const PageFour = ({ domain, intl }) => (
  88. <div className='onboarding-modal__page onboarding-modal__page-four'>
  89. <div className='onboarding-modal__page-four__columns'>
  90. <div className='row'>
  91. <div>
  92. <div className='figure non-interactive'><ColumnHeader icon='home' type={intl.formatMessage(messages.home_title)} /></div>
  93. <p><FormattedMessage id='onboarding.page_four.home' defaultMessage='The home timeline shows posts from people you follow.' /></p>
  94. </div>
  95. <div>
  96. <div className='figure non-interactive'><ColumnHeader icon='bell' type={intl.formatMessage(messages.notifications_title)} /></div>
  97. <p><FormattedMessage id='onboarding.page_four.notifications' defaultMessage='The notifications column shows when someone interacts with you.' /></p>
  98. </div>
  99. </div>
  100. <div className='row'>
  101. <div>
  102. <div className='figure non-interactive' style={{ marginBottom: 0 }}><ColumnHeader icon='users' type={intl.formatMessage(messages.local_title)} /></div>
  103. </div>
  104. <div>
  105. <div className='figure non-interactive' style={{ marginBottom: 0 }}><ColumnHeader icon='globe' type={intl.formatMessage(messages.federated_title)} /></div>
  106. </div>
  107. </div>
  108. <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>
  109. </div>
  110. </div>
  111. );
  112. PageFour.propTypes = {
  113. domain: PropTypes.string.isRequired,
  114. intl: PropTypes.object.isRequired,
  115. };
  116. const PageSix = ({ admin, domain }) => {
  117. let adminSection = '';
  118. if (admin) {
  119. adminSection = (
  120. <p>
  121. <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> }} />
  122. <br />
  123. <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> }} />
  124. </p>
  125. );
  126. }
  127. return (
  128. <div className='onboarding-modal__page onboarding-modal__page-six'>
  129. <h1><FormattedMessage id='onboarding.page_six.almost_done' defaultMessage='Almost done...' /></h1>
  130. {adminSection}
  131. <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>
  132. <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>
  133. <p><em><FormattedMessage id='onboarding.page_six.appetoot' defaultMessage='Bon Appetoot!' /></em></p>
  134. </div>
  135. );
  136. };
  137. PageSix.propTypes = {
  138. admin: ImmutablePropTypes.map,
  139. domain: PropTypes.string.isRequired,
  140. };
  141. const mapStateToProps = state => ({
  142. myAccount: state.getIn(['accounts', me]),
  143. admin: state.getIn(['accounts', state.getIn(['meta', 'admin'])]),
  144. domain: state.getIn(['meta', 'domain']),
  145. });
  146. @connect(mapStateToProps)
  147. @injectIntl
  148. export default class OnboardingModal extends React.PureComponent {
  149. static propTypes = {
  150. onClose: PropTypes.func.isRequired,
  151. intl: PropTypes.object.isRequired,
  152. myAccount: ImmutablePropTypes.map.isRequired,
  153. domain: PropTypes.string.isRequired,
  154. admin: ImmutablePropTypes.map,
  155. };
  156. state = {
  157. currentIndex: 0,
  158. };
  159. componentWillMount() {
  160. const { myAccount, admin, domain, intl } = this.props;
  161. this.pages = [
  162. <PageOne acct={myAccount.get('acct')} domain={domain} />,
  163. <PageTwo myAccount={myAccount} />,
  164. <PageThree myAccount={myAccount} />,
  165. <PageFour domain={domain} intl={intl} />,
  166. <PageSix admin={admin} domain={domain} />,
  167. ];
  168. };
  169. componentDidMount() {
  170. window.addEventListener('keyup', this.handleKeyUp);
  171. }
  172. componentWillUnmount() {
  173. window.addEventListener('keyup', this.handleKeyUp);
  174. }
  175. handleSkip = (e) => {
  176. e.preventDefault();
  177. this.props.onClose();
  178. }
  179. handleDot = (e) => {
  180. const i = Number(e.currentTarget.getAttribute('data-index'));
  181. e.preventDefault();
  182. this.setState({ currentIndex: i });
  183. }
  184. handlePrev = () => {
  185. this.setState(({ currentIndex }) => ({
  186. currentIndex: Math.max(0, currentIndex - 1),
  187. }));
  188. }
  189. handleNext = () => {
  190. const { pages } = this;
  191. this.setState(({ currentIndex }) => ({
  192. currentIndex: Math.min(currentIndex + 1, pages.length - 1),
  193. }));
  194. }
  195. handleSwipe = (index) => {
  196. this.setState({ currentIndex: index });
  197. }
  198. handleKeyUp = ({ key }) => {
  199. switch (key) {
  200. case 'ArrowLeft':
  201. this.handlePrev();
  202. break;
  203. case 'ArrowRight':
  204. this.handleNext();
  205. break;
  206. }
  207. }
  208. handleClose = () => {
  209. this.props.onClose();
  210. }
  211. render () {
  212. const { pages } = this;
  213. const { currentIndex } = this.state;
  214. const hasMore = currentIndex < pages.length - 1;
  215. const nextOrDoneBtn = hasMore ? (
  216. <button
  217. onClick={this.handleNext}
  218. className='onboarding-modal__nav onboarding-modal__next'
  219. >
  220. <FormattedMessage id='onboarding.next' defaultMessage='Next' />
  221. </button>
  222. ) : (
  223. <button
  224. onClick={this.handleClose}
  225. className='onboarding-modal__nav onboarding-modal__done'
  226. >
  227. <FormattedMessage id='onboarding.done' defaultMessage='Done' />
  228. </button>
  229. );
  230. return (
  231. <div className='modal-root__modal onboarding-modal'>
  232. <ReactSwipeableViews index={currentIndex} onChangeIndex={this.handleSwipe} className='onboarding-modal__pager'>
  233. {pages.map((page, i) => {
  234. const className = classNames('onboarding-modal__page__wrapper', {
  235. 'onboarding-modal__page__wrapper--active': i === currentIndex,
  236. });
  237. return (
  238. <div key={i} className={className}>{page}</div>
  239. );
  240. })}
  241. </ReactSwipeableViews>
  242. <div className='onboarding-modal__paginator'>
  243. <div>
  244. <button
  245. onClick={this.handleSkip}
  246. className='onboarding-modal__nav onboarding-modal__skip'
  247. >
  248. <FormattedMessage id='onboarding.skip' defaultMessage='Skip' />
  249. </button>
  250. </div>
  251. <div className='onboarding-modal__dots'>
  252. {pages.map((_, i) => {
  253. const className = classNames('onboarding-modal__dot', {
  254. active: i === currentIndex,
  255. });
  256. return (
  257. <div
  258. key={`dot-${i}`}
  259. role='button'
  260. tabIndex='0'
  261. data-index={i}
  262. onClick={this.handleDot}
  263. className={className}
  264. />
  265. );
  266. })}
  267. </div>
  268. <div>
  269. {nextOrDoneBtn}
  270. </div>
  271. </div>
  272. </div>
  273. );
  274. }
  275. }