Refactor: drag n drop file works on the entire chat screen
This commit is contained in:
parent
0522195a49
commit
975581d97d
4 changed files with 31 additions and 23 deletions
|
|
@ -2,10 +2,6 @@ import { Textarea } from "../../../../../../../components/ui/textarea";
|
||||||
import { classNames } from "../../../../../../../utils/utils";
|
import { classNames } from "../../../../../../../utils/utils";
|
||||||
|
|
||||||
const TextAreaWrapper = ({
|
const TextAreaWrapper = ({
|
||||||
dragOver,
|
|
||||||
dragEnter,
|
|
||||||
dragLeave,
|
|
||||||
onDrop,
|
|
||||||
checkSendingOk,
|
checkSendingOk,
|
||||||
send,
|
send,
|
||||||
lockChat,
|
lockChat,
|
||||||
|
|
@ -54,10 +50,6 @@ const TextAreaWrapper = ({
|
||||||
e.target.style.borderTopWidth = "0";
|
e.target.style.borderTopWidth = "0";
|
||||||
}}
|
}}
|
||||||
onBlur={() => setInputFocus(false)}
|
onBlur={() => setInputFocus(false)}
|
||||||
onDragOver={dragOver}
|
|
||||||
onDragEnter={dragEnter}
|
|
||||||
onDragLeave={dragLeave}
|
|
||||||
onDrop={onDrop}
|
|
||||||
onKeyDown={(event) => {
|
onKeyDown={(event) => {
|
||||||
if (checkSendingOk(event)) {
|
if (checkSendingOk(event)) {
|
||||||
send();
|
send();
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,13 @@ export default function ChatInput({
|
||||||
setChatValue,
|
setChatValue,
|
||||||
inputRef,
|
inputRef,
|
||||||
noInput,
|
noInput,
|
||||||
|
files,
|
||||||
|
setFiles,
|
||||||
|
isDragging,
|
||||||
}: chatInputType): JSX.Element {
|
}: chatInputType): JSX.Element {
|
||||||
const [repeat, setRepeat] = useState(1);
|
const [repeat, setRepeat] = useState(1);
|
||||||
const saveLoading = useFlowsManagerStore((state) => state.saveLoading);
|
const saveLoading = useFlowsManagerStore((state) => state.saveLoading);
|
||||||
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
|
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
|
||||||
const [files, setFiles] = useState<FilePreviewType[]>([]);
|
|
||||||
const [isDragging, setIsDragging] = useState(false);
|
|
||||||
const [inputFocus, setInputFocus] = useState<boolean>(false);
|
const [inputFocus, setInputFocus] = useState<boolean>(false);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
|
@ -40,12 +41,6 @@ export default function ChatInput({
|
||||||
useUpload(uploadFile, currentFlowId, setFiles);
|
useUpload(uploadFile, currentFlowId, setFiles);
|
||||||
const { handleFileChange } = useHandleFileChange(setFiles, currentFlowId);
|
const { handleFileChange } = useHandleFileChange(setFiles, currentFlowId);
|
||||||
|
|
||||||
const { dragOver, dragEnter, dragLeave, onDrop } = useDragAndDrop(
|
|
||||||
setIsDragging,
|
|
||||||
setFiles,
|
|
||||||
currentFlowId,
|
|
||||||
);
|
|
||||||
|
|
||||||
const send = () => {
|
const send = () => {
|
||||||
sendMessage({
|
sendMessage({
|
||||||
repeat,
|
repeat,
|
||||||
|
|
@ -74,10 +69,6 @@ export default function ChatInput({
|
||||||
<div className="flex w-full flex-col-reverse">
|
<div className="flex w-full flex-col-reverse">
|
||||||
<div className="relative w-full">
|
<div className="relative w-full">
|
||||||
<TextAreaWrapper
|
<TextAreaWrapper
|
||||||
dragOver={dragOver}
|
|
||||||
dragEnter={dragEnter}
|
|
||||||
dragLeave={dragLeave}
|
|
||||||
onDrop={onDrop}
|
|
||||||
checkSendingOk={checkSendingOk}
|
checkSendingOk={checkSendingOk}
|
||||||
send={send}
|
send={send}
|
||||||
lockChat={lockChat}
|
lockChat={lockChat}
|
||||||
|
|
@ -119,7 +110,9 @@ export default function ChatInput({
|
||||||
loading={file.loading}
|
loading={file.loading}
|
||||||
key={file.id}
|
key={file.id}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
setFiles((prev) => prev.filter((f) => f.id !== file.id));
|
setFiles((prev: FilePreviewType[]) =>
|
||||||
|
prev.filter((f) => f.id !== file.id),
|
||||||
|
);
|
||||||
// TODO: delete file on backend
|
// TODO: delete file on backend
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,11 @@ import useFlowStore from "../../../../stores/flowStore";
|
||||||
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
||||||
import { VertexBuildTypeAPI, sendAllProps } from "../../../../types/api";
|
import { VertexBuildTypeAPI, sendAllProps } from "../../../../types/api";
|
||||||
import { ChatMessageType, ChatOutputType } from "../../../../types/chat";
|
import { ChatMessageType, ChatOutputType } from "../../../../types/chat";
|
||||||
import { chatViewProps } from "../../../../types/components";
|
import { chatViewProps, FilePreviewType } from "../../../../types/components";
|
||||||
import { classNames } from "../../../../utils/utils";
|
import { classNames } from "../../../../utils/utils";
|
||||||
import ChatInput from "./chatInput";
|
import ChatInput from "./chatInput";
|
||||||
import ChatMessage from "./chatMessage";
|
import ChatMessage from "./chatMessage";
|
||||||
|
import useDragAndDrop from "./chatInput/hooks/use-drag-and-drop";
|
||||||
|
|
||||||
export default function ChatView({
|
export default function ChatView({
|
||||||
sendMessage,
|
sendMessage,
|
||||||
|
|
@ -141,9 +142,23 @@ export default function ChatView({
|
||||||
// return newChatHistory;
|
// return newChatHistory;
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
const [files, setFiles] = useState<FilePreviewType[]>([]);
|
||||||
|
const [isDragging, setIsDragging] = useState(false);
|
||||||
|
|
||||||
|
const { dragOver, dragEnter, dragLeave, onDrop } = useDragAndDrop(
|
||||||
|
setIsDragging,
|
||||||
|
setFiles,
|
||||||
|
currentFlowId,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="eraser-column-arrangement">
|
<div
|
||||||
|
className="eraser-column-arrangement"
|
||||||
|
onDragOver={dragOver}
|
||||||
|
onDragEnter={dragEnter}
|
||||||
|
onDragLeave={dragLeave}
|
||||||
|
onDrop={onDrop}
|
||||||
|
>
|
||||||
<div className="eraser-size">
|
<div className="eraser-size">
|
||||||
<div className="eraser-position">
|
<div className="eraser-position">
|
||||||
<button disabled={lockChat} onClick={() => clearChat()}>
|
<button disabled={lockChat} onClick={() => clearChat()}>
|
||||||
|
|
@ -206,6 +221,9 @@ export default function ChatView({
|
||||||
setChatValue(value);
|
setChatValue(value);
|
||||||
}}
|
}}
|
||||||
inputRef={ref}
|
inputRef={ref}
|
||||||
|
files={files}
|
||||||
|
setFiles={setFiles}
|
||||||
|
isDragging={isDragging}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -485,6 +485,11 @@ export type headerFlowsType = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type chatInputType = {
|
export type chatInputType = {
|
||||||
|
isDragging: boolean;
|
||||||
|
files: FilePreviewType[];
|
||||||
|
setFiles: (
|
||||||
|
files: FilePreviewType[] | ((prev: FilePreviewType[]) => FilePreviewType[]),
|
||||||
|
) => void;
|
||||||
chatValue: string;
|
chatValue: string;
|
||||||
inputRef: {
|
inputRef: {
|
||||||
current: any;
|
current: any;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue