2017-04-21 20:05:35 +02:00
import PropTypes from 'prop-types' ;
2023-05-28 16:38:10 +02:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
import { Helmet } from 'react-helmet' ;
2016-11-16 17:20:52 +01:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2023-05-28 16:38:10 +02:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import { connect } from 'react-redux' ;
2024-01-12 11:31:24 +01:00
import RefreshIcon from '@material-symbols/svg-600/outlined/refresh.svg?react' ;
import RepeatIcon from '@material-symbols/svg-600/outlined/repeat.svg?react' ;
2023-08-29 14:42:20 +02:00
import { debounce } from 'lodash' ;
2023-11-15 12:01:51 +01:00
import { Icon } from 'flavours/glitch/components/icon' ;
import { fetchReblogs , expandReblogs } from '../../actions/interactions' ;
import ColumnHeader from '../../components/column_header' ;
import { LoadingIndicator } from '../../components/loading_indicator' ;
import ScrollableList from '../../components/scrollable_list' ;
import AccountContainer from '../../containers/account_container' ;
import Column from '../ui/components/column' ;
2023-05-28 16:38:10 +02:00
2019-04-08 17:56:25 +02:00
const messages = defineMessages ( {
heading : { id : 'column.reblogged_by' , defaultMessage : 'Boosted by' } ,
2019-10-01 04:57:27 +02:00
refresh : { id : 'refresh' , defaultMessage : 'Refresh' } ,
2019-04-08 17:56:25 +02:00
} ) ;
2016-11-03 20:16:14 +01:00
const mapStateToProps = ( state , props ) => ( {
2023-08-29 14:42:20 +02:00
accountIds : state . getIn ( [ 'user_lists' , 'reblogged_by' , props . params . statusId , 'items' ] ) ,
hasMore : ! ! state . getIn ( [ 'user_lists' , 'reblogged_by' , props . params . statusId , 'next' ] ) ,
isLoading : state . getIn ( [ 'user_lists' , 'reblogged_by' , props . params . statusId , 'isLoading' ] , true ) ,
2016-11-03 20:16:14 +01:00
} ) ;
2019-09-09 15:16:08 +02:00
class Reblogs extends ImmutablePureComponent {
2016-11-03 20:16:14 +01:00
2017-05-12 14:44:10 +02:00
static propTypes = {
params : PropTypes . object . isRequired ,
dispatch : PropTypes . func . isRequired ,
2017-05-20 17:31:47 +02:00
accountIds : ImmutablePropTypes . list ,
2023-08-29 14:42:20 +02:00
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
2019-07-19 09:25:22 +02:00
multiColumn : PropTypes . bool ,
2019-04-08 17:56:25 +02:00
intl : PropTypes . object . isRequired ,
2017-05-12 14:44:10 +02:00
} ;
2023-05-10 09:05:32 +02:00
UNSAFE _componentWillMount ( ) {
2019-09-29 16:27:00 +02:00
if ( ! this . props . accountIds ) {
this . props . dispatch ( fetchReblogs ( this . props . params . statusId ) ) ;
}
2017-04-21 20:05:35 +02:00
}
2016-11-03 20:16:14 +01:00
2019-04-08 17:56:25 +02:00
handleHeaderClick = ( ) => {
this . column . scrollTop ( ) ;
2023-02-03 20:52:07 +01:00
} ;
2019-04-08 17:56:25 +02:00
setRef = c => {
this . column = c ;
2023-02-03 20:52:07 +01:00
} ;
2019-04-08 17:56:25 +02:00
2019-10-01 04:57:27 +02:00
handleRefresh = ( ) => {
this . props . dispatch ( fetchReblogs ( this . props . params . statusId ) ) ;
2023-02-03 20:52:07 +01:00
} ;
2019-10-01 04:57:27 +02:00
2023-08-29 14:42:20 +02:00
handleLoadMore = debounce ( ( ) => {
this . props . dispatch ( expandReblogs ( this . props . params . statusId ) ) ;
} , 300 , { leading : true } ) ;
2016-11-03 20:16:14 +01:00
render ( ) {
2023-08-29 14:42:20 +02:00
const { intl , accountIds , hasMore , isLoading , multiColumn } = this . props ;
2016-11-03 20:16:14 +01:00
if ( ! accountIds ) {
return (
< Column >
< LoadingIndicator / >
< / Column >
) ;
}
2022-05-03 10:59:23 +02:00
const emptyMessage = < FormattedMessage id = 'status.reblogs.empty' defaultMessage = 'No one has boosted this post yet. When someone does, they will show up here.' / > ;
2018-08-26 16:39:37 +02:00
2016-11-03 20:16:14 +01:00
return (
2019-04-08 17:56:25 +02:00
< Column ref = { this . setRef } >
< ColumnHeader
icon = 'retweet'
2023-10-24 19:45:08 +02:00
iconComponent = { RepeatIcon }
2019-04-08 17:56:25 +02:00
title = { intl . formatMessage ( messages . heading ) }
onClick = { this . handleHeaderClick }
showBackButton
2019-08-01 19:17:17 +02:00
multiColumn = { multiColumn }
2019-10-01 04:57:27 +02:00
extraButton = { (
2023-10-24 19:45:08 +02:00
< button type = 'button' className = 'column-header__button' title = { intl . formatMessage ( messages . refresh ) } aria - label = { intl . formatMessage ( messages . refresh ) } onClick = { this . handleRefresh } > < Icon id = 'refresh' icon = { RefreshIcon } / > < / button >
2019-10-01 04:57:27 +02:00
) }
2019-04-08 17:56:25 +02:00
/ >
2016-11-03 20:16:14 +01:00
2018-08-26 16:39:37 +02:00
< ScrollableList
scrollKey = 'reblogs'
2023-08-29 14:42:20 +02:00
onLoadMore = { this . handleLoadMore }
hasMore = { hasMore }
isLoading = { isLoading }
2018-08-26 16:39:37 +02:00
emptyMessage = { emptyMessage }
2019-07-19 09:25:22 +02:00
bindToDocument = { ! multiColumn }
2018-08-26 16:39:37 +02:00
>
{ accountIds . map ( id =>
2020-03-08 16:02:36 +01:00
< AccountContainer key = { id } id = { id } withNote = { false } / > ,
2018-08-26 16:39:37 +02:00
) }
< / ScrollableList >
2022-10-20 14:35:29 +02:00
< Helmet >
< meta name = 'robots' content = 'noindex' / >
< / Helmet >
2016-11-03 20:16:14 +01:00
< / Column >
) ;
}
2017-04-21 20:05:35 +02:00
}
2023-03-24 23:15:25 +01:00
export default connect ( mapStateToProps ) ( injectIntl ( Reblogs ) ) ;