Skip to content

Commit

Permalink
Merge pull request #2684 from GuilhermeJSilva/fix/highlight-folder-on…
Browse files Browse the repository at this point in the history
…-hover

Dragged note highlighting
  • Loading branch information
Rokt33r committed Dec 13, 2018
2 parents 7c839a1 + 4061866 commit 3f77cb2
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions browser/main/SideNav/StorageItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class StorageItem extends React.Component {
const { storage } = this.props

this.state = {
isOpen: !!storage.isOpen
isOpen: !!storage.isOpen,
draggedOver: null
}
}

Expand Down Expand Up @@ -245,14 +246,20 @@ class StorageItem extends React.Component {
}
}

handleDragEnter (e) {
e.dataTransfer.setData('defaultColor', e.target.style.backgroundColor)
e.target.style.backgroundColor = 'rgba(129, 130, 131, 0.08)'
handleDragEnter (e, key) {
e.preventDefault()
if (this.state.draggedOver === key) { return }
this.setState({
draggedOver: key
})
}

handleDragLeave (e) {
e.target.style.opacity = '1'
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
e.preventDefault()
if (this.state.draggedOver === null) { return }
this.setState({
draggedOver: null
})
}

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

handleDrop (e, storage, folder, dispatch, location) {
e.target.style.opacity = '1'
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
e.preventDefault()
if (this.state.draggedOver !== null) {
this.setState({
draggedOver: null
})
}
const noteData = JSON.parse(e.dataTransfer.getData('note'))
this.dropNote(storage, folder, dispatch, location, noteData)
}
Expand All @@ -305,16 +316,22 @@ class StorageItem extends React.Component {
<SortableStorageItemChild
key={folder.key}
index={index}
isActive={isActive}
isActive={isActive || folder.key === this.state.draggedOver}
handleButtonClick={(e) => this.handleFolderButtonClick(folder.key)(e)}
handleContextMenu={(e) => this.handleFolderButtonContextMenu(e, folder)}
folderName={folder.name}
folderColor={folder.color}
isFolded={isFolded}
noteCount={noteCount}
handleDrop={(e) => this.handleDrop(e, storage, folder, dispatch, location)}
handleDragEnter={this.handleDragEnter}
handleDragLeave={this.handleDragLeave}
handleDrop={(e) => {
this.handleDrop(e, storage, folder, dispatch, location)
}}
handleDragEnter={(e) => {
this.handleDragEnter(e, folder.key)
}}
handleDragLeave={(e) => {
this.handleDragLeave(e, folder)
}}
/>
)
})
Expand Down

0 comments on commit 3f77cb2

Please sign in to comment.