From 29e01721c94e036916c374556a172fd1b52c1f91 Mon Sep 17 00:00:00 2001 From: Ahmad Hassan <76843311+ah7255703@users.noreply.github.com> Date: Sun, 5 Nov 2023 15:18:30 +0200 Subject: [PATCH] fix: Fix error handling in ChatScreen --- copilot-widget/lib/components/Messages.tsx | 48 +++++++++++++++------- copilot-widget/lib/screens/ChatScreen.tsx | 8 ++-- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/copilot-widget/lib/components/Messages.tsx b/copilot-widget/lib/components/Messages.tsx index 5a2369d1e..2f8846072 100644 --- a/copilot-widget/lib/components/Messages.tsx +++ b/copilot-widget/lib/components/Messages.tsx @@ -7,6 +7,10 @@ import { FaRegUserCircle } from "react-icons/fa"; import { format } from "timeago.js"; import cn from "../utils/cn"; import formatTimeFromTimestamp from "../utils/formatTime"; +import { useCopyToClipboard } from "@lib/hooks/useCopy"; +import { HiOutlineClipboard, HiOutlineClipboardCheck } from "react-icons/hi"; +import { FailedMessage, useChat } from "@lib/contexts/Controller"; +import { getLast } from "@lib/utils/utils"; function BotIcon({ error }: { error?: boolean }) { return ( +
@@ -63,15 +71,27 @@ export function BotTextMessage({
-
-
- {timestamp && ( - - Bot · {format(timestamp)} - - )} + {isLast && ( +
+
+ {timestamp && ( + + Bot · {format(timestamp)} + + )} +
+
-
+ )}
); } @@ -105,11 +125,12 @@ export function UserMessage({ }: { content: string; timestamp?: number; + id?: string; }) { return (
@@ -128,12 +149,11 @@ export function UserMessage({ ); } -export function BotMessageError() { +export function BotMessageError({ message }: { message?: FailedMessage }) { const { displayText } = useTypeWriter({ text: "Error sending the message.", every: 0.001, }); - return (
diff --git a/copilot-widget/lib/screens/ChatScreen.tsx b/copilot-widget/lib/screens/ChatScreen.tsx index fb456ccfe..57cfca29a 100644 --- a/copilot-widget/lib/screens/ChatScreen.tsx +++ b/copilot-widget/lib/screens/ChatScreen.tsx @@ -15,7 +15,7 @@ import { Map } from "../utils/Map"; function ChatScreen() { const scrollElementRef = useRef(null); const [setPos] = useScrollToPercentage(scrollElementRef); - const { messages, loading, error } = useChat(); + const { messages, loading, failedMessage } = useChat(); const config = useConfigData(); const initialMessage = config?.initialMessage; useEffect(() => { @@ -32,7 +32,7 @@ function ChatScreen() {
{ @@ -48,6 +48,7 @@ function ChatScreen() { return ( @@ -56,6 +57,7 @@ function ChatScreen() { return ( @@ -64,7 +66,7 @@ function ChatScreen() { }} /> {loading && } - {error && } + {failedMessage && }