Skip to content

Commit

Permalink
Add blinking typing cursing (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonypuppo committed Apr 20, 2023
1 parent f849a2e commit fa3f6e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions components/Chat/ChatLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IconRobot } from '@tabler/icons-react';
import { IconDots } from '@tabler/icons-react';
import { FC } from 'react';

interface Props { }
Expand All @@ -14,7 +13,7 @@ export const ChatLoader: FC<Props> = () => {
<div className="min-w-[40px] items-end">
<IconRobot size={30} />
</div>
<IconDots className="animate-pulse" />
<span className="animate-pulse cursor-default mt-1"></span>
</div>
</div>
);
Expand Down
14 changes: 12 additions & 2 deletions components/Chat/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const ChatMessage: FC<Props> = memo(({ message, messageIndex, onEdit }) =
const { t } = useTranslation('chat');

const {
state: { selectedConversation, conversations, currentMessage },
state: { selectedConversation, conversations, currentMessage, messageIsStreaming },
dispatch: homeDispatch,
} = useContext(HomeContext);

Expand Down Expand Up @@ -215,6 +215,14 @@ export const ChatMessage: FC<Props> = memo(({ message, messageIndex, onEdit }) =
rehypePlugins={[rehypeMathjax]}
components={{
code({ node, inline, className, children, ...props }) {
if (children.length) {
if (children[0] == '▍') {
return <span className="animate-pulse cursor-default mt-1"></span>
}

children[0] = (children[0] as string).replace("`▍`", "▍")
}

const match = /language-(\w+)/.exec(className || '');

return !inline ? (
Expand Down Expand Up @@ -253,7 +261,9 @@ export const ChatMessage: FC<Props> = memo(({ message, messageIndex, onEdit }) =
},
}}
>
{message.content}
{`${message.content}${
messageIsStreaming && messageIndex == (selectedConversation?.messages.length ?? 0) - 1 ? '`▍`' : ''
}`}
</MemoizedReactMarkdown>

<div className="md:-mr-8 ml-1 md:ml-0 flex flex-col md:flex-row gap-4 md:gap-1 items-center md:items-start justify-end md:justify-start">
Expand Down

1 comment on commit fa3f6e9

@vercel
Copy link

@vercel vercel bot commented on fa3f6e9 Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.