Skip to content

Commit

Permalink
feat: MessagePrimitive.If hasContent (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Oct 12, 2024
1 parent aaa4468 commit c85e77a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/react/src/primitive-hooks/message/useMessageIf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type MessageIfFilters = {
lastOrHover: boolean | undefined;
speaking: boolean | undefined;
hasAttachments: boolean | undefined;
hasContent: boolean | undefined;
submittedFeedback: "positive" | "negative" | null | undefined;
};
export type UseMessageIfProps = RequireAtLeastOne<MessageIfFilters>;
Expand All @@ -26,7 +27,15 @@ export const useMessageIf = (props: UseMessageIfProps) => {
return useCombinedStore(
[messageStore, messageUtilsStore],
(
{ role, attachments, branchCount, isLast, speech, submittedFeedback },
{
role,
attachments,
content,
branchCount,
isLast,
speech,
submittedFeedback,
},
{ isCopied, isHovering },
) => {
if (props.hasBranches === true && branchCount < 2) return false;
Expand Down Expand Up @@ -55,9 +64,12 @@ export const useMessageIf = (props: UseMessageIfProps) => {
)
return false;

if (props.hasContent === true && content.length === 0) return false;
if (props.hasContent === false && content.length > 0) return false;

if (
props.submittedFeedback !== undefined &&
( submittedFeedback?.type ?? null) !== props.submittedFeedback
(submittedFeedback?.type ?? null) !== props.submittedFeedback
)
return false;

Expand Down

0 comments on commit c85e77a

Please sign in to comment.