mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-12 21:48:51 +01:00
* ✨ feat: Enhance Spinner component with customizable properties and improved animation * 🔧 fix: Replace Loader with Spinner in RunCode component and update FilePreview to use Spinner for progress indication * ✨ feat: Refactor icons in CodeProgress and CancelledIcon components; enhance animation and styling in ExecuteCode and ProgressText components * ✨ feat: Refactor attachment handling in ExecuteCode component; replace individual attachment rendering with AttachmentGroup for improved structure * ✨ feat: Refactor dialog components for improved accessibility and styling; integrate Skeleton loading state in Image component * ✨ feat: Refactor ToolCall component to use ToolCallInfo for better structure; replace ToolPopover with AttachmentGroup; enhance ProgressText with error handling and improved UI elements * 🔧 fix: Remove unnecessary whitespace in ProgressText * 🔧 fix: Remove unnecessary margin from AgentFooter and AgentPanel components; clean up SidePanel imports * ✨ feat: Enhance ToolCall and ToolCallInfo components with improved styling; update translations and add warning text color to Tailwind config * 🔧 fix: Update import statement for useLocalize in ToolCallInfo component; fix: chatform transition * ✨ feat: Refactor ToolCall and ToolCallInfo components for improved structure and styling; add optimized code block for better output display * ✨ feat: Implement OpenAI image generation component; add progress tracking and localization for user feedback * 🔧 fix: Adjust base duration values for image generation; optimize timing for quality settings * chore: remove unnecessary space * ✨ feat: Enhance OpenAI image generation with editing capabilities; update localization for progress feedback * ✨ feat: Add download functionality to images; enhance DialogImage component with download button * ✨ feat: Enhance image resizing functionality; support custom percentage and pixel dimensions in resizeImageBuffer
233 lines
6.8 KiB
TypeScript
233 lines
6.8 KiB
TypeScript
import { useMemo, memo, type FC, useCallback } from 'react';
|
|
import throttle from 'lodash/throttle';
|
|
import { parseISO, isToday } from 'date-fns';
|
|
import { List, AutoSizer, CellMeasurer, CellMeasurerCache } from 'react-virtualized';
|
|
import { useLocalize, TranslationKeys, useMediaQuery } from '~/hooks';
|
|
import { TConversation } from 'librechat-data-provider';
|
|
import { groupConversationsByDate } from '~/utils';
|
|
import { Spinner } from '~/components/svg';
|
|
import Convo from './Convo';
|
|
|
|
interface ConversationsProps {
|
|
conversations: Array<TConversation | null>;
|
|
moveToTop: () => void;
|
|
toggleNav: () => void;
|
|
containerRef: React.RefObject<HTMLDivElement | List>;
|
|
loadMoreConversations: () => void;
|
|
isLoading: boolean;
|
|
isSearchLoading: boolean;
|
|
}
|
|
|
|
const LoadingSpinner = memo(() => {
|
|
const localize = useLocalize();
|
|
|
|
return (
|
|
<div className="mx-auto mt-2 flex items-center justify-center gap-2">
|
|
<Spinner className="text-text-primary" />
|
|
<span className="animate-pulse text-text-primary">{localize('com_ui_loading')}</span>
|
|
</div>
|
|
);
|
|
});
|
|
|
|
const DateLabel: FC<{ groupName: string }> = memo(({ groupName }) => {
|
|
const localize = useLocalize();
|
|
return (
|
|
<div className="mt-2 pl-2 pt-1 text-text-secondary" style={{ fontSize: '0.7rem' }}>
|
|
{localize(groupName as TranslationKeys) || groupName}
|
|
</div>
|
|
);
|
|
});
|
|
|
|
DateLabel.displayName = 'DateLabel';
|
|
|
|
type FlattenedItem =
|
|
| { type: 'header'; groupName: string }
|
|
| { type: 'convo'; convo: TConversation }
|
|
| { type: 'loading' };
|
|
|
|
const MemoizedConvo = memo(
|
|
({
|
|
conversation,
|
|
retainView,
|
|
toggleNav,
|
|
isLatestConvo,
|
|
}: {
|
|
conversation: TConversation;
|
|
retainView: () => void;
|
|
toggleNav: () => void;
|
|
isLatestConvo: boolean;
|
|
}) => {
|
|
return (
|
|
<Convo
|
|
conversation={conversation}
|
|
retainView={retainView}
|
|
toggleNav={toggleNav}
|
|
isLatestConvo={isLatestConvo}
|
|
/>
|
|
);
|
|
},
|
|
(prevProps, nextProps) => {
|
|
return (
|
|
prevProps.conversation.conversationId === nextProps.conversation.conversationId &&
|
|
prevProps.conversation.title === nextProps.conversation.title &&
|
|
prevProps.isLatestConvo === nextProps.isLatestConvo &&
|
|
prevProps.conversation.endpoint === nextProps.conversation.endpoint
|
|
);
|
|
},
|
|
);
|
|
|
|
const Conversations: FC<ConversationsProps> = ({
|
|
conversations: rawConversations,
|
|
moveToTop,
|
|
toggleNav,
|
|
containerRef,
|
|
loadMoreConversations,
|
|
isLoading,
|
|
isSearchLoading,
|
|
}) => {
|
|
const isSmallScreen = useMediaQuery('(max-width: 768px)');
|
|
const convoHeight = isSmallScreen ? 44 : 34;
|
|
|
|
const filteredConversations = useMemo(
|
|
() => rawConversations.filter(Boolean) as TConversation[],
|
|
[rawConversations],
|
|
);
|
|
|
|
const groupedConversations = useMemo(
|
|
() => groupConversationsByDate(filteredConversations),
|
|
[filteredConversations],
|
|
);
|
|
|
|
const firstTodayConvoId = useMemo(
|
|
() =>
|
|
filteredConversations.find((convo) => convo.updatedAt && isToday(parseISO(convo.updatedAt)))
|
|
?.conversationId ?? undefined,
|
|
[filteredConversations],
|
|
);
|
|
|
|
const flattenedItems = useMemo(() => {
|
|
const items: FlattenedItem[] = [];
|
|
groupedConversations.forEach(([groupName, convos]) => {
|
|
items.push({ type: 'header', groupName });
|
|
items.push(...convos.map((convo) => ({ type: 'convo' as const, convo })));
|
|
});
|
|
|
|
if (isLoading) {
|
|
items.push({ type: 'loading' } as any);
|
|
}
|
|
return items;
|
|
}, [groupedConversations, isLoading]);
|
|
|
|
const cache = useMemo(
|
|
() =>
|
|
new CellMeasurerCache({
|
|
fixedWidth: true,
|
|
defaultHeight: convoHeight,
|
|
keyMapper: (index) => {
|
|
const item = flattenedItems[index];
|
|
if (item.type === 'header') {
|
|
return `header-${index}`;
|
|
}
|
|
if (item.type === 'convo') {
|
|
return `convo-${item.convo.conversationId}`;
|
|
}
|
|
if (item.type === 'loading') {
|
|
return `loading-${index}`;
|
|
}
|
|
return `unknown-${index}`;
|
|
},
|
|
}),
|
|
[flattenedItems, convoHeight],
|
|
);
|
|
|
|
const rowRenderer = useCallback(
|
|
({ index, key, parent, style }) => {
|
|
const item = flattenedItems[index];
|
|
if (item.type === 'loading') {
|
|
return (
|
|
<CellMeasurer cache={cache} columnIndex={0} key={key} parent={parent} rowIndex={index}>
|
|
{({ registerChild }) => (
|
|
<div ref={registerChild} style={style}>
|
|
<LoadingSpinner />
|
|
</div>
|
|
)}
|
|
</CellMeasurer>
|
|
);
|
|
}
|
|
return (
|
|
<CellMeasurer cache={cache} columnIndex={0} key={key} parent={parent} rowIndex={index}>
|
|
{({ registerChild }) => (
|
|
<div ref={registerChild} style={style}>
|
|
{item.type === 'header' ? (
|
|
<DateLabel groupName={item.groupName} />
|
|
) : item.type === 'convo' ? (
|
|
<MemoizedConvo
|
|
conversation={item.convo}
|
|
retainView={moveToTop}
|
|
toggleNav={toggleNav}
|
|
isLatestConvo={item.convo.conversationId === firstTodayConvoId}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
)}
|
|
</CellMeasurer>
|
|
);
|
|
},
|
|
[cache, flattenedItems, firstTodayConvoId, moveToTop, toggleNav],
|
|
);
|
|
|
|
const getRowHeight = useCallback(
|
|
({ index }: { index: number }) => cache.getHeight(index, 0),
|
|
[cache],
|
|
);
|
|
|
|
const throttledLoadMore = useMemo(
|
|
() => throttle(loadMoreConversations, 300),
|
|
[loadMoreConversations],
|
|
);
|
|
|
|
const handleRowsRendered = useCallback(
|
|
({ stopIndex }: { stopIndex: number }) => {
|
|
if (stopIndex >= flattenedItems.length - 8) {
|
|
throttledLoadMore();
|
|
}
|
|
},
|
|
[flattenedItems.length, throttledLoadMore],
|
|
);
|
|
|
|
return (
|
|
<div className="relative flex h-full flex-col pb-2 text-sm text-text-primary">
|
|
{isSearchLoading ? (
|
|
<div className="flex flex-1 items-center justify-center">
|
|
<Spinner className="text-text-primary" />
|
|
<span className="ml-2 text-text-primary">Loading...</span>
|
|
</div>
|
|
) : (
|
|
<div className="flex-1">
|
|
<AutoSizer>
|
|
{({ width, height }) => (
|
|
<List
|
|
ref={containerRef as React.RefObject<List>}
|
|
width={width}
|
|
height={height}
|
|
deferredMeasurementCache={cache}
|
|
rowCount={flattenedItems.length}
|
|
rowHeight={getRowHeight}
|
|
rowRenderer={rowRenderer}
|
|
overscanRowCount={10}
|
|
className="outline-none"
|
|
style={{ outline: 'none' }}
|
|
role="list"
|
|
aria-label="Conversations"
|
|
onRowsRendered={handleRowsRendered}
|
|
tabIndex={-1}
|
|
/>
|
|
)}
|
|
</AutoSizer>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default memo(Conversations);
|