refactor: replace isLoading with status (#861)
This commit is contained in:
parent
8e561dced4
commit
553a3d825a
10 changed files with 72 additions and 109 deletions
|
|
@ -319,19 +319,16 @@ const PureToolbar = ({
|
|||
isToolbarVisible,
|
||||
setIsToolbarVisible,
|
||||
append,
|
||||
isLoading,
|
||||
status,
|
||||
stop,
|
||||
setMessages,
|
||||
artifactKind,
|
||||
}: {
|
||||
isToolbarVisible: boolean;
|
||||
setIsToolbarVisible: Dispatch<SetStateAction<boolean>>;
|
||||
isLoading: boolean;
|
||||
append: (
|
||||
message: Message | CreateMessage,
|
||||
chatRequestOptions?: ChatRequestOptions,
|
||||
) => Promise<string | null | undefined>;
|
||||
stop: () => void;
|
||||
status: UseChatHelpers['status'];
|
||||
append: UseChatHelpers['append'];
|
||||
stop: UseChatHelpers['stop'];
|
||||
setMessages: Dispatch<SetStateAction<Message[]>>;
|
||||
artifactKind: ArtifactKind;
|
||||
}) => {
|
||||
|
|
@ -372,10 +369,10 @@ const PureToolbar = ({
|
|||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading) {
|
||||
if (status === 'streaming') {
|
||||
setIsToolbarVisible(false);
|
||||
}
|
||||
}, [isLoading, setIsToolbarVisible]);
|
||||
}, [status, setIsToolbarVisible]);
|
||||
|
||||
const artifactDefinition = artifactDefinitions.find(
|
||||
(definition) => definition.kind === artifactKind,
|
||||
|
|
@ -418,13 +415,13 @@ const PureToolbar = ({
|
|||
exit={{ opacity: 0, y: -20, transition: { duration: 0.1 } }}
|
||||
transition={{ type: 'spring', stiffness: 300, damping: 25 }}
|
||||
onHoverStart={() => {
|
||||
if (isLoading) return;
|
||||
if (status === 'streaming') return;
|
||||
|
||||
cancelCloseTimer();
|
||||
setIsToolbarVisible(true);
|
||||
}}
|
||||
onHoverEnd={() => {
|
||||
if (isLoading) return;
|
||||
if (status === 'streaming') return;
|
||||
|
||||
startCloseTimer();
|
||||
}}
|
||||
|
|
@ -436,7 +433,7 @@ const PureToolbar = ({
|
|||
}}
|
||||
ref={toolbarRef}
|
||||
>
|
||||
{isLoading ? (
|
||||
{status === 'streaming' ? (
|
||||
<motion.div
|
||||
key="stop-icon"
|
||||
initial={{ scale: 1 }}
|
||||
|
|
@ -475,7 +472,7 @@ const PureToolbar = ({
|
|||
};
|
||||
|
||||
export const Toolbar = memo(PureToolbar, (prevProps, nextProps) => {
|
||||
if (prevProps.isLoading !== nextProps.isLoading) return false;
|
||||
if (prevProps.status !== nextProps.status) return false;
|
||||
if (prevProps.isToolbarVisible !== nextProps.isToolbarVisible) return false;
|
||||
if (prevProps.artifactKind !== nextProps.artifactKind) return false;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue