Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | import { Link as MuiLink, Skeleton, styled, Typography } from "@mui/material";
import Alert from "components/Alert";
import Button from "components/Button";
import StyledLink from "components/StyledLink";
import { useListSubCommunities } from "features/communities/hooks";
import useUserCommunities from "features/userQueries/useUserCommunities";
import { useTranslation } from "i18n";
import { DASHBOARD } from "i18n/namespaces";
import React from "react";
import { routeToCommunity } from "routes";
import { theme } from "theme";
import hasAtLeastOnePage from "utils/hasAtLeastOnePage";
const StyledPlaceholder = styled("div")(() => ({
display: "flex",
flexDirection: "column",
padding: theme.spacing(2, 0),
borderBottom: `solid 1px ${theme.palette.divider}`,
"&:first-of-type": {
borderTop: `solid 1px ${theme.palette.divider}`,
},
}));
const StyledCommunityLink = styled(StyledLink)(() => ({
display: "flex",
flexDirection: "column",
padding: theme.spacing(2, 0),
borderBottom: `solid 1px ${theme.palette.divider}`,
"&:first-of-type": {
borderTop: `solid 1px ${theme.palette.divider}`,
},
}));
export default function CommunitiesList({ all = false }: { all?: boolean }) {
const { t } = useTranslation([DASHBOARD]);
const userCommunities = useUserCommunities();
const allCommunities = useListSubCommunities(0);
const communities = all ? allCommunities : userCommunities;
return (
<div>
{communities.error?.message && (
<Alert severity="error">{communities.error.message}</Alert>
)}
{communities.isLoading ? (
<StyledPlaceholder>
<MuiLink variant="h2" component="span" underline="hover">
<Skeleton width={100} />
</MuiLink>
<Typography variant="body2">
<Skeleton width={100} />
</Typography>
</StyledPlaceholder>
) : (
communities.data &&
(hasAtLeastOnePage(communities.data, "communitiesList") ? (
<>
{communities.data.pages
.flatMap((page) => page.communitiesList)
.map((community) => (
<StyledCommunityLink
href={routeToCommunity(community.communityId, community.slug)}
key={`community-link-${community.communityId}`}
>
<Typography variant="h2" component="span">
{community.name}
</Typography>
<Typography variant="body1" color="textSecondary">
{t("dashboard:member_count", {
count: community.memberCount,
})}
</Typography>
</StyledCommunityLink>
))}
{communities.hasNextPage && (
<Button
onClick={() => communities.fetchNextPage()}
loading={communities.isFetching}
>
{t("dashboard:load_more")}
</Button>
)}
</>
) : (
<Typography variant="body1" color="textSecondary">
{t("dashboard:no_community")}
</Typography>
))
)}
</div>
);
}
|