Skip to content

Commit 3f77cb2

Browse files
authored
Merge pull request #2684 from GuilhermeJSilva/fix/highlight-folder-on-hover
Dragged note highlighting
2 parents 7c839a1 + 4061866 commit 3f77cb2

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

browser/main/SideNav/StorageItem.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class StorageItem extends React.Component {
2525
const { storage } = this.props
2626

2727
this.state = {
28-
isOpen: !!storage.isOpen
28+
isOpen: !!storage.isOpen,
29+
draggedOver: null
2930
}
3031
}
3132

@@ -245,14 +246,20 @@ class StorageItem extends React.Component {
245246
}
246247
}
247248

248-
handleDragEnter (e) {
249-
e.dataTransfer.setData('defaultColor', e.target.style.backgroundColor)
250-
e.target.style.backgroundColor = 'rgba(129, 130, 131, 0.08)'
249+
handleDragEnter (e, key) {
250+
e.preventDefault()
251+
if (this.state.draggedOver === key) { return }
252+
this.setState({
253+
draggedOver: key
254+
})
251255
}
252256

253257
handleDragLeave (e) {
254-
e.target.style.opacity = '1'
255-
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
258+
e.preventDefault()
259+
if (this.state.draggedOver === null) { return }
260+
this.setState({
261+
draggedOver: null
262+
})
256263
}
257264

258265
dropNote (storage, folder, dispatch, location, noteData) {
@@ -277,8 +284,12 @@ class StorageItem extends React.Component {
277284
}
278285

279286
handleDrop (e, storage, folder, dispatch, location) {
280-
e.target.style.opacity = '1'
281-
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
287+
e.preventDefault()
288+
if (this.state.draggedOver !== null) {
289+
this.setState({
290+
draggedOver: null
291+
})
292+
}
282293
const noteData = JSON.parse(e.dataTransfer.getData('note'))
283294
this.dropNote(storage, folder, dispatch, location, noteData)
284295
}
@@ -305,16 +316,22 @@ class StorageItem extends React.Component {
305316
<SortableStorageItemChild
306317
key={folder.key}
307318
index={index}
308-
isActive={isActive}
319+
isActive={isActive || folder.key === this.state.draggedOver}
309320
handleButtonClick={(e) => this.handleFolderButtonClick(folder.key)(e)}
310321
handleContextMenu={(e) => this.handleFolderButtonContextMenu(e, folder)}
311322
folderName={folder.name}
312323
folderColor={folder.color}
313324
isFolded={isFolded}
314325
noteCount={noteCount}
315-
handleDrop={(e) => this.handleDrop(e, storage, folder, dispatch, location)}
316-
handleDragEnter={this.handleDragEnter}
317-
handleDragLeave={this.handleDragLeave}
326+
handleDrop={(e) => {
327+
this.handleDrop(e, storage, folder, dispatch, location)
328+
}}
329+
handleDragEnter={(e) => {
330+
this.handleDragEnter(e, folder.key)
331+
}}
332+
handleDragLeave={(e) => {
333+
this.handleDragLeave(e, folder)
334+
}}
318335
/>
319336
)
320337
})

0 commit comments

Comments
 (0)