2023-03-08 10:22:10 -08:00
|
|
|
import React from 'react';
|
|
|
|
|
2023-05-01 11:58:40 -07:00
|
|
|
import { useSuggestedGroups } from 'soapbox/api/hooks';
|
2023-03-08 10:22:10 -08:00
|
|
|
import { Widget } from 'soapbox/components/ui';
|
|
|
|
import GroupListItem from 'soapbox/features/groups/components/discover/group-list-item';
|
|
|
|
import PlaceholderGroupSearch from 'soapbox/features/placeholder/components/placeholder-group-search';
|
|
|
|
|
|
|
|
const SuggestedGroupsPanel = () => {
|
|
|
|
const { groups, isFetching, isFetched, isError } = useSuggestedGroups();
|
|
|
|
const isEmpty = (isFetched && groups.length === 0) || isError;
|
|
|
|
|
|
|
|
if (isEmpty) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Widget
|
|
|
|
title='Suggested Groups'
|
|
|
|
>
|
|
|
|
{isFetching ? (
|
|
|
|
new Array(3).fill(0).map((_, idx) => (
|
|
|
|
<PlaceholderGroupSearch key={idx} />
|
|
|
|
))
|
|
|
|
) : (
|
|
|
|
groups.slice(0, 3).map((group) => (
|
|
|
|
<GroupListItem group={group} withJoinAction={false} key={group.id} />
|
|
|
|
))
|
|
|
|
)}
|
|
|
|
</Widget>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SuggestedGroupsPanel;
|