mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-16 04:36:34 +01:00
refactor: optimize ordering of artifacts and activate latest artifact in Artifacts component
This commit is contained in:
parent
4c810fa5db
commit
15068fdfab
1 changed files with 11 additions and 12 deletions
|
|
@ -85,28 +85,27 @@ export default function Artifacts() {
|
||||||
if (orderedArtifactIds.length > 0) {
|
if (orderedArtifactIds.length > 0) {
|
||||||
const latestArtifactId = orderedArtifactIds[orderedArtifactIds.length - 1];
|
const latestArtifactId = orderedArtifactIds[orderedArtifactIds.length - 1];
|
||||||
setCurrentArtifactId(latestArtifactId);
|
setCurrentArtifactId(latestArtifactId);
|
||||||
setActiveTab('code');
|
|
||||||
}
|
}
|
||||||
}, [orderedArtifactIds]);
|
}, [orderedArtifactIds]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (latestMessage?.messageId !== lastRunMessageIdRef.current) {
|
if (isSubmitting && orderedArtifactIds.length > 0) {
|
||||||
const currentArtifact = currentArtifactId != null ? artifacts[currentArtifactId] : null;
|
const latestArtifactId = orderedArtifactIds[orderedArtifactIds.length - 1];
|
||||||
const currentContent = currentArtifact?.content ?? null;
|
const latestArtifact = artifacts[latestArtifactId];
|
||||||
|
|
||||||
if (
|
if (latestArtifact.content !== lastContentRef.current) {
|
||||||
isSubmitting &&
|
setCurrentArtifactId(latestArtifactId);
|
||||||
currentArtifactId != null &&
|
|
||||||
activeTab !== 'code' &&
|
|
||||||
currentContent !== lastContentRef.current
|
|
||||||
) {
|
|
||||||
setActiveTab('code');
|
setActiveTab('code');
|
||||||
lastContentRef.current = currentContent;
|
lastContentRef.current = latestArtifact.content ?? null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}, [isSubmitting, orderedArtifactIds, artifacts]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (latestMessage?.messageId !== lastRunMessageIdRef.current) {
|
||||||
lastRunMessageIdRef.current = latestMessage?.messageId ?? null;
|
lastRunMessageIdRef.current = latestMessage?.messageId ?? null;
|
||||||
}
|
}
|
||||||
}, [activeTab, currentArtifactId, isSubmitting, latestMessage, artifacts]);
|
}, [latestMessage]);
|
||||||
|
|
||||||
const currentArtifact = currentArtifactId != null ? artifacts[currentArtifactId] : null;
|
const currentArtifact = currentArtifactId != null ? artifacts[currentArtifactId] : null;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue