1
1
const remote = require ( '@electron/remote' )
2
+ const { webUtils } = require ( 'electron' )
2
3
const { app, dialog } = remote
3
4
const html = require ( 'choo/html' )
4
5
const Component = require ( 'nanocomponent' )
@@ -36,7 +37,7 @@ const styles = css`
36
37
`
37
38
38
39
class Header extends Component {
39
- constructor ( opts ) {
40
+ constructor ( opts ) {
40
41
super ( opts )
41
42
42
43
this . emit = null
@@ -52,12 +53,12 @@ class Header extends Component {
52
53
this . searchComp = new Search ( )
53
54
}
54
55
55
- handleSearch ( val ) {
56
+ handleSearch ( val ) {
56
57
this . search = val
57
58
this . emit ( 'library:search' , val )
58
59
}
59
60
60
- handleAddButton ( ) {
61
+ handleAddButton ( ) {
61
62
if ( ! this . dialogOpen ) {
62
63
this . dialogOpen = true
63
64
const paths = config . get ( 'paths' )
@@ -74,26 +75,27 @@ class Header extends Component {
74
75
}
75
76
}
76
77
77
- handlePaths ( { filePaths } ) {
78
+ handlePaths ( { filePaths } ) {
78
79
this . dialogOpen = false
79
80
if ( Array . isArray ( filePaths ) && filePaths . length > 0 ) {
80
81
this . emit ( 'config:set' , { filePaths } )
81
82
this . emit ( 'library:update-library' , filePaths )
82
83
}
83
84
}
84
85
85
- handleNav ( ) {
86
+ handleNav ( ) {
86
87
this . emit ( 'pushState' , '#preferences' )
87
88
}
88
89
89
- handleDrop ( event ) {
90
+ handleDrop ( event ) {
90
91
event . preventDefault ( )
91
92
const { files } = event . dataTransfer
92
- const paths = Array ( files . length ) . fill ( 0 ) . map ( ( _ , i ) => files . item ( i ) . path )
93
+
94
+ const paths = Array ( files . length ) . fill ( 0 ) . map ( ( _ , i ) => webUtils . getPathForFile ( files . item ( i ) ) )
93
95
this . handlePaths ( { filePaths : paths } )
94
96
}
95
97
96
- createElement ( state , emit ) {
98
+ createElement ( state , emit ) {
97
99
this . emit = emit
98
100
this . search = state . library . search
99
101
this . loading = state . library . loading
@@ -106,22 +108,22 @@ class Header extends Component {
106
108
< header class ="${ styles . toolbar } ">
107
109
< div class ="${ styles . toolbarLeft } ">
108
110
${ this . searchComp . render ( { /* eslint-disable indent */
109
- onchange : this . handleSearch ,
110
- value : this . search
111
- } ) /* eslint-enable indent */ }
111
+ onchange : this . handleSearch ,
112
+ value : this . search
113
+ } ) /* eslint-enable indent */ }
112
114
</ div >
113
115
< div class ="${ styles . toolbarRight } ">
114
116
${ button ( { /* eslint-disable indent */
115
- className : this . loading ? styles . spin : null ,
116
- onclick : this . handleAddButton ,
117
- iconName : this . loading ? 'entypo-cog' : 'entypo-folder-music'
118
- } ) /* eslint-enable indent */ }
117
+ className : this . loading ? styles . spin : null ,
118
+ onclick : this . handleAddButton ,
119
+ iconName : this . loading ? 'entypo-cog' : 'entypo-folder-music'
120
+ } ) /* eslint-enable indent */ }
119
121
</ div >
120
122
</ header >
121
123
`
122
124
}
123
125
124
- update ( state , emit ) {
126
+ update ( state , emit ) {
125
127
if ( this . search !== state . library . search ) return true
126
128
if ( this . loading !== state . library . loading ) return true
127
129
return false
0 commit comments