2022-06-16 12:32:17 -07:00
import debounce from 'lodash/debounce' ;
2022-04-11 12:58:48 -07:00
import React from 'react' ;
import { defineMessages , FormattedMessage , useIntl } from 'react-intl' ;
2022-05-30 11:23:55 -07:00
import { fetchBookmarkedStatuses , expandBookmarkedStatuses } from 'soapbox/actions/bookmarks' ;
2022-07-13 18:13:37 -07:00
import PullToRefresh from 'soapbox/components/pull-to-refresh' ;
2022-11-15 08:00:49 -08:00
import StatusList from 'soapbox/components/status-list' ;
2022-04-11 12:58:48 -07:00
import { Column } from 'soapbox/components/ui' ;
2022-06-02 12:00:35 -07:00
import { useAppSelector , useAppDispatch } from 'soapbox/hooks' ;
2022-04-11 12:58:48 -07:00
const messages = defineMessages ( {
heading : { id : 'column.bookmarks' , defaultMessage : 'Bookmarks' } ,
} ) ;
const handleLoadMore = debounce ( ( dispatch ) = > {
dispatch ( expandBookmarkedStatuses ( ) ) ;
} , 300 , { leading : true } ) ;
const Bookmarks : React.FC = ( ) = > {
2022-06-02 12:00:35 -07:00
const dispatch = useAppDispatch ( ) ;
2022-04-11 12:58:48 -07:00
const intl = useIntl ( ) ;
2022-06-05 07:17:26 -07:00
const statusIds = useAppSelector ( ( state ) = > state . status_lists . get ( 'bookmarks' ) ! . items ) ;
const isLoading = useAppSelector ( ( state ) = > state . status_lists . get ( 'bookmarks' ) ! . isLoading ) ;
const hasMore = useAppSelector ( ( state ) = > ! ! state . status_lists . get ( 'bookmarks' ) ! . next ) ;
2022-04-11 12:58:48 -07:00
React . useEffect ( ( ) = > {
dispatch ( fetchBookmarkedStatuses ( ) ) ;
} , [ ] ) ;
const handleRefresh = ( ) = > {
return dispatch ( fetchBookmarkedStatuses ( ) ) ;
} ;
const emptyMessage = < FormattedMessage id = 'empty_column.bookmarks' defaultMessage = "You don't have any bookmarks yet. When you add one, it will show up here." / > ;
return (
2022-11-30 09:19:16 -08:00
< Column label = { intl . formatMessage ( messages . heading ) } transparent >
2022-07-13 18:13:37 -07:00
< PullToRefresh onRefresh = { handleRefresh } >
< StatusList
statusIds = { statusIds }
scrollKey = 'bookmarked_statuses'
hasMore = { hasMore }
isLoading = { typeof isLoading === 'boolean' ? isLoading : true }
onLoadMore = { ( ) = > handleLoadMore ( dispatch ) }
emptyMessage = { emptyMessage }
divideType = 'space'
/ >
< / PullToRefresh >
2022-04-11 12:58:48 -07:00
< / Column >
) ;
} ;
export default Bookmarks ;