Skip to content

Commit

Permalink
Fix drag n drop file loading
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Nov 5, 2024
1 parent a53a885 commit 1aa9cf4
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions renderer/player/elements/header/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const remote = require('@electron/remote')
const { webUtils } = require('electron')
const { app, dialog } = remote
const html = require('choo/html')
const Component = require('nanocomponent')
Expand Down Expand Up @@ -36,7 +37,7 @@ const styles = css`
`

class Header extends Component {
constructor (opts) {
constructor(opts) {
super(opts)

this.emit = null
Expand All @@ -52,12 +53,12 @@ class Header extends Component {
this.searchComp = new Search()
}

handleSearch (val) {
handleSearch(val) {
this.search = val
this.emit('library:search', val)
}

handleAddButton () {
handleAddButton() {
if (!this.dialogOpen) {
this.dialogOpen = true
const paths = config.get('paths')
Expand All @@ -74,26 +75,27 @@ class Header extends Component {
}
}

handlePaths ({ filePaths }) {
handlePaths({ filePaths }) {
this.dialogOpen = false
if (Array.isArray(filePaths) && filePaths.length > 0) {
this.emit('config:set', { filePaths })
this.emit('library:update-library', filePaths)
}
}

handleNav () {
handleNav() {
this.emit('pushState', '#preferences')
}

handleDrop (event) {
handleDrop(event) {
event.preventDefault()
const { files } = event.dataTransfer
const paths = Array(files.length).fill(0).map((_, i) => files.item(i).path)

const paths = Array(files.length).fill(0).map((_, i) => webUtils.getPathForFile(files.item(i)))
this.handlePaths({ filePaths: paths })
}

createElement (state, emit) {
createElement(state, emit) {
this.emit = emit
this.search = state.library.search
this.loading = state.library.loading
Expand All @@ -106,22 +108,22 @@ class Header extends Component {
<header class="${styles.toolbar}">
<div class="${styles.toolbarLeft}">
${this.searchComp.render({ /* eslint-disable indent */
onchange: this.handleSearch,
value: this.search
})/* eslint-enable indent */}
onchange: this.handleSearch,
value: this.search
})/* eslint-enable indent */}
</div>
<div class="${styles.toolbarRight}">
${button({ /* eslint-disable indent */
className: this.loading ? styles.spin : null,
onclick: this.handleAddButton,
iconName: this.loading ? 'entypo-cog' : 'entypo-folder-music'
})/* eslint-enable indent */}
className: this.loading ? styles.spin : null,
onclick: this.handleAddButton,
iconName: this.loading ? 'entypo-cog' : 'entypo-folder-music'
})/* eslint-enable indent */}
</div>
</header>
`
}

update (state, emit) {
update(state, emit) {
if (this.search !== state.library.search) return true
if (this.loading !== state.library.loading) return true
return false
Expand Down

0 comments on commit 1aa9cf4

Please sign in to comment.