Skip to content

Commit b8a2957

Browse files
Dragged note highlighting
1 parent 3793378 commit b8a2957

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

browser/main/SideNav/StorageItem.js

Lines changed: 30 additions & 13 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

@@ -231,14 +232,18 @@ class StorageItem extends React.Component {
231232
}
232233
}
233234

234-
handleDragEnter (e) {
235-
e.dataTransfer.setData('defaultColor', e.target.style.backgroundColor)
236-
e.target.style.backgroundColor = 'rgba(129, 130, 131, 0.08)'
235+
handleDragEnter (e, key) {
236+
if (this.state.draggedOver === key) { return }
237+
this.setState({
238+
draggedOver: key
239+
})
237240
}
238241

239242
handleDragLeave (e) {
240-
e.target.style.opacity = '1'
241-
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
243+
if (this.state.draggedOver === null) { return }
244+
this.setState({
245+
draggedOver: null
246+
})
242247
}
243248

244249
dropNote (storage, folder, dispatch, location, noteData) {
@@ -263,8 +268,11 @@ class StorageItem extends React.Component {
263268
}
264269

265270
handleDrop (e, storage, folder, dispatch, location) {
266-
e.target.style.opacity = '1'
267-
e.target.style.backgroundColor = e.dataTransfer.getData('defaultColor')
271+
if (this.state.draggedOver !== null) {
272+
this.setState({
273+
draggedOver: null
274+
})
275+
}
268276
const noteData = JSON.parse(e.dataTransfer.getData('note'))
269277
this.dropNote(storage, folder, dispatch, location, noteData)
270278
}
@@ -274,7 +282,7 @@ class StorageItem extends React.Component {
274282
const { folderNoteMap, trashedSet } = data
275283
const SortableStorageItemChild = SortableElement(StorageItemChild)
276284
const folderList = storage.folders.map((folder, index) => {
277-
let folderRegex = new RegExp(escapeStringRegexp(path.sep) + 'storages' + escapeStringRegexp(path.sep) + storage.key + escapeStringRegexp(path.sep) + 'folders' + escapeStringRegexp(path.sep) + folder.key)
285+
const folderRegex = new RegExp(escapeStringRegexp(path.sep) + 'storages' + escapeStringRegexp(path.sep) + storage.key + escapeStringRegexp(path.sep) + 'folders' + escapeStringRegexp(path.sep) + folder.key)
278286
const isActive = !!(location.pathname.match(folderRegex))
279287
const noteSet = folderNoteMap.get(storage.key + '-' + folder.key)
280288

@@ -291,16 +299,25 @@ class StorageItem extends React.Component {
291299
<SortableStorageItemChild
292300
key={folder.key}
293301
index={index}
294-
isActive={isActive}
302+
isActive={isActive || folder.key === this.state.draggedOver}
295303
handleButtonClick={(e) => this.handleFolderButtonClick(folder.key)(e)}
296304
handleContextMenu={(e) => this.handleFolderButtonContextMenu(e, folder)}
297305
folderName={folder.name}
298306
folderColor={folder.color}
299307
isFolded={isFolded}
300308
noteCount={noteCount}
301-
handleDrop={(e) => this.handleDrop(e, storage, folder, dispatch, location)}
302-
handleDragEnter={this.handleDragEnter}
303-
handleDragLeave={this.handleDragLeave}
309+
handleDrop={(e) => {
310+
e.preventDefault()
311+
this.handleDrop(e, storage, folder, dispatch, location)
312+
}}
313+
handleDragEnter={(e) => {
314+
e.preventDefault()
315+
this.handleDragEnter(e, folder.key)
316+
}}
317+
handleDragLeave={(e) => {
318+
e.preventDefault()
319+
this.handleDragLeave(e, folder)
320+
}}
304321
/>
305322
)
306323
})

0 commit comments

Comments
 (0)