From fa3f6e93bbe0d1ff9f208ddefae6fc7dfb738dc7 Mon Sep 17 00:00:00 2001 From: Anthony Puppo Date: Thu, 20 Apr 2023 10:33:28 -0400 Subject: [PATCH] Add blinking typing cursing (#619) --- components/Chat/ChatLoader.tsx | 3 +-- components/Chat/ChatMessage.tsx | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/components/Chat/ChatLoader.tsx b/components/Chat/ChatLoader.tsx index 1c7bfd2..e666d57 100644 --- a/components/Chat/ChatLoader.tsx +++ b/components/Chat/ChatLoader.tsx @@ -1,5 +1,4 @@ import { IconRobot } from '@tabler/icons-react'; -import { IconDots } from '@tabler/icons-react'; import { FC } from 'react'; interface Props { } @@ -14,7 +13,7 @@ export const ChatLoader: FC = () => {
- + ); diff --git a/components/Chat/ChatMessage.tsx b/components/Chat/ChatMessage.tsx index 467b353..512551f 100644 --- a/components/Chat/ChatMessage.tsx +++ b/components/Chat/ChatMessage.tsx @@ -33,7 +33,7 @@ export const ChatMessage: FC = memo(({ message, messageIndex, onEdit }) = const { t } = useTranslation('chat'); const { - state: { selectedConversation, conversations, currentMessage }, + state: { selectedConversation, conversations, currentMessage, messageIsStreaming }, dispatch: homeDispatch, } = useContext(HomeContext); @@ -215,6 +215,14 @@ export const ChatMessage: FC = memo(({ message, messageIndex, onEdit }) = rehypePlugins={[rehypeMathjax]} components={{ code({ node, inline, className, children, ...props }) { + if (children.length) { + if (children[0] == '▍') { + return + } + + children[0] = (children[0] as string).replace("`▍`", "▍") + } + const match = /language-(\w+)/.exec(className || ''); return !inline ? ( @@ -253,7 +261,9 @@ export const ChatMessage: FC = memo(({ message, messageIndex, onEdit }) = }, }} > - {message.content} + {`${message.content}${ + messageIsStreaming && messageIndex == (selectedConversation?.messages.length ?? 0) - 1 ? '`▍`' : '' + }`}