refactor: replace isLoading with status (#861)

This commit is contained in:
Jeremy 2025-03-11 15:33:18 -07:00 committed by GitHub
parent 8e561dced4
commit 553a3d825a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 72 additions and 109 deletions

View file

@ -1,9 +1,4 @@
import type {
Attachment,
ChatRequestOptions,
CreateMessage,
Message,
} from 'ai';
import type { Attachment, Message } from 'ai';
import { formatDistance } from 'date-fns';
import { AnimatePresence, motion } from 'framer-motion';
import {
@ -31,6 +26,7 @@ import { codeArtifact } from '@/artifacts/code/client';
import { sheetArtifact } from '@/artifacts/sheet/client';
import { textArtifact } from '@/artifacts/text/client';
import equal from 'fast-deep-equal';
import { UseChatHelpers } from '@ai-sdk/react';
export const artifactDefinitions = [
textArtifact,
@ -60,7 +56,7 @@ function PureArtifact({
input,
setInput,
handleSubmit,
isLoading,
status,
stop,
attachments,
setAttachments,
@ -73,27 +69,17 @@ function PureArtifact({
}: {
chatId: string;
input: string;
setInput: (input: string) => void;
isLoading: boolean;
stop: () => void;
setInput: UseChatHelpers['setInput'];
status: UseChatHelpers['status'];
stop: UseChatHelpers['stop'];
attachments: Array<Attachment>;
setAttachments: Dispatch<SetStateAction<Array<Attachment>>>;
messages: Array<Message>;
setMessages: Dispatch<SetStateAction<Array<Message>>>;
votes: Array<Vote> | undefined;
append: (
message: Message | CreateMessage,
chatRequestOptions?: ChatRequestOptions,
) => Promise<string | null | undefined>;
handleSubmit: (
event?: {
preventDefault?: () => void;
},
chatRequestOptions?: ChatRequestOptions,
) => void;
reload: (
chatRequestOptions?: ChatRequestOptions,
) => Promise<string | null | undefined>;
append: UseChatHelpers['append'];
handleSubmit: UseChatHelpers['handleSubmit'];
reload: UseChatHelpers['reload'];
isReadonly: boolean;
}) {
const { artifact, setArtifact, metadata, setMetadata } = useArtifact();
@ -326,7 +312,7 @@ function PureArtifact({
<div className="flex flex-col h-full justify-between items-center gap-4">
<ArtifactMessages
chatId={chatId}
isLoading={isLoading}
status={status}
votes={votes}
messages={messages}
setMessages={setMessages}
@ -341,7 +327,7 @@ function PureArtifact({
input={input}
setInput={setInput}
handleSubmit={handleSubmit}
isLoading={isLoading}
status={status}
stop={stop}
attachments={attachments}
setAttachments={setAttachments}
@ -487,7 +473,7 @@ function PureArtifact({
isToolbarVisible={isToolbarVisible}
setIsToolbarVisible={setIsToolbarVisible}
append={append}
isLoading={isLoading}
status={status}
stop={stop}
setMessages={setMessages}
artifactKind={artifact.kind}
@ -513,7 +499,7 @@ function PureArtifact({
}
export const Artifact = memo(PureArtifact, (prevProps, nextProps) => {
if (prevProps.isLoading !== nextProps.isLoading) return false;
if (prevProps.status !== nextProps.status) return false;
if (!equal(prevProps.votes, nextProps.votes)) return false;
if (prevProps.input !== nextProps.input) return false;
if (!equal(prevProps.messages, nextProps.messages.length)) return false;