File size: 1,424 Bytes
246d201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from "react";
import { ChatMessage } from "#/components/features/chat/chat-message";
import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons";
import { ImageCarousel } from "../images/image-carousel";
import { ExpandableMessage } from "./expandable-message";

interface MessagesProps {
  messages: Message[];
  isAwaitingUserConfirmation: boolean;
}

export const Messages: React.FC<MessagesProps> = React.memo(
  ({ messages, isAwaitingUserConfirmation }) =>
    messages.map((message, index) => {
      if (message.type === "error" || message.type === "action") {
        return (
          <ExpandableMessage

            key={index}

            type={message.type}

            id={message.translationID}

            message={message.content}

            success={message.success}

          />
        );
      }

      return (
        <ChatMessage

          key={index}

          type={message.sender}

          message={message.content}

        >

          {message.imageUrls && message.imageUrls.length > 0 && (

            <ImageCarousel size="small" images={message.imageUrls} />

          )}

          {messages.length - 1 === index &&

            message.sender === "assistant" &&

            isAwaitingUserConfirmation && <ConfirmationButtons />}

        </ChatMessage>
      );
    }),
);

Messages.displayName = "Messages";