All files / app/features/press Facts.tsx

100% Statements 21/21
86.66% Branches 13/15
100% Functions 3/3
100% Lines 20/20

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  2x 2x 2x 2x 2x 2x   2x 2x 2x   10x                                       2x           2x                                               10x       10x 10x 10x   10x 10x   10x   10x                                                                                                                                                            
import { Favorite, Language, People, Star } from "@mui/icons-material";
import { Box, Skeleton, styled, Typography } from "@mui/material";
import { useTranslation } from "i18n";
import { localizeRelativeTime } from "i18n/datetimes";
import { LANDING, PRESS } from "i18n/namespaces";
import { Temporal } from "temporal-polyfill";
import useSignupPageInfo from "utils/useSignupPageInfo";
 
import { useListVolunteers } from "../communities/hooks";
import SectionHeading from "./SectionHeading";
import SectionWrapper from "./SectionWrapper";
 
const StyledWrapper = styled(Box)(({ theme }) => ({
  display: "flex",
  flexDirection: "column",
  flexWrap: "wrap",
  gap: "1rem",
  alignItems: "center",
  justifyContent: "center",
  paddingLeft: "1rem",
  paddingRight: "1rem",
  width: "100%",
 
  [theme.breakpoints.up("sm")]: {
    flexDirection: "row",
  },
 
  [theme.breakpoints.up("md")]: {
    gap: "1.5rem",
  },
}));
 
const iconStyle = {
  marginRight: 1,
  fontSize: "30px",
  color: "var(--mui-palette-primary-main)",
};
 
const textStyle = { fontSize: "1.25rem" };
 
type LoaderProps = {
  width: string;
};
 
function Loader({ width }: LoaderProps) {
  return (
    <Box sx={{ width: width }}>
      <Typography sx={textStyle}>
        <Box
          component="span"
          sx={{
            display: "inline-block",
            width: "100%",
          }}
        >
          <Skeleton variant="text" width="100%" />
        </Box>
      </Typography>
    </Box>
  );
}
 
export default function Facts() {
  const {
    t,
    i18n: { language: locale },
  } = useTranslation([LANDING, PRESS]);
  const { signupInfo, isLoading: isSignupInfoLoading } = useSignupPageInfo();
  const volunteers = useListVolunteers();
 
  const currentVolunteersList = volunteers.data?.currentVolunteersList ?? [];
  const pastVolunteersList = volunteers.data?.pastVolunteersList ?? [];
  const volunteersNumber =
    currentVolunteersList.length + pastVolunteersList.length;
 
  const isLoading = isSignupInfoLoading || volunteers.isLoading;
 
  return (
    <SectionWrapper>
      <SectionHeading>{t("press:facts_subheading")}</SectionHeading>
      <StyledWrapper>
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
          }}
        >
          <Favorite sx={iconStyle} />
          {isLoading ? (
            <Loader width="9rem" />
          ) : (
            <Typography sx={textStyle}>
              {t("landing:num_users2", {
                // Number(...) returns NaN on bad input, and || treats it as false
                count: Number(signupInfo?.userCount) || 77000,
              })}
            </Typography>
          )}
        </Box>
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
          }}
        >
          <Language sx={iconStyle} />
          {isLoading ? (
            <Loader width="9.5rem" />
          ) : (
            <Typography sx={textStyle}>
              {t("landing:num_countries2", { count: 180 })}
            </Typography>
          )}
        </Box>
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
          }}
        >
          <Star sx={iconStyle} />
          {isLoading ? (
            <Loader width="14.5rem" />
          ) : signupInfo?.lastSignup ? (
            <Typography sx={textStyle}>
              {t("landing:last_signup", {
                timeAgo: localizeRelativeTime(
                  Temporal.Instant.from(signupInfo.lastSignup),
                  locale,
                ),
              })}
            </Typography>
          ) : null}
        </Box>
        <Box
          sx={{
            display: "flex",
            alignItems: "center",
          }}
        >
          <People sx={iconStyle} />
          {isLoading ? (
            <Loader width="7.5rem" />
          ) : (
            <Typography sx={textStyle}>
              {t("press:num_volunteers", { count: volunteersNumber })}
            </Typography>
          )}
        </Box>
      </StyledWrapper>
    </SectionWrapper>
  );
}