2023-04-23 22:24:53 +02:00
import PropTypes from 'prop-types' ;
2023-12-02 19:21:43 +01:00
import { PureComponent } from 'react' ;
2023-05-31 23:43:39 +02:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2023-12-02 19:21:43 +01:00
2023-04-23 22:24:53 +02:00
import classNames from 'classnames' ;
import { Link } from 'react-router-dom' ;
2023-12-02 19:21:43 +01:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import { connect } from 'react-redux' ;
2023-10-24 19:45:08 +02:00
import { ReactComponent as ArrowRightAltIcon } from '@material-symbols/svg-600/outlined/arrow_right_alt.svg' ;
import { ReactComponent as ContentCopyIcon } from '@material-symbols/svg-600/outlined/content_copy.svg' ;
2023-04-25 11:12:37 +02:00
import SwipeableViews from 'react-swipeable-views' ;
2023-04-23 22:24:53 +02:00
2023-12-02 19:21:43 +01:00
import Column from 'flavours/glitch/components/column' ;
2023-10-26 13:00:10 +02:00
import { ColumnBackButton } from 'flavours/glitch/components/column_back_button' ;
2023-12-09 20:26:57 +01:00
import { Icon } from 'flavours/glitch/components/icon' ;
2023-12-02 19:21:43 +01:00
import { me , domain } from 'flavours/glitch/initial_state' ;
2023-04-23 22:24:53 +02:00
const messages = defineMessages ( {
2023-04-25 11:12:37 +02:00
shareableMessage : { id : 'onboarding.share.message' , defaultMessage : 'I\'m {username} on #Mastodon! Come follow me at {url}' } ,
2023-04-23 22:24:53 +02:00
} ) ;
const mapStateToProps = state => ( {
account : state . getIn ( [ 'accounts' , me ] ) ,
} ) ;
2023-05-23 10:52:27 +02:00
class CopyPasteText extends PureComponent {
2023-04-23 22:24:53 +02:00
static propTypes = {
value : PropTypes . string ,
} ;
state = {
copied : false ,
focused : false ,
} ;
setRef = c => {
this . input = c ;
} ;
handleInputClick = ( ) => {
this . setState ( { copied : false } ) ;
this . input . focus ( ) ;
this . input . select ( ) ;
this . input . setSelectionRange ( 0 , this . props . value . length ) ;
} ;
handleButtonClick = e => {
e . stopPropagation ( ) ;
const { value } = this . props ;
navigator . clipboard . writeText ( value ) ;
this . input . blur ( ) ;
this . setState ( { copied : true } ) ;
this . timeout = setTimeout ( ( ) => this . setState ( { copied : false } ) , 700 ) ;
} ;
handleFocus = ( ) => {
this . setState ( { focused : true } ) ;
} ;
handleBlur = ( ) => {
this . setState ( { focused : false } ) ;
} ;
componentWillUnmount ( ) {
if ( this . timeout ) clearTimeout ( this . timeout ) ;
}
render ( ) {
const { value } = this . props ;
const { copied , focused } = this . state ;
return (
< div className = { classNames ( 'copy-paste-text' , { copied , focused } ) } tabIndex = '0' role = 'button' onClick = { this . handleInputClick } >
< textarea readOnly value = { value } ref = { this . setRef } onClick = { this . handleInputClick } onFocus = { this . handleFocus } onBlur = { this . handleBlur } / >
< button className = 'button' onClick = { this . handleButtonClick } >
2023-10-24 19:45:08 +02:00
< Icon id = 'copy' icon = { ContentCopyIcon } / > { copied ? < FormattedMessage id = 'copypaste.copied' defaultMessage = 'Copied' / > : < FormattedMessage id = 'copypaste.copy_to_clipboard' defaultMessage = 'Copy to clipboard' / > }
2023-04-23 22:24:53 +02:00
< / button >
< / div >
) ;
}
}
2023-05-23 10:52:27 +02:00
class TipCarousel extends PureComponent {
2023-04-25 11:12:37 +02: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-05-23 10:52:27 +02:00
class Share extends PureComponent {
2023-04-23 22:24:53 +02:00
static propTypes = {
onBack : PropTypes . func ,
2023-11-03 16:00:03 +01:00
account : ImmutablePropTypes . record ,
2023-04-23 22:24:53 +02:00
intl : PropTypes . object ,
} ;
render ( ) {
2023-10-26 13:00:10 +02:00
const { onBack , account , intl } = this . props ;
2023-04-23 22:24:53 +02:00
const url = ( new URL ( ` /@ ${ account . get ( 'username' ) } ` , document . baseURI ) ) . href ;
return (
< Column >
2023-10-26 13:00:10 +02:00
< ColumnBackButton onClick = { onBack } / >
2023-04-23 22:24:53 +02: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 >
< CopyPasteText value = { intl . formatMessage ( messages . shareableMessage , { username : ` @ ${ account . get ( 'username' ) } @ ${ domain } ` , url } ) } / >
2023-04-25 11:12:37 +02:00
< TipCarousel >
2023-05-31 23:43:39 +02:00
< 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 >
2023-04-25 11:12:37 +02:00
< / TipCarousel >
2023-04-23 22:24:53 +02: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' >
2023-06-23 16:34:27 +02:00
< FormattedMessage id = 'onboarding.actions.go_to_home' defaultMessage = 'Take me to my home feed' / >
2023-10-24 19:45:08 +02:00
< Icon icon = { ArrowRightAltIcon } / >
2023-04-23 22:24:53 +02:00
< / Link >
< Link to = '/explore' className = 'onboarding__link' >
2023-06-23 16:34:27 +02:00
< FormattedMessage id = 'onboarding.actions.go_to_explore' defaultMessage = 'Take me to trending' / >
2023-10-24 19:45:08 +02:00
< Icon icon = { ArrowRightAltIcon } / >
2023-04-23 22:24:53 +02:00
< / Link >
< / div >
< div className = 'onboarding__footer' >
< button className = 'link-button' onClick = { onBack } > < FormattedMessage id = 'onboarding.action.back' defaultMessage = 'Take me back' / > < / button >
< / div >
< / div >
< / Column >
) ;
}
}
2023-05-09 03:11:56 +02:00
export default connect ( mapStateToProps ) ( injectIntl ( Share ) ) ;