bigbuffet-rw/app/soapbox/features/follow-recommendations/index.tsx

83 lines
2.6 KiB
TypeScript
Raw Normal View History

2022-07-01 13:09:07 -07:00
import debounce from 'lodash/debounce';
import React, { useEffect } from 'react';
2022-07-06 06:04:26 -07:00
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
2022-07-01 13:09:07 -07:00
import { fetchSuggestions } from 'soapbox/actions/suggestions';
import ScrollableList from 'soapbox/components/scrollable_list';
import { Stack, Text } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account_container';
import Column from 'soapbox/features/ui/components/column';
import { useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks';
2022-07-06 06:04:26 -07:00
const messages = defineMessages({
2022-09-26 12:23:51 -07:00
heading: { id: 'followRecommendations.heading', defaultMessage: 'Suggested Profiles' },
2022-07-06 06:04:26 -07:00
});
2022-07-01 13:09:07 -07:00
const FollowRecommendations: React.FC = () => {
const dispatch = useAppDispatch();
2022-07-06 06:04:26 -07:00
const intl = useIntl();
2022-07-01 13:09:07 -07:00
const features = useFeatures();
const suggestions = useAppSelector((state) => state.suggestions.items);
const hasMore = useAppSelector((state) => !!state.suggestions.next);
const isLoading = useAppSelector((state) => state.suggestions.isLoading);
const handleLoadMore = debounce(() => {
if (isLoading) {
return null;
}
return dispatch(fetchSuggestions({ limit: 20 }));
}, 300);
useEffect(() => {
dispatch(fetchSuggestions({ limit: 20 }));
}, []);
if (suggestions.size === 0 && !isLoading) {
return (
2022-07-06 06:04:26 -07:00
<Column label={intl.formatMessage(messages.heading)}>
2022-07-01 13:09:07 -07:00
<Text align='center'>
<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>
</Column>
);
}
return (
2022-07-06 06:04:26 -07:00
<Column label={intl.formatMessage(messages.heading)}>
2022-07-01 13:09:07 -07:00
<Stack space={4}>
<ScrollableList
isLoading={isLoading}
scrollKey='suggestions'
onLoadMore={handleLoadMore}
hasMore={hasMore}
itemClassName='pb-4'
>
{features.truthSuggestions ? (
suggestions.map((suggestedProfile) => (
<AccountContainer
key={suggestedProfile.account}
id={suggestedProfile.account}
withAccountNote
showProfileHoverCard={false}
2022-07-06 11:36:28 -07:00
actionAlignment='top'
2022-07-01 13:09:07 -07:00
/>
))
) : (
suggestions.map((suggestion) => (
<AccountContainer
key={suggestion.account}
id={suggestion.account}
withAccountNote
/>
))
)}
</ScrollableList>
</Stack>
</Column>
);
};
export default FollowRecommendations;