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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 1x 1x 6x 4x 4x 4x 4x 4x 6x 1x | import { Groups } from "@mui/icons-material";
import { styled, Typography, TypographyProps, useMediaQuery, useTheme } from "@mui/material";
import Alert from "components/Alert";
import CardTrack, { useCardTrack } from "components/CardTrack";
import StyledLink from "components/StyledLink";
import TextBody from "components/TextBody";
import { Trans, useTranslation } from "i18n";
import { DASHBOARD } from "i18n/namespaces";
import { Community } from "proto/communities_pb";
import { routeToCommunity } from "routes";
import DashboardSectionHeader from "./DashboardSectionHeader";
interface CommunitiesListProps {
communities: Community.AsObject[];
isLoading: boolean;
error?: string;
}
const CARD_WIDTH = 200;
const StyledBrowseCommunitiesLink = styled(StyledLink)(() => ({
verticalAlign: "baseline",
}));
const CommunityCard = styled(StyledLink)(({ theme }) => ({
display: "flex",
flexDirection: "column",
padding: theme.spacing(1.5),
border: "1px solid var(--mui-palette-divider)",
borderRadius: 10,
background: "var(--mui-palette-background-paper)",
transition: "border-color 0.2s, box-shadow 0.2s",
"&:hover": {
borderColor: "var(--mui-palette-primary-main)",
boxShadow: "0 2px 8px rgba(0,0,0,0.08)",
},
}));
const CommunityName = styled(Typography)<TypographyProps>({
fontWeight: 600,
display: "-webkit-box",
WebkitLineClamp: 2,
WebkitBoxOrient: "vertical",
overflow: "hidden",
textOverflow: "ellipsis",
overflowWrap: "anywhere",
});
const SkeletonCard = styled("div")(({ theme }) => ({
padding: theme.spacing(1.5),
border: "1px solid var(--mui-palette-divider)",
borderRadius: 10,
background: "var(--mui-palette-background-paper)",
}));
export default function CommunitiesList({ communities, isLoading, error }: CommunitiesListProps) {
const { t } = useTranslation([DASHBOARD]);
const theme = useTheme();
const cardsPerView = useMediaQuery(theme.breakpoints.down("sm")) ? 2 : 3;
const track = useCardTrack({ maxCardsPerScroll: 3 });
return (
<div>
<DashboardSectionHeader icon={Groups} title={t("dashboard:your_communities_heading")} {...track.navProps} />
<Typography variant="body1" sx={{ paddingBottom: theme.spacing(2) }}>
<Trans
i18nKey="dashboard:communities_intro"
components={{
browseCommunitiesLink: <StyledBrowseCommunitiesLink href="/communities" underline="hover" />,
}}
/>
</Typography>
{error && <Alert severity="error">{error}</Alert>}
{isLoading ? (
<CardTrack cardWidth={CARD_WIDTH}>
{Array.from({ length: cardsPerView }).map((_, i) => (
<SkeletonCard key={i} />
))}
</CardTrack>
) : communities.length > 0 ? (
<CardTrack track={track} cardWidth={CARD_WIDTH}>
{communities.map((community) => (
<CommunityCard
key={`community-${community.communityId}`}
href={routeToCommunity(community.communityId, community.slug)}
>
<CommunityName variant="subtitle2" component="span">
{community.name}
</CommunityName>
<Typography variant="body2" color="textSecondary">
{t("dashboard:member_count", {
count: community.memberCount,
})}
</Typography>
</CommunityCard>
))}
</CardTrack>
) : (
<TextBody>{t("dashboard:no_community")}</TextBody>
)}
</div>
);
}
|