-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchat-single-message-actions.tsx
More file actions
95 lines (83 loc) · 2.72 KB
/
chat-single-message-actions.tsx
File metadata and controls
95 lines (83 loc) · 2.72 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { useChatStore } from '@/components/providers/chat-store-provider';
import { Separator } from '@/components/ui/separator';
import { WAHL_CHAT_PARTY_ID } from '@/lib/constants';
import type { StreamingMessage } from '@/lib/socket.types';
import type { MessageItem } from '@/lib/stores/chat-store.types';
import ChatMessageLikeDislikeButtons from './chat-message-like-dislike-buttons';
import ChatProConButton from './chat-pro-con-button';
import ChatTtsButton from './chat-tts-button';
import ChatVotingBehaviorSummaryButton from './chat-voting-behavior-summary-button';
import CopyButton from './copy-button';
import SourcesButton from './sources-button';
type Props = {
message: MessageItem | StreamingMessage;
isLastMessage?: boolean;
showMessageActions?: boolean;
partyId?: string;
isGroupChat?: boolean;
};
function ChatSingleMessageActions({
isLastMessage,
message,
showMessageActions,
partyId,
}: Props) {
const isLoadingProConPerspective = useChatStore(
(state) => state.loading.proConPerspective === message.id,
);
const isLoadingVotingBehaviorSummary = useChatStore(
(state) => state.loading.votingBehaviorSummary === message.id,
);
if (!showMessageActions) return null;
const isWahlChatMessage = partyId === WAHL_CHAT_PARTY_ID;
const showProConButton =
partyId &&
!message.pro_con_perspective &&
!isLoadingProConPerspective &&
!isWahlChatMessage;
const showVotingBehaviorSummaryButton =
partyId &&
!message.voting_behavior &&
!isLoadingVotingBehaviorSummary &&
!isWahlChatMessage;
const showSeparator = showProConButton || showVotingBehaviorSummaryButton;
return (
<div className="flex flex-wrap items-center gap-2 text-muted-foreground">
<SourcesButton
sources={message.sources ?? []}
messageContent={message.content ?? ''}
/>
{showProConButton && (
<ChatProConButton
partyId={partyId}
message={message}
isLastMessage={isLastMessage}
/>
)}
{showVotingBehaviorSummaryButton && (
<ChatVotingBehaviorSummaryButton
partyId={partyId}
message={message}
isLastMessage={isLastMessage}
/>
)}
{showSeparator && (
<Separator
orientation="vertical"
className="ml-2 hidden h-6 sm:block"
/>
)}
<div className="flex items-center">
<CopyButton
text={message.content ?? ''}
variant="ghost"
size="icon"
className="size-8"
/>
{partyId && <ChatTtsButton partyId={partyId} messageId={message.id} />}
<ChatMessageLikeDislikeButtons message={message} />
</div>
</div>
);
}
export default ChatSingleMessageActions;