2017-04-21 14:05:35 -04:00
import PropTypes from 'prop-types' ;
2023-05-28 10:38:10 -04:00
2022-10-08 21:55:09 -04:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2023-05-28 10:38:10 -04:00
import { Helmet } from 'react-helmet' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2022-10-08 21:55:09 -04:00
import { connect } from 'react-redux' ;
2023-05-28 10:38:10 -04:00
2023-08-29 04:56:19 -04:00
import { debounce } from 'lodash' ;
import { fetchFavourites , expandFavourites } from 'flavours/glitch/actions/interactions' ;
2022-10-08 21:55:09 -04:00
import ColumnHeader from 'flavours/glitch/components/column_header' ;
2023-11-15 06:01:51 -05:00
import { Icon } from 'flavours/glitch/components/icon' ;
2023-06-13 13:26:25 -04:00
import { LoadingIndicator } from 'flavours/glitch/components/loading_indicator' ;
2022-10-08 21:55:09 -04:00
import ScrollableList from 'flavours/glitch/components/scrollable_list' ;
2017-12-04 02:26:40 -05:00
import AccountContainer from 'flavours/glitch/containers/account_container' ;
import Column from 'flavours/glitch/features/ui/components/column' ;
2023-05-28 10:38:10 -04:00
2019-04-08 11:56:25 -04:00
const messages = defineMessages ( {
heading : { id : 'column.favourited_by' , defaultMessage : 'Favourited by' } ,
2019-09-30 22:57:27 -04:00
refresh : { id : 'refresh' , defaultMessage : 'Refresh' } ,
2019-04-08 11:56:25 -04:00
} ) ;
2016-11-04 08:39:24 -04:00
const mapStateToProps = ( state , props ) => ( {
2023-08-29 04:56:19 -04: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 08:39:24 -04:00
} ) ;
2019-09-09 09:16:08 -04:00
class Favourites extends ImmutablePureComponent {
2016-11-04 08:39:24 -04:00
2017-05-12 08:44:10 -04:00
static propTypes = {
params : PropTypes . object . isRequired ,
dispatch : PropTypes . func . isRequired ,
2017-05-20 11:31:47 -04:00
accountIds : ImmutablePropTypes . list ,
2023-08-29 04:56:19 -04:00
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
2019-07-19 03:25:22 -04:00
multiColumn : PropTypes . bool ,
2019-04-08 11:56:25 -04:00
intl : PropTypes . object . isRequired ,
2017-05-12 08:44:10 -04:00
} ;
2023-05-10 03:05:32 -04:00
UNSAFE _componentWillMount ( ) {
2019-09-29 10:27:00 -04:00
if ( ! this . props . accountIds ) {
this . props . dispatch ( fetchFavourites ( this . props . params . statusId ) ) ;
}
2017-04-21 14:05:35 -04:00
}
2016-11-04 08:39:24 -04:00
2019-04-08 11:56:25 -04:00
handleHeaderClick = ( ) => {
this . column . scrollTop ( ) ;
2023-02-03 14:52:07 -05:00
} ;
2019-04-08 11:56:25 -04:00
setRef = c => {
this . column = c ;
2023-02-03 14:52:07 -05:00
} ;
2019-04-08 11:56:25 -04:00
2019-09-30 22:57:27 -04:00
handleRefresh = ( ) => {
this . props . dispatch ( fetchFavourites ( this . props . params . statusId ) ) ;
2023-02-03 14:52:07 -05:00
} ;
2019-09-30 22:57:27 -04:00
2023-08-29 04:56:19 -04:00
handleLoadMore = debounce ( ( ) => {
this . props . dispatch ( expandFavourites ( this . props . params . statusId ) ) ;
} , 300 , { leading : true } ) ;
2016-11-04 08:39:24 -04:00
render ( ) {
2023-08-29 04:56:19 -04:00
const { intl , accountIds , hasMore , isLoading , multiColumn } = this . props ;
2016-11-04 08:39:24 -04:00
if ( ! accountIds ) {
return (
< Column >
< LoadingIndicator / >
< / Column >
) ;
}
2023-07-21 13:09:13 -04: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-26 10:39:37 -04:00
2016-11-04 08:39:24 -04:00
return (
2019-04-08 11:56:25 -04:00
< Column ref = { this . setRef } >
< ColumnHeader
icon = 'star'
title = { intl . formatMessage ( messages . heading ) }
onClick = { this . handleHeaderClick }
showBackButton
2019-08-01 13:17:17 -04:00
multiColumn = { multiColumn }
2019-09-30 22:57:27 -04:00
extraButton = { (
< button className = 'column-header__button' title = { intl . formatMessage ( messages . refresh ) } aria - label = { intl . formatMessage ( messages . refresh ) } onClick = { this . handleRefresh } > < Icon id = 'refresh' / > < / button >
) }
2019-04-08 11:56:25 -04:00
/ >
2018-08-26 10:39:37 -04:00
< ScrollableList
scrollKey = 'favourites'
2023-08-29 04:56:19 -04:00
onLoadMore = { this . handleLoadMore }
hasMore = { hasMore }
isLoading = { isLoading }
2018-08-26 10:39:37 -04:00
emptyMessage = { emptyMessage }
2019-07-19 03:25:22 -04:00
bindToDocument = { ! multiColumn }
2018-08-26 10:39:37 -04:00
>
{ accountIds . map ( id =>
2020-03-08 11:02:36 -04:00
< AccountContainer key = { id } id = { id } withNote = { false } / > ,
2018-08-26 10:39:37 -04:00
) }
< / ScrollableList >
2022-10-20 08:35:29 -04:00
< Helmet >
< meta name = 'robots' content = 'noindex' / >
< / Helmet >
2016-11-04 08:39:24 -04:00
< / Column >
) ;
}
2017-04-21 14:05:35 -04:00
}
2023-03-24 18:15:25 -04:00
export default connect ( mapStateToProps ) ( injectIntl ( Favourites ) ) ;