@ -1,6 +1,7 @@
import PropTypes from 'prop-types' ;
import PropTypes from 'prop-types' ;
import React , { Component } from 'react' ;
import React , { Component } from 'react' ;
import Alert from 'Components/Alert' ;
import Alert from 'Components/Alert' ;
import EnhancedSelectInput from 'Components/Form/EnhancedSelectInput' ;
import TextInput from 'Components/Form/TextInput' ;
import TextInput from 'Components/Form/TextInput' ;
import Button from 'Components/Link/Button' ;
import Button from 'Components/Link/Button' ;
import LoadingIndicator from 'Components/Loading/LoadingIndicator' ;
import LoadingIndicator from 'Components/Loading/LoadingIndicator' ;
@ -44,6 +45,17 @@ const columns = [
}
}
] ;
] ;
const protocols = [
{
key : 'torrent' ,
value : 'torrent'
} ,
{
key : 'usenet' ,
value : 'nzb'
}
] ;
class AddIndexerModalContent extends Component {
class AddIndexerModalContent extends Component {
//
//
@ -53,7 +65,10 @@ class AddIndexerModalContent extends Component {
super ( props , context ) ;
super ( props , context ) ;
this . state = {
this . state = {
filter : ''
filter : '' ,
filterProtocols : [ ] ,
filterLanguages : [ ] ,
filterPrivacyLevels : [ ]
} ;
} ;
}
}
@ -80,8 +95,35 @@ class AddIndexerModalContent extends Component {
onModalClose
onModalClose
} = this . props ;
} = this . props ;
const filter = this . state . filter ;
const languages = Array . from ( new Set ( indexers . map ( ( { language } ) => language ) ) )
const filterLower = filter . toLowerCase ( ) ;
. sort ( ( a , b ) => a . localeCompare ( b ) )
. map ( ( language ) => ( { key : language , value : language } ) ) ;
const privacyLevels = Array . from ( new Set ( indexers . map ( ( { privacy } ) => privacy ) ) )
. sort ( ( a , b ) => a . localeCompare ( b ) )
. map ( ( privacy ) => ( { key : privacy , value : privacy } ) ) ;
const filteredIndexers = indexers . filter ( ( indexer ) => {
const { filter , filterProtocols , filterLanguages , filterPrivacyLevels } = this . state ;
if ( ! indexer . name . toLowerCase ( ) . includes ( filter . toLocaleLowerCase ( ) ) ) {
return false ;
}
if ( filterProtocols . length && ! filterProtocols . includes ( indexer . protocol ) ) {
return false ;
}
if ( filterLanguages . length && ! filterLanguages . includes ( indexer . language ) ) {
return false ;
}
if ( filterPrivacyLevels . length && ! filterPrivacyLevels . includes ( indexer . privacy ) ) {
return false ;
}
return true ;
} ) ;
const errorMessage = getErrorMessage ( error , 'Unable to load indexers' ) ;
const errorMessage = getErrorMessage ( error , 'Unable to load indexers' ) ;
@ -99,11 +141,43 @@ class AddIndexerModalContent extends Component {
className = { styles . filterInput }
className = { styles . filterInput }
placeholder = { translate ( 'FilterPlaceHolder' ) }
placeholder = { translate ( 'FilterPlaceHolder' ) }
name = "filter"
name = "filter"
value = { filter }
value = { this . state . filter }
autoFocus = { true }
autoFocus = { true }
onChange = { this . onFilterChange }
onChange = { this . onFilterChange }
/ >
/ >
< div className = { styles . filterRow } >
< div className = { styles . filterContainer } >
< label className = { styles . filterLabel } > Protocol < / l a b e l >
< EnhancedSelectInput
name = "indexerProtocols"
value = { this . state . filterProtocols }
values = { protocols }
onChange = { ( { value } ) => this . setState ( { filterProtocols : value } ) }
/ >
< / d i v >
< div className = { styles . filterContainer } >
< label className = { styles . filterLabel } > Language < / l a b e l >
< EnhancedSelectInput
name = "indexerLanguages"
value = { this . state . filterLanguages }
values = { languages }
onChange = { ( { value } ) => this . setState ( { filterLanguages : value } ) }
/ >
< / d i v >
< div className = { styles . filterContainer } >
< label className = { styles . filterLabel } > Privacy < / l a b e l >
< EnhancedSelectInput
name = "indexerPrivacyLevels"
value = { this . state . filterPrivacyLevels }
values = { privacyLevels }
onChange = { ( { value } ) => this . setState ( { filterPrivacyLevels : value } ) }
/ >
< / d i v >
< / d i v >
< Alert
< Alert
kind = { kinds . INFO }
kind = { kinds . INFO }
className = { styles . alert }
className = { styles . alert }
@ -133,18 +207,14 @@ class AddIndexerModalContent extends Component {
>
>
< TableBody >
< TableBody >
{
{
indexers . map ( ( indexer ) => {
filteredIndexers . map ( ( indexer ) => (
return indexer . name . toLowerCase ( ) . includes ( filterLower ) ?
(
< SelectIndexerRow
< SelectIndexerRow
key = { indexer . name }
key = { indexer . name }
implementation = { indexer . implementation }
implementation = { indexer . implementation }
{ ... indexer }
{ ... indexer }
onIndexerSelect = { onIndexerSelect }
onIndexerSelect = { onIndexerSelect }
/ >
/ >
) :
) )
null ;
} )
}
}
< / T a b l e B o d y >
< / T a b l e B o d y >
< / T a b l e > :
< / T a b l e > :