2020-03-27 13:59:38 -07:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import PropTypes from 'prop-types' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import { fetchFavouritedStatuses , expandFavouritedStatuses } from '../../actions/favourites' ;
import Column from '../ui/components/column' ;
import StatusList from '../../components/status_list' ;
import { injectIntl , FormattedMessage } from 'react-intl' ;
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import { debounce } from 'lodash' ;
2020-05-28 15:52:07 -07:00
import MissingIndicator from 'soapbox/components/missing_indicator' ;
2020-03-27 13:59:38 -07:00
2021-07-02 13:06:27 -07:00
const mapStateToProps = ( state , { params } ) => {
const username = params . username || '' ;
2020-04-17 15:14:04 -07:00
const me = state . get ( 'me' ) ;
const meUsername = state . getIn ( [ 'accounts' , me , 'username' ] ) ;
2020-03-27 13:59:38 -07:00
return {
isMyAccount : ( username . toLowerCase ( ) === meUsername . toLowerCase ( ) ) ,
statusIds : state . getIn ( [ 'status_lists' , 'favourites' , 'items' ] ) ,
isLoading : state . getIn ( [ 'status_lists' , 'favourites' , 'isLoading' ] , true ) ,
hasMore : ! ! state . getIn ( [ 'status_lists' , 'favourites' , 'next' ] ) ,
} ;
} ;
export default @ connect ( mapStateToProps )
@ injectIntl
class Favourites extends ImmutablePureComponent {
static propTypes = {
dispatch : PropTypes . func . isRequired ,
2021-07-08 14:12:04 -07:00
statusIds : ImmutablePropTypes . orderedSet . isRequired ,
2020-03-27 13:59:38 -07:00
intl : PropTypes . object . isRequired ,
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
isMyAccount : PropTypes . bool . isRequired ,
} ;
2020-06-17 18:42:30 -07:00
componentDidMount ( ) {
2020-03-27 13:59:38 -07:00
this . props . dispatch ( fetchFavouritedStatuses ( ) ) ;
}
handleLoadMore = debounce ( ( ) => {
this . props . dispatch ( expandFavouritedStatuses ( ) ) ;
} , 300 , { leading : true } )
2020-04-14 14:47:35 -07:00
render ( ) {
2020-04-14 13:45:38 -07:00
const { statusIds , hasMore , isLoading , isMyAccount } = this . props ;
2020-03-27 13:59:38 -07:00
if ( ! isMyAccount ) {
return (
< Column >
< MissingIndicator / >
< / C o l u m n >
) ;
}
2020-06-08 18:46:52 -07:00
const emptyMessage = < FormattedMessage id = 'empty_column.favourited_statuses' defaultMessage = "You don't have any liked posts yet. When you like one, it will show up here." / > ;
2020-03-27 13:59:38 -07:00
return (
< Column >
< StatusList
statusIds = { statusIds }
scrollKey = 'favourited_statuses'
hasMore = { hasMore }
isLoading = { isLoading }
onLoadMore = { this . handleLoadMore }
emptyMessage = { emptyMessage }
/ >
< / C o l u m n >
) ;
}
}