Skip to content

Commit 7158fa1

Browse files
authored
Merge pull request #183 from mongodb-developer/interactive_journal
Adding drag and drop feature
2 parents 4a9ec76 + 491735e commit 7158fa1

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

apps/project-assistant/frontend/src/App.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@
349349
box-shadow: 0 0 0 3px rgba(0, 108, 250, 0.1);
350350
}
351351

352+
.entry-input.dragging .entry-input-wrapper {
353+
border-color: var(--mongodb-green);
354+
box-shadow: 0 0 0 3px rgba(0, 237, 100, 0.2);
355+
}
356+
352357
.entry-input input {
353358
flex: 1;
354359
padding: 12px 0;

apps/project-assistant/frontend/src/components/Entry.jsx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function Entry({ messages, onSendMessage, hasActiveProject, activeProject, proje
88
const [searchResults, setSearchResults] = useState(null)
99
const [isSearching, setIsSearching] = useState(false)
1010
const [saveStatus, setSaveStatus] = useState(null)
11+
const [isDragging, setIsDragging] = useState(false)
1112
const messagesEndRef = useRef(null)
1213
const fileInputRef = useRef(null)
1314

@@ -60,17 +61,37 @@ function Entry({ messages, onSendMessage, hasActiveProject, activeProject, proje
6061

6162
const handleFileChange = (e) => {
6263
const files = Array.from(e.target.files || [])
64+
addFiles(files)
65+
e.target.value = ''
66+
}
6367

68+
const addFiles = (files) => {
6469
files.forEach(file => {
65-
setSelectedImages(prev => [...prev, {
66-
file,
67-
preview: URL.createObjectURL(file),
68-
name: file.name
69-
}])
70+
if (file.type.startsWith('image/')) {
71+
setSelectedImages(prev => [...prev, {
72+
file,
73+
preview: URL.createObjectURL(file),
74+
name: file.name
75+
}])
76+
}
7077
})
78+
}
7179

72-
// Reset input so same file can be selected again
73-
e.target.value = ''
80+
const handleDrop = (e) => {
81+
e.preventDefault()
82+
setIsDragging(false)
83+
if (!isV2) return
84+
const files = Array.from(e.dataTransfer.files)
85+
addFiles(files)
86+
}
87+
88+
const handleDragOver = (e) => {
89+
e.preventDefault()
90+
if (isV2) setIsDragging(true)
91+
}
92+
93+
const handleDragLeave = () => {
94+
setIsDragging(false)
7495
}
7596

7697
const removeImage = (index) => {
@@ -214,7 +235,13 @@ function Entry({ messages, onSendMessage, hasActiveProject, activeProject, proje
214235
</div>
215236
)}
216237

217-
<form className="entry-input" onSubmit={handleSubmit}>
238+
<form
239+
className={`entry-input ${isDragging ? 'dragging' : ''}`}
240+
onSubmit={handleSubmit}
241+
onDrop={handleDrop}
242+
onDragOver={handleDragOver}
243+
onDragLeave={handleDragLeave}
244+
>
218245
<div className="entry-input-wrapper">
219246
{isV2 && (
220247
<>

0 commit comments

Comments
 (0)