Do not display account suggestion dismiss button if not supported

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-09-12 23:03:09 +02:00
parent c96a7c4dde
commit 0a7bdbb7d0
11 changed files with 24 additions and 72 deletions

View File

@ -1,28 +1,21 @@
import React, { useEffect } from 'react';
import React from 'react';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { fetchSuggestions } from 'pl-fe/actions/suggestions';
import ScrollableList from 'pl-fe/components/scrollable-list';
import { Column, Stack, Text } from 'pl-fe/components/ui';
import AccountContainer from 'pl-fe/containers/account-container';
import { useAppDispatch, useAppSelector } from 'pl-fe/hooks';
import { useSuggestions } from 'pl-fe/queries/suggestions';
const messages = defineMessages({
heading: { id: 'follow_recommendations.heading', defaultMessage: 'Suggested profiles' },
});
const FollowRecommendations: React.FC = () => {
const dispatch = useAppDispatch();
const intl = useIntl();
const suggestions = useAppSelector((state) => state.suggestions.items);
const isLoading = useAppSelector((state) => state.suggestions.isLoading);
const { data: suggestions, isFetching } = useSuggestions();
useEffect(() => {
dispatch(fetchSuggestions(20));
}, []);
if (suggestions.size === 0 && !isLoading) {
if (suggestions.length === 0 && !isFetching) {
return (
<Column label={intl.formatMessage(messages.heading)}>
<Text align='center'>
@ -36,7 +29,7 @@ const FollowRecommendations: React.FC = () => {
<Column label={intl.formatMessage(messages.heading)}>
<Stack space={4}>
<ScrollableList
isLoading={isLoading}
isLoading={isFetching}
scrollKey='suggestions'
itemClassName='pb-4'
>

View File

@ -5,6 +5,7 @@ import { Link } from 'react-router-dom';
import { Text, Widget } from 'pl-fe/components/ui';
import AccountContainer from 'pl-fe/containers/account-container';
import PlaceholderSidebarSuggestions from 'pl-fe/features/placeholder/components/placeholder-sidebar-suggestions';
import { useFeatures } from 'pl-fe/hooks';
import { useDismissSuggestion, useSuggestions } from 'pl-fe/queries/suggestions';
import type { Account as AccountEntity } from 'pl-fe/normalizers';
@ -18,6 +19,7 @@ interface IWhoToFollowPanel {
}
const WhoToFollowPanel = ({ limit }: IWhoToFollowPanel) => {
const features = useFeatures();
const intl = useIntl();
const { data: suggestions, isFetching } = useSuggestions();
@ -54,7 +56,7 @@ const WhoToFollowPanel = ({ limit }: IWhoToFollowPanel) => {
id={suggestion.account}
actionIcon={require('@tabler/icons/outline/x.svg')}
actionTitle={intl.formatMessage(messages.dismissSuggestion)}
onActionClick={handleDismiss}
onActionClick={features.suggestionsDismiss ? handleDismiss : undefined}
/>
))
)}