Spaces:
Sleeping
Sleeping
wuyiqunLu
commited on
feat: add loading state on message (#41)
Browse files<img width="1210" alt="image"
src="https://github.com/landing-ai/vision-agent-ui/assets/132986242/0a9fd02e-92a8-466a-af4e-a93406c6d69a">
<img width="1212" alt="Screenshot 2024-05-10 at 23 14 28"
src="https://github.com/landing-ai/vision-agent-ui/assets/132986242/e005388e-85a3-4724-9567-9c5ad6b6d552">
components/chat/ChatList.tsx
CHANGED
|
@@ -10,9 +10,10 @@ import Link from 'next/link';
|
|
| 10 |
export interface ChatList {
|
| 11 |
messages: MessageBase[];
|
| 12 |
session: Session | null;
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
-
export function ChatList({ messages, session }: ChatList) {
|
| 16 |
return (
|
| 17 |
<div className="relative mx-auto max-w-5xl px-8 pr-12">
|
| 18 |
{!session && (
|
|
@@ -52,7 +53,10 @@ export function ChatList({ messages, session }: ChatList) {
|
|
| 52 |
// .filter(message => message.role !== 'system')
|
| 53 |
.map((message, index) => (
|
| 54 |
<div key={index}>
|
| 55 |
-
<ChatMessage
|
|
|
|
|
|
|
|
|
|
| 56 |
{index < messages.length - 1 && (
|
| 57 |
<Separator className="my-4 md:my-8" />
|
| 58 |
)}
|
|
|
|
| 10 |
export interface ChatList {
|
| 11 |
messages: MessageBase[];
|
| 12 |
session: Session | null;
|
| 13 |
+
isLoading: boolean;
|
| 14 |
}
|
| 15 |
|
| 16 |
+
export function ChatList({ messages, session, isLoading }: ChatList) {
|
| 17 |
return (
|
| 18 |
<div className="relative mx-auto max-w-5xl px-8 pr-12">
|
| 19 |
{!session && (
|
|
|
|
| 53 |
// .filter(message => message.role !== 'system')
|
| 54 |
.map((message, index) => (
|
| 55 |
<div key={index}>
|
| 56 |
+
<ChatMessage
|
| 57 |
+
message={message}
|
| 58 |
+
isLoading={isLoading && index === messages.length - 1}
|
| 59 |
+
/>
|
| 60 |
{index < messages.length - 1 && (
|
| 61 |
<Separator className="my-4 md:my-8" />
|
| 62 |
)}
|
components/chat/ChatMessage.tsx
CHANGED
|
@@ -17,12 +17,18 @@ import {
|
|
| 17 |
} from '@/components/ui/Tooltip';
|
| 18 |
import Img from '../ui/Img';
|
| 19 |
import { getCleanedUpMessages } from '@/lib/messageUtils';
|
|
|
|
| 20 |
|
| 21 |
export interface ChatMessageProps {
|
| 22 |
message: MessageBase;
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
-
export function ChatMessage({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
const { logs, content } = useMemo(() => {
|
| 27 |
return getCleanedUpMessages({
|
| 28 |
content: message.content,
|
|
@@ -150,6 +156,7 @@ export function ChatMessage({ message, ...props }: ChatMessageProps) {
|
|
| 150 |
{content}
|
| 151 |
</MemoizedReactMarkdown>
|
| 152 |
{/* <ChatMessageActions message={message} /> */}
|
|
|
|
| 153 |
</div>
|
| 154 |
</div>
|
| 155 |
);
|
|
|
|
| 17 |
} from '@/components/ui/Tooltip';
|
| 18 |
import Img from '../ui/Img';
|
| 19 |
import { getCleanedUpMessages } from '@/lib/messageUtils';
|
| 20 |
+
import Loading from '../ui/Loading';
|
| 21 |
|
| 22 |
export interface ChatMessageProps {
|
| 23 |
message: MessageBase;
|
| 24 |
+
isLoading: boolean;
|
| 25 |
}
|
| 26 |
|
| 27 |
+
export function ChatMessage({
|
| 28 |
+
message,
|
| 29 |
+
isLoading,
|
| 30 |
+
...props
|
| 31 |
+
}: ChatMessageProps) {
|
| 32 |
const { logs, content } = useMemo(() => {
|
| 33 |
return getCleanedUpMessages({
|
| 34 |
content: message.content,
|
|
|
|
| 156 |
{content}
|
| 157 |
</MemoizedReactMarkdown>
|
| 158 |
{/* <ChatMessageActions message={message} /> */}
|
| 159 |
+
{isLoading && <Loading />}
|
| 160 |
</div>
|
| 161 |
</div>
|
| 162 |
);
|
components/chat/index.tsx
CHANGED
|
@@ -24,7 +24,11 @@ export function Chat({ chat, session }: ChatProps) {
|
|
| 24 |
<>
|
| 25 |
<div className="h-full overflow-auto relative" ref={scrollRef}>
|
| 26 |
<div className="pb-[200px] pt-4 md:pt-10" ref={messagesRef}>
|
| 27 |
-
<ChatList
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
<div className="h-px w-full" ref={visibilityRef} />
|
| 29 |
</div>
|
| 30 |
</div>
|
|
|
|
| 24 |
<>
|
| 25 |
<div className="h-full overflow-auto relative" ref={scrollRef}>
|
| 26 |
<div className="pb-[200px] pt-4 md:pt-10" ref={messagesRef}>
|
| 27 |
+
<ChatList
|
| 28 |
+
messages={messages}
|
| 29 |
+
session={session}
|
| 30 |
+
isLoading={isLoading}
|
| 31 |
+
/>
|
| 32 |
<div className="h-px w-full" ref={visibilityRef} />
|
| 33 |
</div>
|
| 34 |
</div>
|
components/project/ProjectChat.tsx
CHANGED
|
@@ -34,7 +34,7 @@ const ProjectChat: React.FC<ChatProps> = ({ mediaList }) => {
|
|
| 34 |
<>
|
| 35 |
<div className="h-full overflow-auto" ref={scrollRef}>
|
| 36 |
<div className="pb-[200px] pt-4 md:pt-10" ref={messagesRef}>
|
| 37 |
-
<ChatList messages={messages} session={null} />
|
| 38 |
<div className="h-px w-full" ref={visibilityRef} />
|
| 39 |
</div>
|
| 40 |
</div>
|
|
|
|
| 34 |
<>
|
| 35 |
<div className="h-full overflow-auto" ref={scrollRef}>
|
| 36 |
<div className="pb-[200px] pt-4 md:pt-10" ref={messagesRef}>
|
| 37 |
+
<ChatList messages={messages} session={null} isLoading={isLoading} />
|
| 38 |
<div className="h-px w-full" ref={visibilityRef} />
|
| 39 |
</div>
|
| 40 |
</div>
|