2017-05-03 01:04:16 +01:00
import React from 'react' ;
2017-01-16 12:27:58 +00:00
import { connect } from 'react-redux' ;
2017-04-21 19:05:35 +01:00
import PropTypes from 'prop-types' ;
2017-06-24 11:24:02 +01:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2017-01-16 12:27:58 +00:00
import { fetchFavouritedStatuses , expandFavouritedStatuses } from '../../actions/favourites' ;
import Column from '../ui/components/column' ;
2017-07-14 23:49:34 +01:00
import ColumnHeader from '../../components/column_header' ;
import { addColumn , removeColumn , moveColumn } from '../../actions/columns' ;
2017-01-16 12:27:58 +00:00
import StatusList from '../../components/status_list' ;
2018-08-26 15:39:37 +01:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2017-05-03 01:04:16 +01:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2017-12-09 01:22:13 +00:00
import { debounce } from 'lodash' ;
2017-01-16 12:27:58 +00:00
const messages = defineMessages ( {
2017-05-20 16:31:47 +01:00
heading : { id : 'column.favourites' , defaultMessage : 'Favourites' } ,
2017-01-16 12:27:58 +00:00
} ) ;
const mapStateToProps = state => ( {
2017-06-24 11:24:02 +01:00
statusIds : state . getIn ( [ 'status_lists' , 'favourites' , 'items' ] ) ,
2017-12-09 01:22:13 +00:00
isLoading : state . getIn ( [ 'status_lists' , 'favourites' , 'isLoading' ] , true ) ,
2017-08-28 21:23:44 +01:00
hasMore : ! ! state . getIn ( [ 'status_lists' , 'favourites' , 'next' ] ) ,
2017-01-16 12:27:58 +00:00
} ) ;
2018-09-14 16:59:48 +01:00
export default @ connect ( mapStateToProps )
2017-06-23 18:36:54 +01:00
@ injectIntl
2018-09-14 16:59:48 +01:00
class Favourites extends ImmutablePureComponent {
2017-01-16 12:27:58 +00:00
2017-05-12 13:44:10 +01:00
static propTypes = {
dispatch : PropTypes . func . isRequired ,
2018-07-29 15:52:06 +01:00
shouldUpdateScroll : PropTypes . func ,
2017-06-24 11:24:02 +01:00
statusIds : ImmutablePropTypes . list . isRequired ,
2017-05-12 13:44:10 +01:00
intl : PropTypes . object . isRequired ,
2017-07-14 23:49:34 +01:00
columnId : PropTypes . string ,
multiColumn : PropTypes . bool ,
2017-08-28 21:23:44 +01:00
hasMore : PropTypes . bool ,
2017-12-09 01:22:13 +00:00
isLoading : PropTypes . bool ,
2017-05-12 13:44:10 +01:00
} ;
2017-01-16 12:27:58 +00:00
componentWillMount ( ) {
this . props . dispatch ( fetchFavouritedStatuses ( ) ) ;
2017-04-21 19:05:35 +01:00
}
2017-01-16 12:27:58 +00:00
2017-07-14 23:49:34 +01:00
handlePin = ( ) => {
const { columnId , dispatch } = this . props ;
if ( columnId ) {
dispatch ( removeColumn ( columnId ) ) ;
} else {
dispatch ( addColumn ( 'FAVOURITES' , { } ) ) ;
}
}
handleMove = ( dir ) => {
const { columnId , dispatch } = this . props ;
dispatch ( moveColumn ( columnId , dir ) ) ;
}
handleHeaderClick = ( ) => {
this . column . scrollTop ( ) ;
}
setRef = c => {
this . column = c ;
}
2018-03-05 18:31:40 +00:00
handleLoadMore = debounce ( ( ) => {
2017-01-16 12:27:58 +00:00
this . props . dispatch ( expandFavouritedStatuses ( ) ) ;
2017-12-09 01:22:13 +00:00
} , 300 , { leading : true } )
2017-01-16 12:27:58 +00:00
render ( ) {
2018-07-29 15:52:06 +01:00
const { intl , shouldUpdateScroll , statusIds , columnId , multiColumn , hasMore , isLoading } = this . props ;
2017-07-14 23:49:34 +01:00
const pinned = ! ! columnId ;
2017-01-16 12:27:58 +00:00
2018-08-26 15:39:37 +01:00
const emptyMessage = < FormattedMessage id = 'empty_column.favourited_statuses' defaultMessage = "You don't have any favourite toots yet. When you favourite one, it will show up here." / > ;
2017-01-16 12:27:58 +00:00
return (
2019-08-01 18:17:17 +01:00
< Column bindToDocument = { ! multiColumn } ref = { this . setRef } label = { intl . formatMessage ( messages . heading ) } >
2017-07-14 23:49:34 +01:00
< ColumnHeader
icon = 'star'
title = { intl . formatMessage ( messages . heading ) }
onPin = { this . handlePin }
onMove = { this . handleMove }
onClick = { this . handleHeaderClick }
pinned = { pinned }
multiColumn = { multiColumn }
2017-09-06 16:32:15 +01:00
showBackButton
2017-07-14 23:49:34 +01:00
/ >
< StatusList
trackScroll = { ! pinned }
statusIds = { statusIds }
scrollKey = { ` favourited_statuses- ${ columnId } ` }
2017-08-28 21:23:44 +01:00
hasMore = { hasMore }
2017-12-09 01:22:13 +00:00
isLoading = { isLoading }
2018-03-05 18:31:40 +00:00
onLoadMore = { this . handleLoadMore }
2018-07-29 15:52:06 +01:00
shouldUpdateScroll = { shouldUpdateScroll }
2018-08-26 15:39:37 +01:00
emptyMessage = { emptyMessage }
2019-07-19 08:25:22 +01:00
bindToDocument = { ! multiColumn }
2017-07-14 23:49:34 +01:00
/ >
2017-01-16 12:27:58 +00:00
< / C o l u m n >
) ;
}
2017-04-21 19:05:35 +01:00
}