Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/components/file-viewer.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,24 @@
display: flex;
flex-direction: column;
}

.dropzone {
border: 2px dashed #cccccc;
border-radius: 8px;
padding: 20px;
text-align: center;
cursor: pointer;
width: 100%;
max-width: 600px;
background-color: #fff;
transition: border-color 0.2s;
}

.dropzone p {
margin: 0;
color: #666666;
}

.dropzone:hover {
border-color: #888888;
}
46 changes: 24 additions & 22 deletions app/components/file-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import React, { useState, useEffect, useCallback } from "react";
import { useDropzone } from "react-dropzone";
import styles from "./file-viewer.module.css";

const TrashIcon = () => (
Expand Down Expand Up @@ -42,17 +43,25 @@ const FileViewer = () => {
method: "DELETE",
body: JSON.stringify({ fileId }),
});
fetchFiles();
};

const handleFileUpload = async (event) => {
const data = new FormData();
if (event.target.files.length < 0) return;
data.append("file", event.target.files[0]);
await fetch("/api/assistants/files", {
method: "POST",
body: data,
});
};
const onDrop = useCallback(async (acceptedFiles) => {
for (const file of acceptedFiles) {
const data = new FormData();
data.append("file", file);
await fetch("/api/assistants/files", {
method: "POST",
body: data,
});
}
fetchFiles();
}, []);

const { getRootProps, getInputProps } = useDropzone({
onDrop,
multiple: true,
});

return (
<div className={styles.fileViewer}>
Expand All @@ -78,20 +87,13 @@ const FileViewer = () => {
)}
</div>
<div className={styles.fileUploadContainer}>
<label htmlFor="file-upload" className={styles.fileUploadBtn}>
Attach files
</label>
<input
type="file"
id="file-upload"
name="file-upload"
className={styles.fileUploadInput}
multiple
onChange={handleFileUpload}
/>
<div {...getRootProps({ className: styles.dropzone })}>
<input {...getInputProps()} />
<p>Drag your files here or click to upload</p>
</div>
</div>
</div>
);
};

export default FileViewer;
export default FileViewer;
59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"openai": "^4.46.0",
"react": "^18",
"react-dom": "^18",
"react-markdown": "^9.0.1"
"react-markdown": "^9.0.1",
"react-dropzone": "^14.2.3"
},
"devDependencies": {
"@types/node": "20.12.7",
Expand Down