Skip to content

Commit fa3f6e9

Browse files
authored
Add blinking typing cursing (#619)
1 parent f849a2e commit fa3f6e9

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

components/Chat/ChatLoader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { IconRobot } from '@tabler/icons-react';
2-
import { IconDots } from '@tabler/icons-react';
32
import { FC } from 'react';
43

54
interface Props { }
@@ -14,7 +13,7 @@ export const ChatLoader: FC<Props> = () => {
1413
<div className="min-w-[40px] items-end">
1514
<IconRobot size={30} />
1615
</div>
17-
<IconDots className="animate-pulse" />
16+
<span className="animate-pulse cursor-default mt-1"></span>
1817
</div>
1918
</div>
2019
);

components/Chat/ChatMessage.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const ChatMessage: FC<Props> = memo(({ message, messageIndex, onEdit }) =
3333
const { t } = useTranslation('chat');
3434

3535
const {
36-
state: { selectedConversation, conversations, currentMessage },
36+
state: { selectedConversation, conversations, currentMessage, messageIsStreaming },
3737
dispatch: homeDispatch,
3838
} = useContext(HomeContext);
3939

@@ -215,6 +215,14 @@ export const ChatMessage: FC<Props> = memo(({ message, messageIndex, onEdit }) =
215215
rehypePlugins={[rehypeMathjax]}
216216
components={{
217217
code({ node, inline, className, children, ...props }) {
218+
if (children.length) {
219+
if (children[0] == '▍') {
220+
return <span className="animate-pulse cursor-default mt-1"></span>
221+
}
222+
223+
children[0] = (children[0] as string).replace("`▍`", "▍")
224+
}
225+
218226
const match = /language-(\w+)/.exec(className || '');
219227

220228
return !inline ? (
@@ -253,7 +261,9 @@ export const ChatMessage: FC<Props> = memo(({ message, messageIndex, onEdit }) =
253261
},
254262
}}
255263
>
256-
{message.content}
264+
{`${message.content}${
265+
messageIsStreaming && messageIndex == (selectedConversation?.messages.length ?? 0) - 1 ? '`▍`' : ''
266+
}`}
257267
</MemoizedReactMarkdown>
258268

259269
<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">

0 commit comments

Comments
 (0)