All files / app/features/messages MessagesHeader.tsx

85% Statements 17/20
37.5% Branches 3/8
100% Functions 4/4
83.33% Lines 15/18

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 541x 1x 1x 1x 1x 1x   1x   2x         2x             1x     2x             2x               2x 2x 2x                        
import { styled } from "@mui/material";
import HtmlMeta from "components/HtmlMeta";
import PageTitle from "components/PageTitle";
import MarkAllReadButton from "features/messages/requests/MarkAllReadButton";
import { useTranslation } from "i18n";
import { MESSAGES } from "i18n/namespaces";
import { MessageType } from "routes";
import { assertNever } from "utils/assertNever";
 
const StyledRoot = styled("div")(({ theme }) => ({
  paddingLeft: theme.spacing(2),
  paddingRight: theme.spacing(2),
}));
 
const StyledHeader = styled("div")(({ theme }) => ({
  display: "flex",
  alignItems: "center",
  gap: theme.spacing(2),
}));
 
// Map tab to MarkAllReadButton type (excluding archived)
const getMarkAllReadType = (
  tab: MessageType,
): "chats" | "hosting" | "surfing" | "all" | null => {
  switch (tab) {
    case "chats":
    case "hosting":
    case "surfing":
      return tab;
    case "all":
    case "unread":
      return "all";
    case "archived":
      return null;
    default:
      return assertNever(tab);
  }
};
 
export default function MessagesHeader({ tab }: { tab: MessageType }) {
  const { t } = useTranslation(MESSAGES);
  const markAllReadType = getMarkAllReadType(tab);
 
  return (
    <StyledRoot>
      <HtmlMeta title={t("messages_page.title")} />
      <StyledHeader>
        <PageTitle>{t("messages_page.title")}</PageTitle>
        {markAllReadType && <MarkAllReadButton type={markAllReadType} />}
      </StyledHeader>
    </StyledRoot>
  );
}