@@ -2,39 +2,38 @@ import React from 'react'
2
2
import { View } from 'react-native'
3
3
import SongList from '../Containers/SongList'
4
4
import { connect } from 'react-redux'
5
- import styles from './Styles/MusicPlayerScreenStyle'
6
5
import PlayerArea from '../Containers/PlayerArea'
7
- import Filter from './../Components/Filter'
8
6
import { SearchBar } from 'react-native-elements'
9
7
import R from 'ramda'
10
8
11
9
class MusicPlayer extends React . Component {
12
- constructor ( props ) {
10
+ constructor ( props ) {
13
11
super ( props )
14
12
this . state = {
15
13
searchTerm : '' ,
16
14
currentlyDisplayed : [ ]
17
15
}
18
16
}
19
- componentWillReceiveProps ( props ) {
17
+ componentWillReceiveProps ( props ) {
20
18
this . setState ( { currentlyDisplayed : props . songs } )
21
19
}
22
- filterDisplayed ( text ) {
23
- this . setState
24
- ( {
25
- searchTerm : text ,
26
- currentlyDisplayed : this . props . songs
27
- } )
28
-
29
- this . setState ( { currentlyDisplayed : this . props . songs } )
20
+ filterDisplayed ( text ) {
21
+ const songContains = ( a , p , v ) => R . path ( [ 'metadata' , p ] , a ) . toLowerCase ( ) . indexOf ( text . toLowerCase ( ) ) > - 1
22
+ const currentlyDisplayed = this . props . songs
23
+ . filter ( song =>
24
+ songContains ( song , 'title' ) ||
25
+ songContains ( song , 'artist' ) ||
26
+ songContains ( song , 'genre' )
27
+ )
28
+ this . setState ( { currentlyDisplayed} )
30
29
}
31
30
render ( ) {
32
31
const songs = this . state . currentlyDisplayed || [ ]
33
32
return (
34
- < View style = { styles . container } >
35
- < SearchBar round onChangeText = { text => this . filterDisplayed ( text ) } placeholder = 'Type Here...' />
33
+ < View style = { { flex : 1 , backgroundColor : 'white' } } >
34
+ < SearchBar round onChangeText = { text => this . filterDisplayed ( text ) } placeholder = 'Type Here...' />
36
35
< SongList songs = { songs } />
37
- < PlayerArea />
36
+ < PlayerArea style = { { marginTop : - 20 } } />
38
37
</ View >
39
38
)
40
39
}
0 commit comments