mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 10:50:14 +01:00
27 lines
751 B
TypeScript
27 lines
751 B
TypeScript
|
|
import { useMemo } from 'react';
|
||
|
|
import { useRecoilValue } from 'recoil';
|
||
|
|
import type { TAttachment } from 'librechat-data-provider';
|
||
|
|
import { useSearchResultsByTurn } from './useSearchResultsByTurn';
|
||
|
|
import store from '~/store';
|
||
|
|
|
||
|
|
export default function useAttachments({
|
||
|
|
messageId,
|
||
|
|
attachments,
|
||
|
|
}: {
|
||
|
|
messageId?: string;
|
||
|
|
attachments?: TAttachment[];
|
||
|
|
}) {
|
||
|
|
const messageAttachmentsMap = useRecoilValue(store.messageAttachmentsMap);
|
||
|
|
const messageAttachments = useMemo(
|
||
|
|
() => attachments ?? messageAttachmentsMap[messageId ?? ''] ?? [],
|
||
|
|
[attachments, messageAttachmentsMap, messageId],
|
||
|
|
);
|
||
|
|
|
||
|
|
const searchResults = useSearchResultsByTurn(messageAttachments);
|
||
|
|
|
||
|
|
return {
|
||
|
|
attachments: messageAttachments,
|
||
|
|
searchResults,
|
||
|
|
};
|
||
|
|
}
|