-
Notifications
You must be signed in to change notification settings - Fork 900
fixed #348 #396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fixed #348 #396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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,13 +48,25 @@ export const EmailListItem = forwardRef( | |||||||||||||||||||||||||||||||||||||||||
ref: ForwardedRef<HTMLLIElement>, | ||||||||||||||||||||||||||||||||||||||||||
) => { | ||||||||||||||||||||||||||||||||||||||||||
const { thread, splitView, onSelected } = props; | ||||||||||||||||||||||||||||||||||||||||||
const { userLabels } = useLabels(); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const lastMessage = thread.messages?.[thread.messages.length - 1]; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const isUnread = useMemo(() => { | ||||||||||||||||||||||||||||||||||||||||||
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]); | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+59
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the label lookup logic. The current implementation treats const labelsToDisplay = useMemo(() => {
const labelIds = lastMessage?.labelIds;
return labelIds
?.map((id) => {
- const label = userLabels[Number(id)];
+ const label = userLabels.find(label => label.id === id);
if (!label) return null;
return { id, name: label.name };
})
.filter(isDefined);
}, [lastMessage?.labelIds, userLabels]); 📝 Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain@elie222 I see the CodeRabbit suggestion about the label lookup logic. Let me investigate the actual implementation of the 🏁 Script executed:
Length of output: 61 🏁 Script executed:
Length of output: 878 🏁 Script executed:
Length of output: 28833 @elie222 You're right to point this out! After examining the The current implementation in the diff is incorrect because:
CodeRabbit's suggested fix is correct: const label = userLabels.find(label => label.id === id); This properly searches through the array to find a label object whose The current code would likely return 🏁 Script executed:
Length of output: 2124 Perfect! Now I can see the complete picture. The Here's the definitive analysis: The ProblemThe current code: const label = userLabels[Number(id)]; This is wrong because:
The Correct SolutionCodeRabbit's suggestion is the proper way to find labels: const label = userLabels.find(label => label.id === id); This correctly:
ImpactThe current incorrect implementation would cause:
CodeRabbit's suggestion should definitely be applied to fix the label display functionality in the email list. 🧬 Code Graph Analysis ResultsRelevant snippets for understanding
|
||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const preventPropagation = useCallback( | ||||||||||||||||||||||||||||||||||||||||||
(e: React.MouseEvent | React.KeyboardEvent) => e.stopPropagation(), | ||||||||||||||||||||||||||||||||||||||||||
[], | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -138,6 +153,9 @@ export const EmailListItem = forwardRef( | |||||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||||||
<div className="ml-2 min-w-0 overflow-hidden text-foreground"> | ||||||||||||||||||||||||||||||||||||||||||
{lastMessage.headers.subject} | ||||||||||||||||||||||||||||||||||||||||||
{labelsToDisplay && labelsToDisplay.length > 0 && ( | ||||||||||||||||||||||||||||||||||||||||||
<LabelsDisplay labels={labelsToDisplay} /> | ||||||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||
<div className="ml-4 mr-6 flex flex-1 items-center overflow-hidden truncate font-normal leading-5 text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||||||
{decodedSnippet} | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -195,6 +213,9 @@ export const EmailListItem = forwardRef( | |||||||||||||||||||||||||||||||||||||||||
<div className="mt-1.5 whitespace-nowrap text-sm leading-6"> | ||||||||||||||||||||||||||||||||||||||||||
<div className="min-w-0 overflow-hidden font-medium text-foreground"> | ||||||||||||||||||||||||||||||||||||||||||
{lastMessage.headers.subject} | ||||||||||||||||||||||||||||||||||||||||||
{labelsToDisplay && labelsToDisplay.length > 0 && ( | ||||||||||||||||||||||||||||||||||||||||||
<LabelsDisplay labels={labelsToDisplay} /> | ||||||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||||||||||||||
<div className="mr-6 mt-0.5 flex flex-1 items-center overflow-hidden truncate pl-1 font-normal leading-5 text-muted-foreground"> | ||||||||||||||||||||||||||||||||||||||||||
{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 ( | ||||||||||||||||||||||||||||||||||||||||||
<span className="ml-2 inline-flex flex-wrap items-center gap-1"> | ||||||||||||||||||||||||||||||||||||||||||
{labels.map((label) => ( | ||||||||||||||||||||||||||||||||||||||||||
<Badge variant="secondary" key={label.id} className="text-xs"> | ||||||||||||||||||||||||||||||||||||||||||
{label.name} | ||||||||||||||||||||||||||||||||||||||||||
</Badge> | ||||||||||||||||||||||||||||||||||||||||||
))} | ||||||||||||||||||||||||||||||||||||||||||
</span> | ||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we convert to number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise it will be of type any and typescript complains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't make sense. something hacky going on here.