2020-03-02 17:26:25 -05:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import { FormattedMessage } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
import { debounce } from 'lodash'
2020-03-04 18:08:08 -05: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 01:02:36 -04:00
const mapStateToProps = ( state , { params : { username } } ) => {
return {
isMyAccount : ( username . toLowerCase ( ) === meUsername . toLowerCase ( ) ) ,
2020-02-29 10:42:47 -05: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 17:26:25 -05:00
}
}
2019-08-07 01:02:36 -04:00
2020-02-25 11:04:44 -05:00
export default
@ connect ( mapStateToProps )
2020-02-29 10:42:47 -05:00
class Favorites extends ImmutablePureComponent {
2019-08-07 01:02:36 -04:00
static propTypes = {
dispatch : PropTypes . func . isRequired ,
statusIds : ImmutablePropTypes . list . isRequired ,
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
isMyAccount : PropTypes . bool . isRequired ,
2020-03-02 17:26:25 -05:00
}
2019-08-07 01:02:36 -04:00
2020-03-02 17:26:25 -05:00
componentWillMount ( ) {
this . props . dispatch ( fetchFavoritedStatuses ( ) )
2019-08-07 01:02:36 -04:00
}
handleLoadMore = debounce ( ( ) => {
2020-03-02 17:26:25 -05:00
this . props . dispatch ( expandFavoritedStatuses ( ) )
2019-08-07 01:02:36 -04:00
} , 300 , { leading : true } )
2020-03-02 17:26:25 -05:00
render ( ) {
const { statusIds , hasMore , isLoading , isMyAccount } = this . props
2019-08-07 01:02:36 -04:00
if ( ! isMyAccount ) {
2020-03-02 17:26:25 -05:00
return < ColumnIndicator type = 'missing' / >
2019-08-07 01:02:36 -04:00
}
2020-03-02 17:26:25 -05:00
console . log ( "statusIds:" , statusIds )
2019-08-07 01:02:36 -04:00
return (
2020-03-02 17:26:25 -05:00
< StatusList
statusIds = { statusIds }
scrollKey = 'favorited_statuses'
hasMore = { hasMore }
isLoading = { isLoading }
onLoadMore = { this . handleLoadMore }
emptyMessage = { < FormattedMessage id = 'empty_column.favorited_statuses' defaultMessage = "You don't have any favorite gabs yet. When you favorite one, it will show up here." / > }
/ >
)
2019-08-07 01:02:36 -04:00
}
}