2023-04-24 05:24:53 +09:00
import PropTypes from 'prop-types' ;
2023-12-03 03:21:43 +09:00
import { PureComponent } from 'react' ;
2023-11-15 20:13:53 +09:00
import { defineMessages , useIntl , FormattedMessage } from 'react-intl' ;
2023-12-03 03:21:43 +09:00
2023-04-24 05:24:53 +09:00
import classNames from 'classnames' ;
import { Link } from 'react-router-dom' ;
2023-12-03 03:21:43 +09:00
2023-04-25 18:12:37 +09:00
import SwipeableViews from 'react-swipeable-views' ;
2023-04-24 05:24:53 +09:00
2024-01-16 19:27:26 +09:00
import ArrowRightAltIcon from '@/material-icons/400-24px/arrow_right_alt.svg?react' ;
2023-10-26 20:00:10 +09:00
import { ColumnBackButton } from 'flavours/glitch/components/column_back_button' ;
2024-09-12 21:54:16 +09:00
import { CopyPasteText } from 'flavours/glitch/components/copy_paste_text' ;
2023-12-10 04:26:57 +09:00
import { Icon } from 'flavours/glitch/components/icon' ;
2023-12-03 03:21:43 +09:00
import { me , domain } from 'flavours/glitch/initial_state' ;
2023-11-15 20:13:53 +09:00
import { useAppSelector } from 'flavours/glitch/store' ;
2023-12-03 03:21:43 +09:00
2023-04-24 05:24:53 +09:00
const messages = defineMessages ( {
2023-04-25 18:12:37 +09:00
shareableMessage : { id : 'onboarding.share.message' , defaultMessage : 'I\'m {username} on #Mastodon! Come follow me at {url}' } ,
2023-04-24 05:24:53 +09:00
} ) ;
2023-05-23 17:52:27 +09:00
class TipCarousel extends PureComponent {
2023-04-25 18:12:37 +09:00
static propTypes = {
children : PropTypes . node ,
} ;
state = {
index : 0 ,
} ;
handleSwipe = index => {
this . setState ( { index } ) ;
} ;
handleChangeIndex = e => {
this . setState ( { index : Number ( e . currentTarget . getAttribute ( 'data-index' ) ) } ) ;
} ;
handleKeyDown = e => {
switch ( e . key ) {
case 'ArrowLeft' :
e . preventDefault ( ) ;
this . setState ( ( { index } , { children } ) => ( { index : Math . abs ( index - 1 ) % children . length } ) ) ;
break ;
case 'ArrowRight' :
e . preventDefault ( ) ;
this . setState ( ( { index } , { children } ) => ( { index : ( index + 1 ) % children . length } ) ) ;
break ;
}
} ;
render ( ) {
const { children } = this . props ;
const { index } = this . state ;
return (
< div className = 'tip-carousel' tabIndex = '0' onKeyDown = { this . handleKeyDown } >
< SwipeableViews onChangeIndex = { this . handleSwipe } index = { index } enableMouseEvents tabIndex = '-1' >
{ children }
< / SwipeableViews >
< div className = 'media-modal__pagination' >
{ children . map ( ( _ , i ) => (
< button key = { i } className = { classNames ( 'media-modal__page-dot' , { active : i === index } ) } data - index = { i } onClick = { this . handleChangeIndex } >
{ i + 1 }
< / button >
) ) }
< / div >
< / div >
) ;
}
}
2023-11-15 20:13:53 +09:00
export const Share = ( ) => {
const account = useAppSelector ( state => state . getIn ( [ 'accounts' , me ] ) ) ;
const intl = useIntl ( ) ;
const url = ( new URL ( ` /@ ${ account . get ( 'username' ) } ` , document . baseURI ) ) . href ;
2023-04-24 05:24:53 +09:00
2023-11-15 20:13:53 +09:00
return (
< >
< ColumnBackButton / >
2023-04-24 05:24:53 +09:00
2023-11-15 20:13:53 +09:00
< div className = 'scrollable privacy-policy' >
< div className = 'column-title' >
< h3 > < FormattedMessage id = 'onboarding.share.title' defaultMessage = 'Share your profile' / > < / h3 >
< p > < FormattedMessage id = 'onboarding.share.lead' defaultMessage = 'Let people know how they can find you on Mastodon!' / > < / p >
< / div >
2023-04-24 05:24:53 +09:00
2023-11-15 20:13:53 +09:00
< CopyPasteText value = { intl . formatMessage ( messages . shareableMessage , { username : ` @ ${ account . get ( 'username' ) } @ ${ domain } ` , url } ) } / >
2023-04-24 05:24:53 +09:00
2023-11-15 20:13:53 +09:00
< TipCarousel >
< div > < p className = 'onboarding__lead' > < FormattedMessage id = 'onboarding.tips.verification' defaultMessage = '<strong>Did you know?</strong> You can verify your account by putting a link to your Mastodon profile on your own website and adding the website to your profile. No fees or documents necessary!' values = { { strong : chunks => < strong > { chunks } < / strong > } } / > < / p > < / div >
< div > < p className = 'onboarding__lead' > < FormattedMessage id = 'onboarding.tips.migration' defaultMessage = '<strong>Did you know?</strong> If you feel like {domain} is not a great server choice for you in the future, you can move to another Mastodon server without losing your followers. You can even host your own server!' values = { { domain , strong : chunks => < strong > { chunks } < / strong > } } / > < / p > < / div >
< div > < p className = 'onboarding__lead' > < FormattedMessage id = 'onboarding.tips.2fa' defaultMessage = '<strong>Did you know?</strong> You can secure your account by setting up two-factor authentication in your account settings. It works with any TOTP app of your choice, no phone number necessary!' values = { { strong : chunks => < strong > { chunks } < / strong > } } / > < / p > < / div >
< / TipCarousel >
2023-04-24 05:24:53 +09:00
2023-11-15 20:13:53 +09:00
< p className = 'onboarding__lead' > < FormattedMessage id = 'onboarding.share.next_steps' defaultMessage = 'Possible next steps:' / > < / p >
< div className = 'onboarding__links' >
< Link to = '/home' className = 'onboarding__link' >
< FormattedMessage id = 'onboarding.actions.go_to_home' defaultMessage = 'Take me to my home feed' / >
< Icon icon = { ArrowRightAltIcon } / >
< / Link >
2023-04-24 05:24:53 +09:00
2023-11-15 20:13:53 +09:00
< Link to = '/explore' className = 'onboarding__link' >
< FormattedMessage id = 'onboarding.actions.go_to_explore' defaultMessage = 'Take me to trending' / >
< Icon icon = { ArrowRightAltIcon } / >
< / Link >
< / div >
< div className = 'onboarding__footer' >
< Link className = 'link-button' to = '/start' > < FormattedMessage id = 'onboarding.action.back' defaultMessage = 'Take me back' / > < / Link >
< / div >
< / div >
< / >
) ;
} ;