All files / app/features/communities CommunityBase.tsx

100% Statements 14/14
66.66% Branches 4/6
100% Functions 2/2
100% Lines 12/12

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 367x 7x 7x 7x 7x 7x   7x             51x             104x 110x   110x       110x              
import { styled } from "@mui/material";
import Alert from "components/Alert";
import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner";
import { useCommunity } from "features/communities/hooks";
import { useTranslation } from "i18n";
import { COMMUNITIES } from "i18n/namespaces";
import { Community } from "proto/communities_pb";
import React from "react";
 
interface CommunityBaseProps {
  children(communityParams: { community: Community.AsObject }): React.ReactNode;
  communityId: number;
}
 
const StyledWrapper = styled("div")(({ theme }) => ({
  marginBottom: theme.spacing(2),
  "& > section": {
    margin: theme.spacing(3, 0),
  },
}));
 
export default function CommunityBase({ children, communityId }: CommunityBaseProps) {
  const { t } = useTranslation([COMMUNITIES]);
 
  const { isLoading: isCommunityLoading, error: communityError, data: community } = useCommunity(communityId);
 
  if (!communityId) return <Alert severity="error">{t("communities:invalid_community_id")}</Alert>;
 
  if (isCommunityLoading) return <CenteredSpinner />;
 
  if (!community || communityError)
    return <Alert severity="error">{communityError?.message || t("communities:error_loading_community")}</Alert>;
 
  return <StyledWrapper>{children({ community })}</StyledWrapper>;
}