I'm trying to filter cards based off text fields that could be empty or could be filled out, if they are filled out then I want to filter everything that doesn't include that string out.
For example, if I just wanted to filter by the title "Test" I would only put something in the title input box, but if i wanted to filter by both title and composer I would have both text fields filled out and only the cards that matched with both text fields would show.
Currently how I'm trying to do it is as follows:
filterMusicLibrary() {
let musicLibraryItems = [];
this.state.musicGet.map(music => {
if(music.title) {
if(music.title.includes(this.state.title) ) {
musicLibraryItems.push(
<MusicLibraryItem key= {music.id} music={music} history={this.props.history}/>
);
}
}
if(music.composer) {
if(music.composer.includes(this.state.composer) ) {
musicLibraryItems.push(
<MusicLibraryItem key= {music.id} music={music} history={this.props.history}/>
);
}
}
if(music.arranger) {
if(music.arranger.includes(this.state.arranger) ) {
musicLibraryItems.push(
<MusicLibraryItem key= {music.id} music={music} history={this.props.history}/>
);
}
}
if(music.instrumentation) {
if(music.instrumentation.includes(this.state.instrumentation) ) {
musicLibraryItems.push(
<MusicLibraryItem key= {music.id} music={music} history={this.props.history}/>
);
}
}
});
musicLibraryItems = [..new Set(musicLibraryItems)]
return musicLibraryItems;
}
I'm pushing everything to a musicLibraryItems array and then I was hoping to get the unique values by using the Set variable type from ES6 but it failed to work as intended, this way is also extremely inefficient and I was wondering if someone could help me find a solution.