2022-10-09 12:55:09 +11:00
import PropTypes from 'prop-types' ;
2023-05-24 01:15:17 +10:00
2019-10-01 12:57:27 +10:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2023-05-24 01:15:17 +10:00
import { Helmet } from 'react-helmet' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2022-10-09 12:55:09 +11:00
import { connect } from 'react-redux' ;
2023-05-24 01:15:17 +10:00
2023-10-25 04:45:08 +11:00
import { ReactComponent as RefreshIcon } from '@material-symbols/svg-600/outlined/refresh.svg' ;
2023-08-29 18:56:19 +10:00
import { debounce } from 'lodash' ;
import { fetchFavourites , expandFavourites } from 'mastodon/actions/interactions' ;
2022-10-09 12:55:09 +11:00
import ColumnHeader from 'mastodon/components/column_header' ;
2023-05-09 11:11:56 +10:00
import { Icon } from 'mastodon/components/icon' ;
2023-06-14 03:26:25 +10:00
import { LoadingIndicator } from 'mastodon/components/loading_indicator' ;
2022-10-09 12:55:09 +11:00
import ScrollableList from 'mastodon/components/scrollable_list' ;
import AccountContainer from 'mastodon/containers/account_container' ;
import Column from 'mastodon/features/ui/components/column' ;
2019-10-01 12:57:27 +10:00
const messages = defineMessages ( {
refresh : { id : 'refresh' , defaultMessage : 'Refresh' } ,
} ) ;
2016-11-04 23:39:24 +11:00
const mapStateToProps = ( state , props ) => ( {
2023-08-29 18:56:19 +10:00
accountIds : state . getIn ( [ 'user_lists' , 'favourited_by' , props . params . statusId , 'items' ] ) ,
hasMore : ! ! state . getIn ( [ 'user_lists' , 'favourited_by' , props . params . statusId , 'next' ] ) ,
isLoading : state . getIn ( [ 'user_lists' , 'favourited_by' , props . params . statusId , 'isLoading' ] , true ) ,
2016-11-04 23:39:24 +11:00
} ) ;
2018-09-15 01:59:48 +10:00
class Favourites extends ImmutablePureComponent {
2016-11-04 23:39:24 +11:00
2017-05-12 22:44:10 +10:00
static propTypes = {
params : PropTypes . object . isRequired ,
dispatch : PropTypes . func . isRequired ,
2017-05-21 01:31:47 +10:00
accountIds : ImmutablePropTypes . list ,
2023-08-29 18:56:19 +10:00
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
2019-07-19 17:25:22 +10:00
multiColumn : PropTypes . bool ,
2019-10-01 12:57:27 +10:00
intl : PropTypes . object . isRequired ,
2017-05-12 22:44:10 +10:00
} ;
2023-05-10 17:05:32 +10:00
UNSAFE _componentWillMount ( ) {
2019-09-30 00:27:00 +10:00
if ( ! this . props . accountIds ) {
this . props . dispatch ( fetchFavourites ( this . props . params . statusId ) ) ;
}
2017-04-22 04:05:35 +10:00
}
2016-11-04 23:39:24 +11:00
2019-10-01 12:57:27 +10:00
handleRefresh = ( ) => {
this . props . dispatch ( fetchFavourites ( this . props . params . statusId ) ) ;
2023-01-30 11:45:35 +11:00
} ;
2019-10-01 12:57:27 +10:00
2023-08-29 18:56:19 +10:00
handleLoadMore = debounce ( ( ) => {
this . props . dispatch ( expandFavourites ( this . props . params . statusId ) ) ;
} , 300 , { leading : true } ) ;
2016-11-04 23:39:24 +11:00
render ( ) {
2023-08-29 18:56:19 +10:00
const { intl , accountIds , hasMore , isLoading , multiColumn } = this . props ;
2016-11-04 23:39:24 +11:00
if ( ! accountIds ) {
return (
< Column >
< LoadingIndicator / >
< / Column >
) ;
}
2023-07-22 03:09:13 +10:00
const emptyMessage = < FormattedMessage id = 'empty_column.favourites' defaultMessage = 'No one has favorited this post yet. When someone does, they will show up here.' / > ;
2018-08-27 00:39:37 +10:00
2016-11-04 23:39:24 +11:00
return (
2019-10-01 12:57:27 +10:00
< Column bindToDocument = { ! multiColumn } >
< ColumnHeader
showBackButton
multiColumn = { multiColumn }
extraButton = { (
2023-10-25 04:45:08 +11: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 12:57:27 +10:00
) }
/ >
2016-11-04 23:39:24 +11:00
2018-08-27 00:39:37 +10:00
< ScrollableList
scrollKey = 'favourites'
2023-08-29 18:56:19 +10:00
onLoadMore = { this . handleLoadMore }
hasMore = { hasMore }
isLoading = { isLoading }
2018-08-27 00:39:37 +10:00
emptyMessage = { emptyMessage }
2019-07-19 17:25:22 +10:00
bindToDocument = { ! multiColumn }
2018-08-27 00:39:37 +10:00
>
{ accountIds . map ( id =>
2020-03-09 02:02:36 +11:00
< AccountContainer key = { id } id = { id } withNote = { false } / > ,
2018-08-27 00:39:37 +10:00
) }
< / ScrollableList >
2022-10-20 23:35:29 +11:00
< Helmet >
< meta name = 'robots' content = 'noindex' / >
< / Helmet >
2016-11-04 23:39:24 +11:00
< / Column >
) ;
}
2017-04-22 04:05:35 +10:00
}
2023-03-24 13:17:53 +11:00
export default connect ( mapStateToProps ) ( injectIntl ( Favourites ) ) ;