2020-08-17 21:07:16 +01:00
import React from 'react'
2020-08-17 21:59:29 +01:00
import PropTypes from 'prop-types'
2020-08-17 21:39:25 +01:00
import { connect } from 'react-redux'
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
2020-03-24 04:39:12 +00:00
class LikedStatuses extends ImmutablePureComponent {
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 ( ) {
2020-07-29 21:40:47 +01:00
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
}
}
2020-08-19 01:22:15 +01:00
const mapStateToProps = ( state , { params : { username } } ) => ( {
isMyAccount : ( username . toLowerCase ( ) === meUsername . toLowerCase ( ) ) ,
statusIds : state . getIn ( [ 'status_lists' , 'favorites' , 'items' ] ) ,
isLoading : state . getIn ( [ 'status_lists' , 'favorites' , 'isLoading' ] , true ) ,
hasMore : ! ! state . getIn ( [ 'status_lists' , 'favorites' , 'next' ] ) ,
} )
LikedStatuses . propTypes = {
dispatch : PropTypes . func . isRequired ,
statusIds : ImmutablePropTypes . list . isRequired ,
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
isMyAccount : PropTypes . bool . isRequired ,
}
export default connect ( mapStateToProps ) ( LikedStatuses )