2017-04-22 03:05:35 +09:00
import PropTypes from 'prop-types' ;
2023-05-28 23:38:10 +09:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2022-10-09 10:55:09 +09:00
import { Helmet } from 'react-helmet' ;
2023-05-28 23:38:10 +09:00
2017-06-24 19:24:02 +09:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2022-10-09 10:55:09 +09:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import { connect } from 'react-redux' ;
2023-05-28 23:38:10 +09:00
2024-01-15 06:41:16 +09:00
import { ReactComponent as StarIcon } from '@material-symbols/svg-600/outlined/star-fill.svg' ;
2023-05-28 23:38:10 +09:00
import { debounce } from 'lodash' ;
2022-10-09 10:55:09 +09:00
import { addColumn , removeColumn , moveColumn } from 'flavours/glitch/actions/columns' ;
2017-12-04 16:26:40 +09:00
import { fetchFavouritedStatuses , expandFavouritedStatuses } from 'flavours/glitch/actions/favourites' ;
import ColumnHeader from 'flavours/glitch/components/column_header' ;
import StatusList from 'flavours/glitch/components/status_list' ;
2022-10-09 10:55:09 +09:00
import Column from 'flavours/glitch/features/ui/components/column' ;
2023-06-23 06:48:40 +09:00
import { getStatusList } from 'flavours/glitch/selectors' ;
2017-01-16 21:27:58 +09:00
const messages = defineMessages ( {
2023-07-22 02:09:13 +09:00
heading : { id : 'column.favourites' , defaultMessage : 'Favorites' } ,
2017-01-16 21:27:58 +09:00
} ) ;
const mapStateToProps = state => ( {
2023-06-23 06:48:40 +09:00
statusIds : getStatusList ( state , 'favourites' ) ,
2018-01-09 23:46:35 +09:00
isLoading : state . getIn ( [ 'status_lists' , 'favourites' , 'isLoading' ] , true ) ,
2017-08-29 05:23:44 +09:00
hasMore : ! ! state . getIn ( [ 'status_lists' , 'favourites' , 'next' ] ) ,
2017-01-16 21:27:58 +09:00
} ) ;
2019-09-09 22:16:08 +09:00
class Favourites extends ImmutablePureComponent {
2017-01-16 21:27:58 +09:00
2017-05-12 21:44:10 +09:00
static propTypes = {
dispatch : PropTypes . func . isRequired ,
2017-06-24 19:24:02 +09:00
statusIds : ImmutablePropTypes . list . isRequired ,
2017-05-12 21:44:10 +09:00
intl : PropTypes . object . isRequired ,
2017-07-15 07:49:34 +09:00
columnId : PropTypes . string ,
multiColumn : PropTypes . bool ,
2017-08-29 05:23:44 +09:00
hasMore : PropTypes . bool ,
2018-01-09 23:46:35 +09:00
isLoading : PropTypes . bool ,
2017-05-12 21:44:10 +09:00
} ;
2017-01-16 21:27:58 +09:00
2023-05-10 16:05:32 +09:00
UNSAFE _componentWillMount ( ) {
2017-01-16 21:27:58 +09:00
this . props . dispatch ( fetchFavouritedStatuses ( ) ) ;
2017-04-22 03:05:35 +09:00
}
2017-01-16 21:27:58 +09:00
2017-07-15 07:49:34 +09:00
handlePin = ( ) => {
const { columnId , dispatch } = this . props ;
if ( columnId ) {
dispatch ( removeColumn ( columnId ) ) ;
} else {
dispatch ( addColumn ( 'FAVOURITES' , { } ) ) ;
}
2023-02-04 04:52:07 +09:00
} ;
2017-07-15 07:49:34 +09:00
handleMove = ( dir ) => {
const { columnId , dispatch } = this . props ;
dispatch ( moveColumn ( columnId , dir ) ) ;
2023-02-04 04:52:07 +09:00
} ;
2017-07-15 07:49:34 +09:00
handleHeaderClick = ( ) => {
this . column . scrollTop ( ) ;
2023-02-04 04:52:07 +09:00
} ;
2017-07-15 07:49:34 +09:00
setRef = c => {
this . column = c ;
2023-02-04 04:52:07 +09:00
} ;
2017-07-15 07:49:34 +09:00
2018-05-28 00:46:48 +09:00
handleLoadMore = debounce ( ( ) => {
2017-01-16 21:27:58 +09:00
this . props . dispatch ( expandFavouritedStatuses ( ) ) ;
2023-02-04 04:52:07 +09:00
} , 300 , { leading : true } ) ;
2017-01-16 21:27:58 +09:00
render ( ) {
2018-01-09 23:46:35 +09:00
const { intl , statusIds , columnId , multiColumn , hasMore , isLoading } = this . props ;
2017-07-15 07:49:34 +09:00
const pinned = ! ! columnId ;
2017-01-16 21:27:58 +09:00
2023-07-22 02:09:13 +09: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 23:39:37 +09:00
2017-01-16 21:27:58 +09:00
return (
2023-12-10 04:26:57 +09:00
< Column bindToDocument = { ! multiColumn } ref = { this . setRef } label = { intl . formatMessage ( messages . heading ) } >
2017-07-15 07:49:34 +09:00
< ColumnHeader
icon = 'star'
2024-01-15 06:41:16 +09:00
iconComponent = { StarIcon }
2017-07-15 07:49:34 +09:00
title = { intl . formatMessage ( messages . heading ) }
onPin = { this . handlePin }
onMove = { this . handleMove }
onClick = { this . handleHeaderClick }
pinned = { pinned }
multiColumn = { multiColumn }
2017-09-07 00:32:15 +09:00
showBackButton
2017-07-15 07:49:34 +09:00
/ >
< StatusList
trackScroll = { ! pinned }
statusIds = { statusIds }
scrollKey = { ` favourited_statuses- ${ columnId } ` }
2017-08-29 05:23:44 +09:00
hasMore = { hasMore }
2018-01-09 23:46:35 +09:00
isLoading = { isLoading }
2018-05-28 00:46:48 +09:00
onLoadMore = { this . handleLoadMore }
2018-08-26 23:39:37 +09:00
emptyMessage = { emptyMessage }
2019-07-19 16:25:22 +09:00
bindToDocument = { ! multiColumn }
2017-07-15 07:49:34 +09:00
/ >
2022-10-09 10:55:09 +09:00
< Helmet >
< title > { intl . formatMessage ( messages . heading ) } < / title >
2022-10-20 21:35:29 +09:00
< meta name = 'robots' content = 'noindex' / >
2022-10-09 10:55:09 +09:00
< / Helmet >
2017-01-16 21:27:58 +09:00
< / Column >
) ;
}
2017-04-22 03:05:35 +09:00
}
2023-03-25 07:15:25 +09:00
export default connect ( mapStateToProps ) ( injectIntl ( Favourites ) ) ;