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