diff --git a/apps/web/components/email-list/EmailListItem.tsx b/apps/web/components/email-list/EmailListItem.tsx index a61d789824..dd9399fd34 100644 --- a/apps/web/components/email-list/EmailListItem.tsx +++ b/apps/web/components/email-list/EmailListItem.tsx @@ -21,6 +21,9 @@ import { Button } from "@/components/ui/button"; import { findCtaLink } from "@/utils/parse/parseHtml.client"; import { ErrorBoundary } from "@/components/ErrorBoundary"; import { internalDateToDate } from "@/utils/date"; +import { Badge } from "@/components/ui/badge"; +import { isDefined } from "@/utils/types"; +import { useLabels } from "@/hooks/useLabels"; export const EmailListItem = forwardRef( ( @@ -45,6 +48,7 @@ export const EmailListItem = forwardRef( ref: ForwardedRef, ) => { const { thread, splitView, onSelected } = props; + const { userLabels } = useLabels(); const lastMessage = thread.messages?.[thread.messages.length - 1]; @@ -52,6 +56,17 @@ export const EmailListItem = forwardRef( return lastMessage?.labelIds?.includes("UNREAD"); }, [lastMessage?.labelIds]); + const labelsToDisplay = useMemo(() => { + const labelIds = lastMessage?.labelIds; + return labelIds + ?.map((id) => { + const label = userLabels[Number(id)]; + if (!label) return null; + return { id, name: label.name }; + }) + .filter(isDefined); + }, [lastMessage?.labelIds, userLabels]); + const preventPropagation = useCallback( (e: React.MouseEvent | React.KeyboardEvent) => e.stopPropagation(), [], @@ -138,6 +153,9 @@ export const EmailListItem = forwardRef( )}
{lastMessage.headers.subject} + {labelsToDisplay && labelsToDisplay.length > 0 && ( + + )}
{decodedSnippet} @@ -195,6 +213,9 @@ export const EmailListItem = forwardRef(
{lastMessage.headers.subject} + {labelsToDisplay && labelsToDisplay.length > 0 && ( + + )}
{decodedSnippet} @@ -216,3 +237,25 @@ export const EmailListItem = forwardRef( ); EmailListItem.displayName = "EmailListItem"; + +type Label = { + id: string; + name: string; +}; + +type LabelBadgesProps = { + labels: Label[] | undefined; +}; + +function LabelsDisplay({ labels }: LabelBadgesProps) { + if (!labels || labels.length === 0) return null; + return ( + + {labels.map((label) => ( + + {label.name} + + ))} + + ); +}