@@ -88,7 +88,8 @@ class LibraryComponent extends React.Component {
88
88
}
89
89
handleSelect ( id ) {
90
90
this . handleClose ( ) ;
91
- this . props . onItemSelected ( this . getFilteredData ( ) [ id ] ) ;
91
+ this . props . onItemSelected ( this . getFilteredData ( )
92
+ . find ( item => this . constructKey ( item ) === id ) ) ;
92
93
}
93
94
handleClose ( ) {
94
95
this . props . onRequestClose ( ) ;
@@ -100,7 +101,8 @@ class LibraryComponent extends React.Component {
100
101
selectedTag : tag . toLowerCase ( )
101
102
} ) ;
102
103
} else {
103
- this . props . onItemMouseLeave ( this . getFilteredData ( ) [ [ this . state . playingItem ] ] ) ;
104
+ this . props . onItemMouseLeave ( ( this . getFilteredData ( )
105
+ . find ( item => this . constructKey ( item ) === this . state . playingItem ) ) ) ;
104
106
this . setState ( {
105
107
filterQuery : '' ,
106
108
playingItem : null ,
@@ -111,15 +113,17 @@ class LibraryComponent extends React.Component {
111
113
handleMouseEnter ( id ) {
112
114
// don't restart if mouse over already playing item
113
115
if ( this . props . onItemMouseEnter && this . state . playingItem !== id ) {
114
- this . props . onItemMouseEnter ( this . getFilteredData ( ) [ id ] ) ;
116
+ this . props . onItemMouseEnter ( this . getFilteredData ( )
117
+ . find ( item => this . constructKey ( item ) === id ) ) ;
115
118
this . setState ( {
116
119
playingItem : id
117
120
} ) ;
118
121
}
119
122
}
120
123
handleMouseLeave ( id ) {
121
124
if ( this . props . onItemMouseLeave ) {
122
- this . props . onItemMouseLeave ( this . getFilteredData ( ) [ id ] ) ;
125
+ this . props . onItemMouseLeave ( this . getFilteredData ( )
126
+ . find ( item => this . constructKey ( item ) === id ) ) ;
123
127
this . setState ( {
124
128
playingItem : null
125
129
} ) ;
@@ -139,7 +143,8 @@ class LibraryComponent extends React.Component {
139
143
selectedTag : ALL_TAG . tag
140
144
} ) ;
141
145
} else {
142
- this . props . onItemMouseLeave ( this . getFilteredData ( ) [ [ this . state . playingItem ] ] ) ;
146
+ this . props . onItemMouseLeave ( this . getFilteredData ( )
147
+ . find ( item => this . constructKey ( item ) === this . state . playingItem ) ) ;
143
148
this . setState ( {
144
149
filterQuery : event . target . value ,
145
150
playingItem : null ,
@@ -174,13 +179,17 @@ class LibraryComponent extends React.Component {
174
179
. indexOf ( this . state . selectedTag ) !== - 1
175
180
) ) ;
176
181
}
182
+ constructKey ( data ) {
183
+ return typeof data . name === 'string' ? data . name : data . rawURL ;
184
+ }
177
185
scrollToTop ( ) {
178
186
this . filteredDataRef . scrollTop = 0 ;
179
187
}
180
188
setFilteredDataRef ( ref ) {
181
189
this . filteredDataRef = ref ;
182
190
}
183
- renderElement ( data , index ) {
191
+ renderElement ( data ) {
192
+ const key = this . constructKey ( data ) ;
184
193
return ( < LibraryItem
185
194
bluetoothRequired = { data . bluetoothRequired }
186
195
collaborator = { data . collaborator }
@@ -192,11 +201,11 @@ class LibraryComponent extends React.Component {
192
201
iconMd5 = { data . costumes ? data . costumes [ 0 ] . md5ext : data . md5ext }
193
202
iconRawURL = { data . rawURL }
194
203
icons = { data . costumes }
195
- id = { index }
204
+ id = { key }
196
205
insetIconURL = { data . insetIconURL }
197
206
internetConnectionRequired = { data . internetConnectionRequired }
198
- isPlaying = { this . state . playingItem === index }
199
- key = { typeof data . name === 'string' ? data . name : data . rawURL }
207
+ isPlaying = { this . state . playingItem === key }
208
+ key = { key }
200
209
name = { data . name }
201
210
showPlayButton = { this . props . showPlayButton }
202
211
onMouseEnter = { this . handleMouseEnter }
@@ -205,8 +214,8 @@ class LibraryComponent extends React.Component {
205
214
/> ) ;
206
215
}
207
216
renderData ( data ) {
208
- if ( this . state . selectedTag !== ALL_TAG . tag ) {
209
- return data . map ( ( dataItem , index ) => this . renderElement ( dataItem , index ) ) ;
217
+ if ( this . state . selectedTag !== ALL_TAG . tag || ! this . props . withCategories ) {
218
+ return data . map ( item => this . renderElement ( item ) ) ;
210
219
}
211
220
212
221
const dataByCategory = Object . groupBy ( data , el => el . category ) ;
@@ -228,7 +237,7 @@ class LibraryComponent extends React.Component {
228
237
< div
229
238
className = { styles . libraryCategoryItems }
230
239
>
231
- { values . map ( ( dataItem , index ) => this . renderElement ( dataItem , index ) ) }
240
+ { values . map ( item => this . renderElement ( item ) ) }
232
241
</ div >
233
242
</ div > ) ) ;
234
243
}
@@ -313,6 +322,7 @@ LibraryComponent.propTypes = {
313
322
/* eslint-enable react/no-unused-prop-types, lines-around-comment */
314
323
) ,
315
324
filterable : PropTypes . bool ,
325
+ withCategories : PropTypes . bool ,
316
326
id : PropTypes . string . isRequired ,
317
327
intl : intlShape . isRequired ,
318
328
onItemMouseEnter : PropTypes . func ,
0 commit comments