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-07-25 00:48:31 +01:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import { FormattedMessage } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
import debounce from 'lodash.debounce'
import { fetchBookmarkedStatuses , expandBookmarkedStatuses } from '../actions/bookmarks'
import { meUsername } from '../initial_state'
import StatusList from '../components/status_list'
import ColumnIndicator from '../components/column_indicator'
2020-12-17 06:34:00 +00:00
import Block from '../components/block'
import Button from '../components/button'
import Text from '../components/text'
2020-07-25 00:48:31 +01:00
class BookmarkedStatuses extends ImmutablePureComponent {
componentWillMount ( ) {
2020-12-16 07:39:07 +00:00
this . props . dispatch ( fetchBookmarkedStatuses ( this . props . bookmarkCollectionId ) )
2020-07-25 00:48:31 +01:00
}
handleLoadMore = debounce ( ( ) => {
2020-12-16 07:39:07 +00:00
this . props . dispatch ( expandBookmarkedStatuses ( this . props . bookmarkCollectionId ) )
2020-07-25 00:48:31 +01:00
} , 300 , { leading : true } )
render ( ) {
2020-07-29 21:40:47 +01:00
const {
statusIds ,
hasMore ,
isLoading ,
isMyAccount ,
} = this . props
2020-07-25 00:48:31 +01:00
if ( ! isMyAccount ) {
return < ColumnIndicator type = 'missing' / >
}
2020-12-17 06:34:00 +00:00
console . log ( "statusIds:" , statusIds )
2020-07-25 00:48:31 +01:00
return (
2020-12-17 06:34:00 +00:00
< div className = { [ _s . d , _s . w100PC ] . join ( ' ' ) } >
< Block >
< div className = { [ _s . d , _s . px15 , _s . py10 ] . join ( ' ' ) } >
< div className = { [ _s . d , _s . flexRow , _s . aiCenter ] . join ( ' ' ) } >
< Text size = 'extraLarge' weight = 'bold' >
Bookmarks :
< / T e x t >
< Button
className = { [ _s . px10 , _s . mlAuto ] . join ( ' ' ) }
onClick = { this . handleOpenModal }
backgroundColor = 'tertiary'
color = 'tertiary'
icon = 'cog'
/ >
< / d i v >
< / d i v >
< / B l o c k >
< div className = { [ _s . d , _s . w100PC , _s . mt10 ] . join ( ' ' ) } >
< StatusList
statusIds = { statusIds }
scrollKey = 'bookmarked_statuses'
hasMore = { hasMore }
isLoading = { isLoading }
onLoadMore = { this . handleLoadMore }
emptyMessage = { < FormattedMessage id = 'empty_column.bookmarked_statuses' defaultMessage = "You don't have any bookmarked gabs yet. If you are GabPRO, when you bookmark one, it will show up here." / > }
/ >
< / d i v >
< / d i v >
2020-07-25 00:48:31 +01:00
)
}
}
2020-12-16 07:39:07 +00:00
const mapStateToProps = ( state , { params : { username , bookmarkCollectionId } } ) => ( {
bookmarkCollectionId ,
isMyAccount : ( username . toLowerCase ( ) === meUsername . toLowerCase ( ) ) ,
2020-12-17 06:34:00 +00:00
statusIds : state . getIn ( [ 'status_lists' , 'bookmarks' , bookmarkCollectionId , 'items' ] ) ,
isLoading : state . getIn ( [ 'status_lists' , 'bookmarks' , bookmarkCollectionId , 'isLoading' ] , true ) ,
hasMore : ! ! state . getIn ( [ 'status_lists' , 'bookmarks' , bookmarkCollectionId , 'next' ] ) ,
2020-12-16 07:39:07 +00:00
} )
2020-08-19 01:22:15 +01:00
BookmarkedStatuses . propTypes = {
dispatch : PropTypes . func . isRequired ,
statusIds : ImmutablePropTypes . list . isRequired ,
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
2020-12-17 06:34:00 +00:00
bookmarkCollectionId : PropTypes . string ,
2020-08-19 01:22:15 +01:00
isMyAccount : PropTypes . bool . isRequired ,
}
export default connect ( mapStateToProps ) ( BookmarkedStatuses )