2017-05-03 00:04:16 +00:00
import React from 'react' ;
2017-01-30 20:40:55 +00:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2017-04-21 18:05:35 +00:00
import PropTypes from 'prop-types' ;
2017-12-04 07:26:40 +00:00
import InnerHeader from 'flavours/glitch/features/account/components/header' ;
import ActionBar from 'flavours/glitch/features/account/components/action_bar' ;
import MissingIndicator from 'flavours/glitch/components/missing_indicator' ;
2017-05-03 00:04:16 +00:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2018-03-16 18:54:00 +00:00
import { FormattedMessage } from 'react-intl' ;
import { NavLink } from 'react-router-dom' ;
2018-03-29 12:43:20 +00:00
import MovedNote from './moved_note' ;
2017-01-30 20:40:55 +00:00
2017-06-23 17:36:54 +00:00
export default class Header extends ImmutablePureComponent {
2017-01-30 20:40:55 +00:00
2017-05-12 12:44:10 +00:00
static propTypes = {
account : ImmutablePropTypes . map ,
onFollow : PropTypes . func . isRequired ,
onBlock : PropTypes . func . isRequired ,
onMention : PropTypes . func . isRequired ,
2018-03-29 19:13:47 +00:00
onDirect : PropTypes . func . isRequired ,
2017-11-09 14:41:10 +00:00
onReblogToggle : PropTypes . func . isRequired ,
2017-05-12 12:44:10 +00:00
onReport : PropTypes . func . isRequired ,
2017-05-19 19:05:32 +00:00
onMute : PropTypes . func . isRequired ,
onBlockDomain : PropTypes . func . isRequired ,
onUnblockDomain : PropTypes . func . isRequired ,
2018-08-10 14:25:46 +00:00
onEndorseToggle : PropTypes . func . isRequired ,
2018-03-16 19:29:42 +00:00
hideTabs : PropTypes . bool ,
2017-05-12 12:44:10 +00:00
} ;
static contextTypes = {
2017-05-20 15:31:47 +00:00
router : PropTypes . object ,
2017-05-12 12:44:10 +00:00
} ;
2017-01-30 20:40:55 +00:00
2017-05-12 12:44:10 +00:00
handleFollow = ( ) => {
2017-01-30 20:40:55 +00:00
this . props . onFollow ( this . props . account ) ;
2017-04-21 18:05:35 +00:00
}
2017-01-30 20:40:55 +00:00
2017-05-12 12:44:10 +00:00
handleBlock = ( ) => {
2017-01-30 20:40:55 +00:00
this . props . onBlock ( this . props . account ) ;
2017-04-21 18:05:35 +00:00
}
2017-01-30 20:40:55 +00:00
2017-05-12 12:44:10 +00:00
handleMention = ( ) => {
2017-06-20 18:40:03 +00:00
this . props . onMention ( this . props . account , this . context . router . history ) ;
2017-04-21 18:05:35 +00:00
}
2017-01-30 20:40:55 +00:00
2018-03-29 19:13:47 +00:00
handleDirect = ( ) => {
this . props . onDirect ( this . props . account , this . context . router . history ) ;
}
2017-05-12 12:44:10 +00:00
handleReport = ( ) => {
2017-02-14 19:59:26 +00:00
this . props . onReport ( this . props . account ) ;
2017-04-21 18:05:35 +00:00
}
2017-02-14 19:59:26 +00:00
2017-11-09 14:41:10 +00:00
handleReblogToggle = ( ) => {
this . props . onReblogToggle ( this . props . account ) ;
}
2017-05-12 12:44:10 +00:00
handleMute = ( ) => {
2017-02-06 01:51:56 +00:00
this . props . onMute ( this . props . account ) ;
2017-04-21 18:05:35 +00:00
}
2017-02-06 01:51:56 +00:00
2017-05-19 19:05:32 +00:00
handleBlockDomain = ( ) => {
const domain = this . props . account . get ( 'acct' ) . split ( '@' ) [ 1 ] ;
if ( ! domain ) return ;
2018-03-04 22:38:00 +00:00
this . props . onBlockDomain ( domain ) ;
2017-05-19 19:05:32 +00:00
}
handleUnblockDomain = ( ) => {
const domain = this . props . account . get ( 'acct' ) . split ( '@' ) [ 1 ] ;
if ( ! domain ) return ;
2018-03-04 22:38:00 +00:00
this . props . onUnblockDomain ( domain ) ;
2017-05-19 19:05:32 +00:00
}
2018-08-10 14:25:46 +00:00
handleEndorseToggle = ( ) => {
this . props . onEndorseToggle ( this . props . account ) ;
}
2017-01-30 20:40:55 +00:00
render ( ) {
2018-03-16 19:29:42 +00:00
const { account , hideTabs } = this . props ;
2017-01-30 20:40:55 +00:00
2017-02-26 22:06:27 +00:00
if ( account === null ) {
return < MissingIndicator / > ;
2017-01-30 20:40:55 +00:00
}
return (
2017-04-23 02:26:55 +00:00
< div className = 'account-timeline__header' >
2018-03-29 12:43:20 +00:00
{ account . get ( 'moved' ) && < MovedNote from = { account } to = { account . get ( 'moved' ) } / > }
2017-01-30 20:40:55 +00:00
< InnerHeader
account = { account }
onFollow = { this . handleFollow }
2018-03-05 10:09:29 +00:00
onBlock = { this . handleBlock }
2017-01-30 20:40:55 +00:00
/ >
< ActionBar
account = { account }
onBlock = { this . handleBlock }
onMention = { this . handleMention }
2018-03-29 19:13:47 +00:00
onDirect = { this . handleDirect }
2017-11-09 14:41:10 +00:00
onReblogToggle = { this . handleReblogToggle }
2017-02-14 19:59:26 +00:00
onReport = { this . handleReport }
2017-02-06 01:51:56 +00:00
onMute = { this . handleMute }
2017-05-19 19:05:32 +00:00
onBlockDomain = { this . handleBlockDomain }
onUnblockDomain = { this . handleUnblockDomain }
2018-08-10 14:25:46 +00:00
onEndorseToggle = { this . handleEndorseToggle }
2017-01-30 20:40:55 +00:00
/ >
2018-03-16 18:54:00 +00:00
2018-03-16 19:29:42 +00:00
{ ! hideTabs && (
< div className = 'account__section-headline' >
< NavLink exact to = { ` /accounts/ ${ account . get ( 'id' ) } ` } > < FormattedMessage id = 'account.posts' defaultMessage = 'Toots' / > < / N a v L i n k >
< NavLink exact to = { ` /accounts/ ${ account . get ( 'id' ) } /with_replies ` } > < FormattedMessage id = 'account.posts_with_replies' defaultMessage = 'Toots with replies' / > < / N a v L i n k >
< NavLink exact to = { ` /accounts/ ${ account . get ( 'id' ) } /media ` } > < FormattedMessage id = 'account.media' defaultMessage = 'Media' / > < / N a v L i n k >
< / d i v >
) }
2017-01-30 20:40:55 +00:00
< / d i v >
) ;
}
2017-04-21 18:05:35 +00:00
2017-05-12 12:44:10 +00:00
}