Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/components/EmailViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function ThreadContent({
autoOpenReplyForMessageId={autoOpenReplyForMessageId}
topRightComponent={topRightComponent}
onSendSuccess={onSendSuccess}
withHeader
/>
)}
</LoadingContent>
Expand Down
18 changes: 11 additions & 7 deletions apps/web/components/email-list/EmailThread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ export function EmailThread({
autoOpenReplyForMessageId,
topRightComponent,
onSendSuccess,
withHeader,
}: {
messages: ThreadMessage[];
refetch: () => void;
showReplyButton: boolean;
autoOpenReplyForMessageId?: string;
topRightComponent?: React.ReactNode;
onSendSuccess?: (messageId: string, threadId: string) => void;
withHeader?: boolean;
}) {
// Place draft messages as replies to their parent message
const organizedMessages = useMemo(() => {
Expand Down Expand Up @@ -50,14 +52,16 @@ export function EmailThread({

return (
<div className="flex-1 overflow-auto bg-muted p-4">
<div className="flex items-center justify-between">
<div className="text-2xl font-semibold text-foreground">
{messages[0]?.headers.subject}
{withHeader && (
<div className="flex items-center justify-between">
<div className="text-2xl font-semibold text-foreground">
{messages[0]?.headers.subject}
</div>
{topRightComponent && (
<div className="flex items-center gap-2">{topRightComponent}</div>
)}
</div>
{topRightComponent && (
<div className="flex items-center gap-2">{topRightComponent}</div>
)}
</div>
)}
Comment on lines +55 to +64
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add null check and improve accessibility.

The header implementation needs some improvements:

  1. Add null check for messages[0] to prevent potential runtime errors
  2. Add semantic HTML and ARIA attributes for better accessibility

Apply this diff to improve the implementation:

-      {withHeader && (
+      {withHeader && messages.length > 0 && (
-        <div className="flex items-center justify-between">
+        <header role="banner" className="flex items-center justify-between">
           <div className="text-2xl font-semibold text-foreground">
-            {messages[0]?.headers.subject}
+            <h1>{messages[0].headers.subject}</h1>
           </div>
           {topRightComponent && (
             <div className="flex items-center gap-2">{topRightComponent}</div>
           )}
-        </div>
+        </header>
       )}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{withHeader && (
<div className="flex items-center justify-between">
<div className="text-2xl font-semibold text-foreground">
{messages[0]?.headers.subject}
</div>
{topRightComponent && (
<div className="flex items-center gap-2">{topRightComponent}</div>
)}
</div>
{topRightComponent && (
<div className="flex items-center gap-2">{topRightComponent}</div>
)}
</div>
)}
{withHeader && messages.length > 0 && (
<header role="banner" className="flex items-center justify-between">
<div className="text-2xl font-semibold text-foreground">
<h1>{messages[0].headers.subject}</h1>
</div>
{topRightComponent && (
<div className="flex items-center gap-2">{topRightComponent}</div>
)}
</header>
)}

<ul className="mt-4 space-y-2 sm:space-y-4">
{organizedMessages.map(({ message, draftMessage }) => {
const defaultShowReply =
Expand Down