All files / app/features/messages ThreadTitleRow.tsx

100% Statements 9/9
60% Branches 3/5
100% Functions 4/4
100% Lines 8/8

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 423x 3x   3x   13x                   3x 29x 13x                               13x                
import { styled } from "@mui/material";
import RelativeTime from "components/RelativeTime";
import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb";
import React from "react";
 
const StyledRow = styled("span")(({ theme }) => ({
  display: "flex",
  alignItems: "baseline",
  gap: theme.spacing(1),
  // lets the title truncate instead of pushing the time off the row
  "& > :first-of-type": {
    minWidth: 0,
  },
}));
 
const StyledRelativeTime = styled(RelativeTime, {
  shouldForwardProp: (prop) => prop !== "isUnread",
})<{ isUnread: boolean }>(({ theme, isUnread }) => ({
  ...theme.typography.caption,
  flexShrink: 0,
  marginInlineStart: "auto",
  whiteSpace: "nowrap",
  color: isUnread ? "var(--mui-palette-text-primary)" : "var(--mui-palette-text-secondary)",
  fontWeight: isUnread ? "bold" : "normal",
}));
 
interface ThreadTitleRowProps {
  children: React.ReactNode;
  latestMessageTime?: Timestamp.AsObject;
  isUnread: boolean;
}
 
/** A message list row's title, with the time of its latest message (which the list is ordered by). */
export default function ThreadTitleRow({ children, latestMessageTime, isUnread }: ThreadTitleRowProps) {
  return (
    <StyledRow>
      {children}
      {latestMessageTime && <StyledRelativeTime instant={latestMessageTime} isUnread={isUnread} />}
    </StyledRow>
  );
}