2022-10-09 03:55:09 +02:00
import { debounce } from 'lodash' ;
2018-04-11 19:42:25 +02:00
import PropTypes from 'prop-types' ;
2022-10-09 03:55:09 +02:00
import React from 'react' ;
import { Helmet } from 'react-helmet' ;
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2018-04-11 19:42:25 +02:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2022-10-09 03:55:09 +02:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import { connect } from 'react-redux' ;
2018-04-11 19:42:25 +02:00
import { fetchBookmarkedStatuses , expandBookmarkedStatuses } from 'flavours/glitch/actions/bookmarks' ;
import { addColumn , removeColumn , moveColumn } from 'flavours/glitch/actions/columns' ;
2022-10-09 03:55:09 +02:00
import ColumnHeader from 'flavours/glitch/components/column_header' ;
2018-04-11 19:42:25 +02:00
import StatusList from 'flavours/glitch/components/status_list' ;
2022-10-09 03:55:09 +02:00
import Column from 'flavours/glitch/features/ui/components/column' ;
2018-04-11 19:42:25 +02:00
const messages = defineMessages ( {
heading : { id : 'column.bookmarks' , defaultMessage : 'Bookmarks' } ,
} ) ;
const mapStateToProps = state => ( {
statusIds : state . getIn ( [ 'status_lists' , 'bookmarks' , 'items' ] ) ,
isLoading : state . getIn ( [ 'status_lists' , 'bookmarks' , 'isLoading' ] , true ) ,
hasMore : ! ! state . getIn ( [ 'status_lists' , 'bookmarks' , 'next' ] ) ,
} ) ;
2019-09-09 15:16:08 +02:00
export default @ connect ( mapStateToProps )
2018-04-11 19:42:25 +02:00
@ injectIntl
2019-09-09 15:16:08 +02:00
class Bookmarks extends ImmutablePureComponent {
2018-04-11 19:42:25 +02:00
static propTypes = {
dispatch : PropTypes . func . isRequired ,
statusIds : ImmutablePropTypes . list . isRequired ,
intl : PropTypes . object . isRequired ,
columnId : PropTypes . string ,
multiColumn : PropTypes . bool ,
hasMore : PropTypes . bool ,
isLoading : PropTypes . bool ,
} ;
componentWillMount ( ) {
this . props . dispatch ( fetchBookmarkedStatuses ( ) ) ;
}
handlePin = ( ) => {
const { columnId , dispatch } = this . props ;
if ( columnId ) {
dispatch ( removeColumn ( columnId ) ) ;
} else {
dispatch ( addColumn ( 'BOOKMARKS' , { } ) ) ;
}
}
handleMove = ( dir ) => {
const { columnId , dispatch } = this . props ;
dispatch ( moveColumn ( columnId , dir ) ) ;
}
handleHeaderClick = ( ) => {
this . column . scrollTop ( ) ;
}
setRef = c => {
this . column = c ;
}
2018-05-27 17:46:48 +02:00
handleLoadMore = debounce ( ( ) => {
2018-04-11 19:42:25 +02:00
this . props . dispatch ( expandBookmarkedStatuses ( ) ) ;
} , 300 , { leading : true } )
render ( ) {
const { intl , statusIds , columnId , multiColumn , hasMore , isLoading } = this . props ;
const pinned = ! ! columnId ;
2022-05-03 10:59:23 +02:00
const emptyMessage = < FormattedMessage id = 'empty_column.bookmarked_statuses' defaultMessage = "You don't have any bookmarked posts yet. When you bookmark one, it will show up here." / > ;
2019-07-20 15:07:24 +02:00
2018-04-11 19:42:25 +02:00
return (
2019-10-05 22:41:49 +02:00
< Column bindToDocument = { ! multiColumn } ref = { this . setRef } name = 'bookmarks' >
2018-04-11 19:42:25 +02:00
< ColumnHeader
icon = 'bookmark'
title = { intl . formatMessage ( messages . heading ) }
onPin = { this . handlePin }
onMove = { this . handleMove }
onClick = { this . handleHeaderClick }
pinned = { pinned }
multiColumn = { multiColumn }
showBackButton
/ >
< StatusList
trackScroll = { ! pinned }
statusIds = { statusIds }
scrollKey = { ` bookmarked_statuses- ${ columnId } ` }
hasMore = { hasMore }
isLoading = { isLoading }
2018-05-27 17:46:48 +02:00
onLoadMore = { this . handleLoadMore }
2019-07-20 15:07:24 +02:00
emptyMessage = { emptyMessage }
2019-10-05 22:41:49 +02:00
bindToDocument = { ! multiColumn }
2018-04-11 19:42:25 +02:00
/ >
2022-10-09 03:55:09 +02:00
< Helmet >
< title > { intl . formatMessage ( messages . heading ) } < / t i t l e >
< / H e l m e t >
2018-04-11 19:42:25 +02:00
< / C o l u m n >
) ;
}
}