@@ -88,7 +88,8 @@ class LibraryComponent extends React.Component {
8888 }
8989 handleSelect ( id ) {
9090 this . handleClose ( ) ;
91- this . props . onItemSelected ( this . getFilteredData ( ) [ id ] ) ;
91+ this . props . onItemSelected ( this . getFilteredData ( )
92+ . find ( item => this . constructKey ( item ) === id ) ) ;
9293 }
9394 handleClose ( ) {
9495 this . props . onRequestClose ( ) ;
@@ -100,7 +101,8 @@ class LibraryComponent extends React.Component {
100101 selectedTag : tag . toLowerCase ( )
101102 } ) ;
102103 } 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 ) ) ) ;
104106 this . setState ( {
105107 filterQuery : '' ,
106108 playingItem : null ,
@@ -111,15 +113,17 @@ class LibraryComponent extends React.Component {
111113 handleMouseEnter ( id ) {
112114 // don't restart if mouse over already playing item
113115 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 ) ) ;
115118 this . setState ( {
116119 playingItem : id
117120 } ) ;
118121 }
119122 }
120123 handleMouseLeave ( id ) {
121124 if ( this . props . onItemMouseLeave ) {
122- this . props . onItemMouseLeave ( this . getFilteredData ( ) [ id ] ) ;
125+ this . props . onItemMouseLeave ( this . getFilteredData ( )
126+ . find ( item => this . constructKey ( item ) === id ) ) ;
123127 this . setState ( {
124128 playingItem : null
125129 } ) ;
@@ -139,7 +143,8 @@ class LibraryComponent extends React.Component {
139143 selectedTag : ALL_TAG . tag
140144 } ) ;
141145 } 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 ) ) ;
143148 this . setState ( {
144149 filterQuery : event . target . value ,
145150 playingItem : null ,
@@ -174,13 +179,17 @@ class LibraryComponent extends React.Component {
174179 . indexOf ( this . state . selectedTag ) !== - 1
175180 ) ) ;
176181 }
182+ constructKey ( data ) {
183+ return typeof data . name === 'string' ? data . name : data . rawURL ;
184+ }
177185 scrollToTop ( ) {
178186 this . filteredDataRef . scrollTop = 0 ;
179187 }
180188 setFilteredDataRef ( ref ) {
181189 this . filteredDataRef = ref ;
182190 }
183- renderElement ( data , index ) {
191+ renderElement ( data ) {
192+ const key = this . constructKey ( data ) ;
184193 return ( < LibraryItem
185194 bluetoothRequired = { data . bluetoothRequired }
186195 collaborator = { data . collaborator }
@@ -192,11 +201,11 @@ class LibraryComponent extends React.Component {
192201 iconMd5 = { data . costumes ? data . costumes [ 0 ] . md5ext : data . md5ext }
193202 iconRawURL = { data . rawURL }
194203 icons = { data . costumes }
195- id = { index }
204+ id = { key }
196205 insetIconURL = { data . insetIconURL }
197206 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 }
200209 name = { data . name }
201210 showPlayButton = { this . props . showPlayButton }
202211 onMouseEnter = { this . handleMouseEnter }
@@ -205,8 +214,8 @@ class LibraryComponent extends React.Component {
205214 /> ) ;
206215 }
207216 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 ) ) ;
210219 }
211220
212221 const dataByCategory = Object . groupBy ( data , el => el . category ) ;
@@ -228,7 +237,7 @@ class LibraryComponent extends React.Component {
228237 < div
229238 className = { styles . libraryCategoryItems }
230239 >
231- { values . map ( ( dataItem , index ) => this . renderElement ( dataItem , index ) ) }
240+ { values . map ( item => this . renderElement ( item ) ) }
232241 </ div >
233242 </ div > ) ) ;
234243 }
@@ -313,6 +322,7 @@ LibraryComponent.propTypes = {
313322 /* eslint-enable react/no-unused-prop-types, lines-around-comment */
314323 ) ,
315324 filterable : PropTypes . bool ,
325+ withCategories : PropTypes . bool ,
316326 id : PropTypes . string . isRequired ,
317327 intl : intlShape . isRequired ,
318328 onItemMouseEnter : PropTypes . func ,
0 commit comments