From e8813640721baf1b8fccd6c755a47095a8390b10 Mon Sep 17 00:00:00 2001 From: paulclindo Date: Fri, 8 Nov 2024 18:45:28 -0500 Subject: [PATCH] wip file drag support --- .../components/chat/conversation-footer.tsx | 485 ++++++++++-------- 1 file changed, 264 insertions(+), 221 deletions(-) diff --git a/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx b/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx index e11d586b9..a971211b3 100644 --- a/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx +++ b/apps/shinkai-desktop/src/components/chat/conversation-footer.tsx @@ -638,15 +638,19 @@ function ConversationChatFooter({ inboxId }: { inboxId: string }) { }, ); - const { getRootProps: getRootFileProps, getInputProps: getInputFileProps } = - useDropzone({ - multiple: true, - onDrop: (acceptedFiles) => { - const previousFiles = chatForm.getValues('files') ?? []; - const newFiles = [...previousFiles, ...acceptedFiles]; - chatForm.setValue('files', newFiles, { shouldValidate: true }); - }, - }); + const { + getRootProps: getRootFileProps, + getInputProps: getInputFileProps, + isDragActive, + open, + } = useDropzone({ + multiple: true, + onDrop: (acceptedFiles) => { + const previousFiles = chatForm.getValues('files') ?? []; + const newFiles = [...previousFiles, ...acceptedFiles]; + chatForm.setValue('files', newFiles, { shouldValidate: true }); + }, + }); const currentFiles = useWatch({ control: chatForm.control, @@ -749,231 +753,270 @@ function ConversationChatFooter({ inboxId }: { inboxId: string }) { }, [chatForm, inboxId]); return ( -
-
- -
- ( - - - {t('chat.enterMessage')} - - -
-
-
- - - - -
+
+
+ + + ( + + + {t('chat.enterMessage')} + + +
+
+
+ + + + +
- - - - {t('common.uploadFile')} -
- {allowedFileExtensions.join(', ')} -
-
- - - - -
+ )} + onClick={() => { + open(); + }} + type="button" + > + + + + + + + {t('common.uploadFile')} +
+ {allowedFileExtensions.join(', ')} +
+
+ + + + +
- -
+ +
- - {!debounceMessage && ( - - Enter to send - - )} - -
- } - disabled={ - isLoadingMessage || isWorkflowSelectedAndFilesPresent - } - onChange={field.onChange} - onSubmit={chatForm.handleSubmit(onSubmit)} - ref={textareaRef} - topAddons={ - <> - {workflowSelected && ( -
- - - -
- -
- - {formatText(workflowSelected.name)}{' '} - - -{' '} - - {workflowSelected.description} - + +
+ } + disabled={ + isLoadingMessage || isWorkflowSelectedAndFilesPresent + } + onChange={field.onChange} + onSubmit={chatForm.handleSubmit(onSubmit)} + ref={textareaRef} + topAddons={ + <> + + {isDragActive && ( + +
+
+
+ + + + Drop files here to add to your message.
- - - + + )} + + {workflowSelected && ( +
+ + + +
+ +
+ + {formatText(workflowSelected.name)}{' '} + + -{' '} + + {workflowSelected.description} + +
+
+
+ + + {workflowSelected.description} + + +
+
+ +
+ )} + {currentFiles && currentFiles.length > 0 && ( +
+ {currentFiles.map((file, index) => ( +
+ {getFileExt(file.name) && + fileIconMap[getFileExt(file.name)] ? ( + + ) : ( + + )} +
+ + {file.name} + + + {size(file.size)} + +
+ +
+ ))} +
+ )} + + } + value={field.value} + /> + +
+ {!!debounceMessage && + !workflowSelected && + isWorkflowRecommendationsSuccess && + workflowRecommendations?.length > 0 && + workflowRecommendations?.map((workflow) => ( + { - setWorkflowSelected(undefined); + setWorkflowSelected(workflow); }} type="button" > - - -
- )} - {currentFiles && currentFiles.length > 0 && ( -
- {currentFiles.map((file, index) => ( -
- {getFileExt(file.name) && - fileIconMap[getFileExt(file.name)] ? ( - - ) : ( - - )} -
- - {file.name} - - - {size(file.size)} - -
- -
- ))} -
+ + {formatText(workflow.name)} + + ))} + {!debounceMessage && ( + + Shift + Enter{' '} + for a new line + )} - - } - value={field.value} - /> - -
- {!!debounceMessage && - !workflowSelected && - isWorkflowRecommendationsSuccess && - workflowRecommendations?.length > 0 && - workflowRecommendations?.map((workflow) => ( - { - setWorkflowSelected(workflow); - }} - type="button" - > - - {formatText(workflow.name)} - - ))} - {!debounceMessage && ( - - Shift + Enter{' '} - for a new line - - )} -
-
-
- - - )} - /> - +
+ +
+ + + )} + /> + +
);