2022-10-08 20:55:09 -05:00
import { debounce } from 'lodash' ;
2018-04-11 12:42:25 -05:00
import PropTypes from 'prop-types' ;
2022-10-08 20:55:09 -05:00
import React from 'react' ;
import { Helmet } from 'react-helmet' ;
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2018-04-11 12:42:25 -05:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2022-10-08 20:55:09 -05:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
import { connect } from 'react-redux' ;
2018-04-11 12:42:25 -05:00
import { fetchBookmarkedStatuses , expandBookmarkedStatuses } from 'flavours/glitch/actions/bookmarks' ;
import { addColumn , removeColumn , moveColumn } from 'flavours/glitch/actions/columns' ;
2022-10-08 20:55:09 -05:00
import ColumnHeader from 'flavours/glitch/components/column_header' ;
2018-04-11 12:42:25 -05:00
import StatusList from 'flavours/glitch/components/status_list' ;
2022-10-08 20:55:09 -05:00
import Column from 'flavours/glitch/features/ui/components/column' ;
2018-04-11 12:42:25 -05: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 08:16:08 -05:00
export default @ connect ( mapStateToProps )
2018-04-11 12:42:25 -05:00
@ injectIntl
2019-09-09 08:16:08 -05:00
class Bookmarks extends ImmutablePureComponent {
2018-04-11 12:42:25 -05: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 10:46:48 -05:00
handleLoadMore = debounce ( ( ) => {
2018-04-11 12:42:25 -05:00
this . props . dispatch ( expandBookmarkedStatuses ( ) ) ;
} , 300 , { leading : true } )
render ( ) {
const { intl , statusIds , columnId , multiColumn , hasMore , isLoading } = this . props ;
const pinned = ! ! columnId ;
2022-05-03 03:59:23 -05: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 08:07:24 -05:00
2018-04-11 12:42:25 -05:00
return (
2019-10-05 15:41:49 -05:00
< Column bindToDocument = { ! multiColumn } ref = { this . setRef } name = 'bookmarks' >
2018-04-11 12:42:25 -05: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 10:46:48 -05:00
onLoadMore = { this . handleLoadMore }
2019-07-20 08:07:24 -05:00
emptyMessage = { emptyMessage }
2019-10-05 15:41:49 -05:00
bindToDocument = { ! multiColumn }
2018-04-11 12:42:25 -05:00
/ >
2022-10-08 20:55:09 -05:00
< Helmet >
< title > { intl . formatMessage ( messages . heading ) } < / t i t l e >
2022-10-20 07:35:29 -05:00
< meta name = 'robots' content = 'noindex' / >
2022-10-08 20:55:09 -05:00
< / H e l m e t >
2018-04-11 12:42:25 -05:00
< / C o l u m n >
) ;
}
}