All files / app/features/communities/events LongEventCard.tsx

100% Statements 22/22
100% Branches 9/9
100% Functions 2/2
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 155 156 157 158 159 160 161 162 163              3x 3x 3x 3x 3x 3x   3x 3x 3x 3x 3x   4x                                                                                                                                       3x             51x     51x   51x 51x 51x 51x                                                                                                                   51x  
import {
  Card,
  CardContent,
  CardMedia,
  Theme,
  Tooltip,
  Typography,
} from "@mui/material";
import { eventImagePlaceholderUrl } from "appConstants";
import Pill from "components/Pill";
import { useTranslation } from "i18n";
import { COMMUNITIES } from "i18n/namespaces";
import Link from "next/link";
import { Event } from "proto/events_pb";
import { routeToEvent } from "routes";
import { theme } from "theme";
import { timestamp2Date } from "utils/date";
import dayjs from "utils/dayjs";
import makeStyles from "utils/makeStyles";
 
const useStyles = makeStyles((theme: Theme) => ({
  root: {
    margin: 0,
    "&:not(:first-child)": {
      margin: theme.spacing(2, 0),
    },
    border: `1px solid ${theme.palette.grey[300]}`,
    borderRadius: theme.spacing(1),
 
    "&:hover": {
      backgroundColor: theme.palette.grey[50],
    },
  },
  attendees: {
    display: "flex",
    alignItems: "flex-end",
    justifyContent: "flex-end",
    minWidth: theme.spacing(10),
    fontSize: ".85rem",
    color: theme.palette.text.secondary,
  },
  card: {
    display: "flex",
    width: "100%",
    height: theme.spacing(20),
    [theme.breakpoints.down("sm")]: {
      height: "auto",
    },
  },
  cardMedia: {
    height: "100%",
    width: "25%",
    objectFit: "fill",
  },
  cardContent: {
    width: "75%",
    display: "flex",
    flexDirection: "column",
    justifyContent: "space-between",
  },
  eventInfo: {
    display: "flex",
    justifyContent: "flex-end",
    flexDirection: "column",
    fontSize: ".85rem",
  },
  row: {
    display: "flex",
    justifyContent: "space-between",
  },
  tags: {
    minWidth: theme.spacing(15),
    [theme.breakpoints.down("sm")]: {
      minWidth: theme.spacing(10),
    },
  },
  title: {
    display: "-webkit-box",
    lineClamp: 2,
    boxOrient: "vertical",
    overflow: "hidden",
    textOverflow: "ellipsis",
    maxHeight: "3em" /* Approximate height for 2 lines of text */,
    lineHeight: "1.5em",
    paddingRight: theme.spacing(2),
  },
}));
 
const LongEventCard = ({
  event,
  userId,
}: {
  event: Event.AsObject;
  userId: number | null | undefined;
}) => {
  const classes = useStyles({
    eventImageSrc: event.photoUrl || eventImagePlaceholderUrl,
  });
  const { t } = useTranslation([COMMUNITIES]);
 
  const startTime = dayjs(timestamp2Date(event.startTime!)).format("llll");
  const isCreatedByMe = event.creatorUserId === userId;
  const isOnline = event.onlineInformation?.link !== undefined;
  const isCancelled = event.isCancelled;
 
  return (
    <Card className={classes.root} data-testid="event-item">
      <Link
        href={routeToEvent(event.eventId, event.slug)}
        className={classes.card}
      >
        <CardMedia
          className={classes.cardMedia}
          component="img"
          image={event.photoUrl || eventImagePlaceholderUrl}
        />
        <CardContent className={classes.cardContent}>
          <div className={classes.row}>
            <Tooltip title={event.title}>
              <Typography variant="h3" className={classes.title}>
                {event.title}
              </Typography>
            </Tooltip>
            <div className={classes.tags}>
              {isCreatedByMe && (
                <Pill variant="rounded">{t("communities:created_by_me")}</Pill>
              )}
              {isOnline && (
                <Pill variant="rounded">{t("communities:online")}</Pill>
              )}
              {isCancelled && (
                <Pill
                  backgroundColor={theme.palette.error.main}
                  color={theme.palette.common.white}
                  variant="rounded"
                >
                  {t("communities:cancelled")}
                </Pill>
              )}
            </div>
          </div>
          <div className={classes.row}>
            <div className={classes.eventInfo}>
              {event.offlineInformation
                ? event.offlineInformation.address
                : t("communities:virtual_event_location_placeholder")}
 
              <div>{startTime}</div>
            </div>
            <div className={classes.attendees}>
              {t("communities:attendees_count", {
                count: event.goingCount + event.maybeCount,
              })}
            </div>
          </div>
        </CardContent>
      </Link>
    </Card>
  );
};
 
export default LongEventCard;