2022-05-19 09:29:28 -07:00
import debounce from 'lodash/debounce' ;
2022-11-25 09:04:11 -08:00
import React from 'react' ;
2022-04-12 11:25:53 -07:00
import { FormattedMessage } from 'react-intl' ;
2022-04-12 06:52:04 -07:00
2022-11-15 08:00:49 -08:00
import ScrollableList from 'soapbox/components/scrollable-list' ;
2022-04-12 06:52:04 -07:00
import { Button , Card , CardBody , Stack , Text } from 'soapbox/components/ui' ;
2022-11-15 08:13:54 -08:00
import AccountContainer from 'soapbox/containers/account-container' ;
2022-09-27 06:58:49 -07:00
import { useOnboardingSuggestions } from 'soapbox/queries/suggestions' ;
2022-04-12 06:52:04 -07:00
const SuggestedAccountsStep = ( { onNext } : { onNext : ( ) = > void } ) = > {
2022-08-09 08:00:22 -07:00
const { data , fetchNextPage , hasNextPage , isFetching } = useOnboardingSuggestions ( ) ;
2022-04-12 06:52:04 -07:00
2022-05-19 09:29:28 -07:00
const handleLoadMore = debounce ( ( ) = > {
2022-08-09 08:00:22 -07:00
if ( isFetching ) {
2022-05-19 09:29:28 -07:00
return null ;
}
2022-08-09 08:00:22 -07:00
return fetchNextPage ( ) ;
2022-05-19 09:29:28 -07:00
} , 300 ) ;
2022-04-12 06:52:04 -07:00
2022-04-20 10:24:03 -07:00
const renderSuggestions = ( ) = > {
2022-08-09 08:00:22 -07:00
if ( ! data ) {
return null ;
}
2022-04-20 10:24:03 -07:00
return (
2022-05-19 09:29:28 -07:00
< div className = 'sm:pt-4 sm:pb-10 flex flex-col' >
< ScrollableList
2022-08-09 08:00:22 -07:00
isLoading = { isFetching }
2022-05-19 09:29:28 -07:00
scrollKey = 'suggestions'
onLoadMore = { handleLoadMore }
2022-08-09 08:00:22 -07:00
hasMore = { hasNextPage }
2022-05-19 09:29:28 -07:00
useWindowScroll = { false }
style = { { height : 320 } }
>
2022-08-09 08:00:22 -07:00
{ data . map ( ( suggestion ) = > (
< div key = { suggestion . account . id } className = 'py-2' >
2022-05-19 09:29:28 -07:00
< AccountContainer
2022-08-09 08:00:22 -07:00
id = { suggestion . account . id }
2022-05-19 09:29:28 -07:00
showProfileHoverCard = { false }
2022-07-01 13:07:01 -07:00
withLinkToProfile = { false }
2022-05-19 09:29:28 -07:00
/ >
< / div >
) ) }
< / ScrollableList >
2022-04-20 10:24:03 -07:00
< / div >
) ;
} ;
const renderEmpty = ( ) = > {
return (
2022-07-22 10:30:16 -07:00
< div className = 'bg-primary-50 dark:bg-gray-800 my-2 rounded-lg text-center p-8' >
2022-04-20 10:24:03 -07:00
< Text >
< FormattedMessage id = 'empty_column.follow_recommendations' defaultMessage = 'Looks like no suggestions could be generated for you. You can try using search to look for people you might know or explore trending hashtags.' / >
< / Text >
< / div >
) ;
} ;
const renderBody = ( ) = > {
2022-08-09 08:00:22 -07:00
if ( ! data || data . length === 0 ) {
2022-04-20 10:24:03 -07:00
return renderEmpty ( ) ;
} else {
return renderSuggestions ( ) ;
}
} ;
2022-04-12 06:52:04 -07:00
return (
< Card variant = 'rounded' size = 'xl' >
< CardBody >
< div >
2022-07-22 10:30:16 -07:00
< div className = 'pb-4 sm:pb-10 mb-4 border-b border-gray-200 dark:border-gray-800 border-solid -mx-4 sm:-mx-10' >
2022-04-12 06:52:04 -07:00
< Stack space = { 2 } >
< Text size = '2xl' align = 'center' weight = 'bold' >
2022-04-12 11:25:53 -07:00
< FormattedMessage id = 'onboarding.suggestions.title' defaultMessage = 'Suggested accounts' / >
2022-04-12 06:52:04 -07:00
< / Text >
< Text theme = 'muted' align = 'center' >
2022-04-12 11:25:53 -07:00
< FormattedMessage id = 'onboarding.suggestions.subtitle' defaultMessage = 'Here are a few of the most popular accounts you might like.' / >
2022-04-12 06:52:04 -07:00
< / Text >
< / Stack >
< / div >
2022-04-20 10:24:03 -07:00
{ renderBody ( ) }
2022-04-12 06:52:04 -07:00
< div className = 'sm:w-2/3 md:w-1/2 mx-auto' >
< Stack >
< Stack justifyContent = 'center' space = { 2 } >
< Button
block
theme = 'primary'
onClick = { onNext }
>
2022-04-20 10:08:49 -07:00
< FormattedMessage id = 'onboarding.done' defaultMessage = 'Done' / >
2022-04-12 06:52:04 -07:00
< / Button >
2022-07-22 10:30:16 -07:00
< Button block theme = 'tertiary' type = 'button' onClick = { onNext } >
2022-04-12 11:25:53 -07:00
< FormattedMessage id = 'onboarding.skip' defaultMessage = 'Skip for now' / >
< / Button >
2022-04-12 06:52:04 -07:00
< / Stack >
< / Stack >
< / div >
< / div >
< / CardBody >
< / Card >
) ;
} ;
export default SuggestedAccountsStep ;