refactor: replace isLoading with status (#861)
This commit is contained in:
parent
8e561dced4
commit
553a3d825a
10 changed files with 72 additions and 109 deletions
|
|
@ -1,29 +1,26 @@
|
|||
import { PreviewMessage } from './message';
|
||||
import { useScrollToBottom } from './use-scroll-to-bottom';
|
||||
import { Vote } from '@/lib/db/schema';
|
||||
import { ChatRequestOptions, Message } from 'ai';
|
||||
import { Message } from 'ai';
|
||||
import { memo } from 'react';
|
||||
import equal from 'fast-deep-equal';
|
||||
import { UIArtifact } from './artifact';
|
||||
import { UseChatHelpers } from '@ai-sdk/react';
|
||||
|
||||
interface ArtifactMessagesProps {
|
||||
chatId: string;
|
||||
isLoading: boolean;
|
||||
status: UseChatHelpers['status'];
|
||||
votes: Array<Vote> | undefined;
|
||||
messages: Array<Message>;
|
||||
setMessages: (
|
||||
messages: Message[] | ((messages: Message[]) => Message[]),
|
||||
) => void;
|
||||
reload: (
|
||||
chatRequestOptions?: ChatRequestOptions,
|
||||
) => Promise<string | null | undefined>;
|
||||
setMessages: UseChatHelpers['setMessages'];
|
||||
reload: UseChatHelpers['reload'];
|
||||
isReadonly: boolean;
|
||||
artifactStatus: UIArtifact['status'];
|
||||
}
|
||||
|
||||
function PureArtifactMessages({
|
||||
chatId,
|
||||
isLoading,
|
||||
status,
|
||||
votes,
|
||||
messages,
|
||||
setMessages,
|
||||
|
|
@ -43,8 +40,7 @@ function PureArtifactMessages({
|
|||
chatId={chatId}
|
||||
key={message.id}
|
||||
message={message}
|
||||
isLoading={isLoading && index === messages.length - 1}
|
||||
index={index}
|
||||
isLoading={status === 'streaming' && index === messages.length - 1}
|
||||
vote={
|
||||
votes
|
||||
? votes.find((vote) => vote.messageId === message.id)
|
||||
|
|
@ -74,8 +70,8 @@ function areEqual(
|
|||
)
|
||||
return true;
|
||||
|
||||
if (prevProps.isLoading !== nextProps.isLoading) return false;
|
||||
if (prevProps.isLoading && nextProps.isLoading) return false;
|
||||
if (prevProps.status !== nextProps.status) return false;
|
||||
if (prevProps.status && nextProps.status) return false;
|
||||
if (prevProps.messages.length !== nextProps.messages.length) return false;
|
||||
if (!equal(prevProps.votes, nextProps.votes)) return false;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue