Skip to content

Commit

Permalink
Paste inage to input
Browse files Browse the repository at this point in the history
  • Loading branch information
msveshnikov committed Apr 28, 2024
1 parent f6569a3 commit b87e337
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/components/ChatInput.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Box, TextField, Button } from "@mui/material";
import { Box, TextField, Button, Typography } from "@mui/material";
import FileSelector from "./FileSelector";
import { models } from "./Settings";

Expand All @@ -26,22 +26,36 @@ const ChatInput = ({

return (
<Box display="flex" padding={2}>
<TextField
data-testid="input-field"
fullWidth
label="Enter your question"
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyPress={(e) => {
if (e.key === "Enter") {
onSubmit();
}
}}
multiline
minRows={1}
maxRows={6}
onPaste={handlePaste}
/>
<Box display="flex" flexDirection="column" width="100%">
<TextField
data-testid="input-field"
fullWidth
label="Enter your question"
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyPress={(e) => {
if (e.key === "Enter") {
onSubmit();
}
}}
multiline
minRows={1}
maxRows={6}
onPaste={handlePaste}
/>
{pastedImage && (
<Box mt={2}>
<Typography variant="subtitle2">Pasted Image:</Typography>
<img
src={URL.createObjectURL(pastedImage)}
alt="Pasted"
width="100"
height="100"
style={{ objectFit: "contain" }}
/>
</Box>
)}
</Box>
<FileSelector
onFileSelect={onFileSelect}
allowedFileTypes={models[selectedModel]}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function Main({ darkMode, toggleTheme }) {
const fileData = reader.result;
fileType = fileData.split(";")[0].split("/")[1];
const fileBytesBase64 = fileData.split(",")[1];
setPastedImage(null);
sendFileAndQuery(fileType, fileBytesBase64, input);
};
reader.readAsDataURL(pastedImage || selectedFile);
Expand Down Expand Up @@ -208,6 +209,7 @@ function Main({ darkMode, toggleTheme }) {

setIsModelResponding(false);
setSelectedFile(null);
setPastedImage(null);
};

function removeBrackets(text) {
Expand Down

0 comments on commit b87e337

Please sign in to comment.