mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 03:10:15 +01:00
21 lines
649 B
TypeScript
21 lines
649 B
TypeScript
|
|
import { useSetRecoilState } from 'recoil';
|
||
|
|
import type { TAttachment, EventSubmission } from 'librechat-data-provider';
|
||
|
|
import store from '~/store';
|
||
|
|
|
||
|
|
export default function useAttachmentHandler() {
|
||
|
|
const setAttachmentsMap = useSetRecoilState(store.messageAttachmentsMap);
|
||
|
|
|
||
|
|
return ({ data }: { data: TAttachment; submission: EventSubmission }) => {
|
||
|
|
const { messageId } = data;
|
||
|
|
|
||
|
|
setAttachmentsMap((prevMap) => {
|
||
|
|
const messageAttachments =
|
||
|
|
(prevMap as Record<string, TAttachment[] | undefined>)[messageId] || [];
|
||
|
|
return {
|
||
|
|
...prevMap,
|
||
|
|
[messageId]: [...messageAttachments, data],
|
||
|
|
};
|
||
|
|
});
|
||
|
|
};
|
||
|
|
}
|