@ -12,6 +12,7 @@ import Card from './card';
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import Video from 'flavours/glitch/features/video' ;
import Video from 'flavours/glitch/features/video' ;
import VisibilityIcon from 'flavours/glitch/components/status_visibility_icon' ;
import VisibilityIcon from 'flavours/glitch/components/status_visibility_icon' ;
import scheduleIdleTask from 'flavours/glitch/util/schedule_idle_task' ;
export default class DetailedStatus extends ImmutablePureComponent {
export default class DetailedStatus extends ImmutablePureComponent {
@ -26,10 +27,17 @@ export default class DetailedStatus extends ImmutablePureComponent {
onOpenVideo : PropTypes . func . isRequired ,
onOpenVideo : PropTypes . func . isRequired ,
onToggleHidden : PropTypes . func . isRequired ,
onToggleHidden : PropTypes . func . isRequired ,
expanded : PropTypes . bool ,
expanded : PropTypes . bool ,
measureHeight : PropTypes . bool ,
onHeightChange : PropTypes . func ,
domain : PropTypes . string . isRequired ,
} ;
state = {
height : null ,
} ;
} ;
handleAccountClick = ( e ) => {
handleAccountClick = ( e ) => {
if ( e . button === 0 && ! ( e . ctrlKey || e . altKey || e . metaKey ) ) {
if ( e . button === 0 && ! ( e . ctrlKey || e . altKey || e . metaKey ) && this . context . router ) {
e . preventDefault ( ) ;
e . preventDefault ( ) ;
this . context . router . history . push ( ` /accounts/ ${ this . props . status . getIn ( [ 'account' , 'id' ] ) } ` ) ;
this . context . router . history . push ( ` /accounts/ ${ this . props . status . getIn ( [ 'account' , 'id' ] ) } ` ) ;
}
}
@ -38,7 +46,7 @@ export default class DetailedStatus extends ImmutablePureComponent {
}
}
parseClick = ( e , destination ) => {
parseClick = ( e , destination ) => {
if ( e . button === 0 && ! ( e . ctrlKey || e . altKey || e . metaKey ) ) {
if ( e . button === 0 && ! ( e . ctrlKey || e . altKey || e . metaKey ) && this . context . router ) {
e . preventDefault ( ) ;
e . preventDefault ( ) ;
this . context . router . history . push ( destination ) ;
this . context . router . history . push ( destination ) ;
}
}
@ -50,15 +58,58 @@ export default class DetailedStatus extends ImmutablePureComponent {
this . props . onOpenVideo ( media , startTime ) ;
this . props . onOpenVideo ( media , startTime ) ;
}
}
_measureHeight ( heightJustChanged ) {
if ( this . props . measureHeight && this . node ) {
scheduleIdleTask ( ( ) => this . node && this . setState ( { height : this . node . offsetHeight } ) ) ;
if ( this . props . onHeightChange && heightJustChanged ) {
this . props . onHeightChange ( ) ;
}
}
}
setRef = c => {
this . node = c ;
this . _measureHeight ( ) ;
}
componentDidUpdate ( prevProps , prevState ) {
this . _measureHeight ( prevState . height !== this . state . height ) ;
}
handleModalLink = e => {
e . preventDefault ( ) ;
let href ;
if ( e . target . nodeName !== 'A' ) {
href = e . target . parentNode . href ;
} else {
href = e . target . href ;
}
window . open ( href , 'mastodon-intent' , 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes' ) ;
}
render ( ) {
render ( ) {
const status = this . props . status . get ( 'reblog' ) ? this . props . status . get ( 'reblog' ) : this . props . status ;
const status = this . props . status . get ( 'reblog' ) ? this . props . status . get ( 'reblog' ) : this . props . status ;
const { expanded , onToggleHidden , settings } = this . props ;
const { expanded , onToggleHidden , settings } = this . props ;
const outerStyle = { boxSizing : 'border-box' } ;
if ( ! status ) {
return null ;
}
let media = '' ;
let media = '' ;
let mediaIcon = null ;
let mediaIcon = null ;
let applicationLink = '' ;
let applicationLink = '' ;
let reblogLink = '' ;
let reblogLink = '' ;
let reblogIcon = 'retweet' ;
let reblogIcon = 'retweet' ;
let favouriteLink = '' ;
if ( this . props . measureHeight ) {
outerStyle . height = ` ${ this . state . height } px ` ;
}
if ( status . get ( 'media_attachments' ) . size > 0 ) {
if ( status . get ( 'media_attachments' ) . size > 0 ) {
if ( status . get ( 'media_attachments' ) . some ( item => item . get ( 'type' ) === 'unknown' ) ) {
if ( status . get ( 'media_attachments' ) . some ( item => item . get ( 'type' ) === 'unknown' ) ) {
@ -108,20 +159,51 @@ export default class DetailedStatus extends ImmutablePureComponent {
if ( status . get ( 'visibility' ) === 'private' ) {
if ( status . get ( 'visibility' ) === 'private' ) {
reblogLink = < i className = { ` fa fa- ${ reblogIcon } ` } / > ;
reblogLink = < i className = { ` fa fa- ${ reblogIcon } ` } / > ;
} else if ( this . context . router ) {
reblogLink = (
< Link to = { ` /statuses/ ${ status . get ( 'id' ) } /reblogs ` } className = 'detailed-status__link' >
< i className = { ` fa fa- ${ reblogIcon } ` } / >
< span className = 'detailed-status__reblogs' >
< FormattedNumber value = { status . get ( 'reblogs_count' ) } / >
< / s p a n >
< / L i n k >
) ;
} else {
reblogLink = (
< a href = { ` /interact/ ${ status . get ( 'id' ) } ?type=reblog ` } className = 'detailed-status__link' onClick = { this . handleModalLink } >
< i className = { ` fa fa- ${ reblogIcon } ` } / >
< span className = 'detailed-status__reblogs' >
< FormattedNumber value = { status . get ( 'reblogs_count' ) } / >
< / s p a n >
< / a >
) ;
}
if ( this . context . router ) {
favouriteLink = (
< Link to = { ` /statuses/ ${ status . get ( 'id' ) } /favourites ` } className = 'detailed-status__link' >
< i className = 'fa fa-star' / >
< span className = 'detailed-status__favorites' >
< FormattedNumber value = { status . get ( 'favourites_count' ) } / >
< / s p a n >
< / L i n k >
) ;
} else {
} else {
reblogLink = ( < Link to = { ` /statuses/ ${ status . get ( 'id' ) } /reblogs ` } className = 'detailed-status__link' >
< i className = { ` fa fa- ${ reblogIcon } ` } / >
< span className = 'detailed-status__reblogs' >
< FormattedNumber value = { status . get ( 'reblogs_count' ) } / >
< / s p a n >
< / L i n k > ) ;
favouriteLink = (
< a href = { ` /interact/ ${ status . get ( 'id' ) } ?type=favourite ` } className = 'detailed-status__link' onClick = { this . handleModalLink } >
< i className = 'fa fa-star' / >
< span className = 'detailed-status__favorites' >
< FormattedNumber value = { status . get ( 'favourites_count' ) } / >
< / s p a n >
< / a >
) ;
}
}
return (
return (
< div className = 'detailed-status' data - status - by = { status . getIn ( [ 'account' , 'acct' ] ) } >
< div ref = { this . setRef } className= 'detailed-status' data - status - by = { status . getIn ( [ 'account' , 'acct' ] ) } style = { outerStyle } >
< a href = { status . getIn ( [ 'account' , 'url' ] ) } onClick = { this . handleAccountClick } className = 'detailed-status__display-name' >
< a href = { status . getIn ( [ 'account' , 'url' ] ) } onClick = { this . handleAccountClick } className = 'detailed-status__display-name' >
< div className = 'detailed-status__display-avatar' > < Avatar account = { status . get ( 'account' ) } size = { 48 } / > < / d i v >
< div className = 'detailed-status__display-avatar' > < Avatar account = { status . get ( 'account' ) } size = { 48 } / > < / d i v >
< DisplayName account = { status . get ( 'account' ) } / >
< DisplayName account = { status . get ( 'account' ) } localDomain = { this . props . domain } / >
< / a >
< / a >
< StatusContent
< StatusContent
@ -137,12 +219,7 @@ export default class DetailedStatus extends ImmutablePureComponent {
< div className = 'detailed-status__meta' >
< div className = 'detailed-status__meta' >
< a className = 'detailed-status__datetime' href = { status . get ( 'url' ) } target = '_blank' rel = 'noopener' >
< a className = 'detailed-status__datetime' href = { status . get ( 'url' ) } target = '_blank' rel = 'noopener' >
< FormattedDate value = { new Date ( status . get ( 'created_at' ) ) } hour12 = { false } year = 'numeric' month = 'short' day = '2-digit' hour = '2-digit' minute = '2-digit' / >
< FormattedDate value = { new Date ( status . get ( 'created_at' ) ) } hour12 = { false } year = 'numeric' month = 'short' day = '2-digit' hour = '2-digit' minute = '2-digit' / >
< / a > { a p p l i c a t i o n L i n k } · { r e b l o g L i n k } · < L i n k t o = { ` / s t a t u s e s / $ { s t a t u s . g e t ( ' i d ' ) } / f a v o u r i t e s ` } c l a s s N a m e = ' d e t a i l e d - s t a t u s _ _ l i n k ' >
< i className = 'fa fa-star' / >
< span className = 'detailed-status__favorites' >
< FormattedNumber value = { status . get ( 'favourites_count' ) } / >
< / s p a n >
< /Link> · <VisibilityIcon visibility={status.get('visibility')} / >
< /a>{applicationLink} · {reblogLink} · {favouriteLink} · <VisibilityIcon visibility={status.get('visibility')} / >
< / d i v >
< / d i v >
< / d i v >
< / d i v >
) ;
) ;