2020-03-02 22:26:25 +00:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import { FormattedMessage } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
2020-04-08 02:06:59 +01:00
import debounce from 'lodash.debounce'
2020-03-04 23:08:08 +00:00
import { fetchFavoritedStatuses , expandFavoritedStatuses } from '../actions/favorites'
import { meUsername } from '../initial_state'
import StatusList from '../components/status_list'
import ColumnIndicator from '../components/column_indicator'
2019-08-07 06:02:36 +01:00
const mapStateToProps = ( state , { params : { username } } ) => {
return {
isMyAccount : ( username . toLowerCase ( ) === meUsername . toLowerCase ( ) ) ,
2020-02-29 15:42:47 +00:00
statusIds : state . getIn ( [ 'status_lists' , 'favorites' , 'items' ] ) ,
isLoading : state . getIn ( [ 'status_lists' , 'favorites' , 'isLoading' ] , true ) ,
hasMore : ! ! state . getIn ( [ 'status_lists' , 'favorites' , 'next' ] ) ,
2020-03-02 22:26:25 +00:00
}
}
2019-08-07 06:02:36 +01:00
2020-02-25 16:04:44 +00:00
export default
@ connect ( mapStateToProps )
2020-03-24 04:39:12 +00:00
class LikedStatuses extends ImmutablePureComponent {
2019-08-07 06:02:36 +01:00
static propTypes = {
dispatch : PropTypes . func . isRequired ,
statusIds : ImmutablePropTypes . list . isRequired ,
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
isMyAccount : PropTypes . bool . isRequired ,
2020-03-02 22:26:25 +00:00
}
2019-08-07 06:02:36 +01:00
2020-03-02 22:26:25 +00:00
componentWillMount ( ) {
this . props . dispatch ( fetchFavoritedStatuses ( ) )
2019-08-07 06:02:36 +01:00
}
handleLoadMore = debounce ( ( ) => {
2020-03-02 22:26:25 +00:00
this . props . dispatch ( expandFavoritedStatuses ( ) )
2019-08-07 06:02:36 +01:00
} , 300 , { leading : true } )
2020-03-02 22:26:25 +00:00
render ( ) {
const { statusIds , hasMore , isLoading , isMyAccount } = this . props
2019-08-07 06:02:36 +01:00
if ( ! isMyAccount ) {
2020-03-02 22:26:25 +00:00
return < ColumnIndicator type = 'missing' / >
2019-08-07 06:02:36 +01:00
}
return (
2020-03-02 22:26:25 +00:00
< StatusList
statusIds = { statusIds }
2020-03-24 04:39:12 +00:00
scrollKey = 'liked_statuses'
2020-03-02 22:26:25 +00:00
hasMore = { hasMore }
isLoading = { isLoading }
onLoadMore = { this . handleLoadMore }
2020-03-24 04:39:12 +00:00
emptyMessage = { < FormattedMessage id = 'empty_column.liked_statuses' defaultMessage = "You don't have any liked gabs yet. When you like one, it will show up here." / > }
2020-03-02 22:26:25 +00:00
/ >
)
2019-08-07 06:02:36 +01:00
}
}