All files / app/features/communities/CommunitiesPage CommunitiesPage.tsx

0% Statements 0/35
0% Branches 0/4
0% Functions 0/10
0% Lines 0/26

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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166                                                                                                                                                                                                                                                                                                                                           
import { ExpandMoreOutlined, ExploreOutlined } from "@mui/icons-material";
import { Button, Collapse, styled, Typography } from "@mui/material";
import MuiLink from "@mui/material/Link";
import PageTitle from "components/PageTitle";
import useAccountInfo from "features/auth/useAccountInfo";
import CommunitiesList from "features/dashboard/CommunitiesList";
import CommunityBrowser from "features/dashboard/CommunityBrowser";
import { Trans, useTranslation } from "i18n";
import { DASHBOARD, GLOBAL } from "i18n/namespaces";
import { useState } from "react";
import {
  communityCreationFormURL,
  helpCenterCommunityBuilderURL,
} from "routes";
 
import NewCommunities from "../NewCommunities";
import CommunitySearch from "./CommunitySearch";
 
const HeaderRow = styled("div")(({ theme }) => ({
  display: "flex",
  justifyContent: "flex-start",
  flexDirection: "column",
  width: "100%",
  paddingBottom: theme.spacing(2),
}));
 
const Subtitle = styled(Typography)(({ theme }) => ({
  fontWeight: "bold",
  fontSize: "1.25rem",
  paddingBottom: theme.spacing(1),
}));
 
const MainTitle = styled(Typography)(({ theme }) => ({
  fontWeight: "bold",
  fontSize: "2rem",
  paddingBottom: theme.spacing(2),
  paddingTop: theme.spacing(2),
}));
 
const StyledTypography = styled(Typography)(({ theme }) => ({
  paddingBlockEnd: theme.spacing(1),
}));
 
const BrowserContainer = styled("div")(({ theme }) => ({
  marginTop: theme.spacing(3),
  padding: theme.spacing(3),
  backgroundColor: "var(--mui-palette-grey-50)",
  borderRadius: theme.spacing(1),
  border: `1px solid var(--mui-palette-divider)`,
}));
 
const BrowserHeader = styled("div")(({ theme }) => ({
  display: "flex",
  alignItems: "center",
  gap: theme.spacing(1),
  marginBottom: theme.spacing(1.5),
}));
 
const BrowserTitle = styled(Typography)(({ theme }) => ({
  fontWeight: 600,
  fontSize: "1rem",
  color: "var(--mui-palette-text-primary)",
}));
 
const ExpandButton = styled(Button)(({ theme }) => ({
  marginTop: theme.spacing(1),
  "& .MuiButton-endIcon": {
    transition: "transform 0.3s",
  },
  "&.expanded .MuiButton-endIcon": {
    transform: "rotate(180deg)",
  },
}));
 
const CommunitiesPage = () => {
  const { t } = useTranslation([GLOBAL, DASHBOARD]);
  const { data: accountInfo } = useAccountInfo();
  const [browserExpanded, setBrowserExpanded] = useState(false);
 
  return (
    <>
      <div>
        <HeaderRow>
          <PageTitle>{t("nav.communities")}</PageTitle>
        </HeaderRow>
      </div>
      <Subtitle variant="h2">
        {t("dashboard:communities_welcome_title")}
      </Subtitle>
      <StyledTypography variant="body1" paragraph>
        <Trans i18nKey="dashboard:communities_intro" />
      </StyledTypography>
      <StyledTypography variant="body1" paragraph>
        <Trans
          i18nKey="dashboard:community_builder"
          components={{
            1: (
              <MuiLink
                href={helpCenterCommunityBuilderURL}
                target="_blank"
                rel="noreferrer noopener"
                underline="hover"
              />
            ),
          }}
        />
      </StyledTypography>
 
      <MainTitle variant="h1">
        {t("dashboard:my_communities_heading")}
      </MainTitle>
      <CommunitiesList />
 
      <MainTitle variant="h1">{t("dashboard:find_your_community")}</MainTitle>
 
      <StyledTypography variant="body1" paragraph>
        <Trans
          i18nKey="dashboard:find_your_community_intro_simplified"
          components={{
            1: (
              <MuiLink
                href={communityCreationFormURL(accountInfo?.username)}
                target="_blank"
                rel="noreferrer noopener"
                underline="hover"
              />
            ),
          }}
        />
      </StyledTypography>
 
      <NewCommunities />
 
      <CommunitySearch />
 
      <BrowserContainer>
        <BrowserHeader>
          <ExploreOutlined color="action" />
          <BrowserTitle>{t("dashboard:browse_all_communities")}</BrowserTitle>
        </BrowserHeader>
 
        <StyledTypography variant="body2" color="textSecondary">
          <Trans i18nKey="dashboard:browse_communities_text" />
        </StyledTypography>
 
        <Collapse in={browserExpanded} timeout="auto">
          <CommunityBrowser />
        </Collapse>
 
        <ExpandButton
          onClick={() => setBrowserExpanded(!browserExpanded)}
          endIcon={<ExpandMoreOutlined />}
          className={browserExpanded ? "expanded" : ""}
          variant="text"
        >
          {browserExpanded
            ? t("dashboard:hide_all_communities")
            : t("dashboard:show_all_communities")}
        </ExpandButton>
      </BrowserContainer>
    </>
  );
};
 
export default CommunitiesPage;