|
|
@ -2,10 +2,11 @@ import './BlacklistForm.scss'; |
|
|
|
import AddButton from '../ui/AddButton'; |
|
|
|
import AddButton from '../ui/AddButton'; |
|
|
|
import DeleteButton from '../ui/DeleteButton'; |
|
|
|
import DeleteButton from '../ui/DeleteButton'; |
|
|
|
import React from 'react'; |
|
|
|
import React from 'react'; |
|
|
|
|
|
|
|
import { BlacklistJSON } from '../../../shared/settings/Blacklist'; |
|
|
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
interface Props { |
|
|
|
value: string[]; |
|
|
|
value: BlacklistJSON; |
|
|
|
onChange: (value: string[]) => void; |
|
|
|
onChange: (value: BlacklistJSON) => void; |
|
|
|
onBlur: () => void; |
|
|
|
onBlur: () => void; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -19,19 +20,24 @@ class BlacklistForm extends React.Component<Props> { |
|
|
|
render() { |
|
|
|
render() { |
|
|
|
return <div className='form-blacklist-form'> |
|
|
|
return <div className='form-blacklist-form'> |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.props.value.map((url, index) => { |
|
|
|
this.props.value |
|
|
|
return <div key={index} className='form-blacklist-form-row'> |
|
|
|
.map((item, index) => { |
|
|
|
<input data-index={index} type='text' name='url' |
|
|
|
if (typeof item !== 'string') { |
|
|
|
className='column-url' value={url} |
|
|
|
// TODO support partial blacklist;
|
|
|
|
onChange={this.bindValue.bind(this)} |
|
|
|
return null; |
|
|
|
onBlur={this.props.onBlur} |
|
|
|
} |
|
|
|
/> |
|
|
|
return <div key={index} className='form-blacklist-form-row'> |
|
|
|
<DeleteButton data-index={index} name='delete' |
|
|
|
<input data-index={index} type='text' name='url' |
|
|
|
onClick={this.bindValue.bind(this)} |
|
|
|
className='column-url' value={item} |
|
|
|
onBlur={this.props.onBlur} |
|
|
|
onChange={this.bindValue.bind(this)} |
|
|
|
/> |
|
|
|
onBlur={this.props.onBlur} |
|
|
|
</div>; |
|
|
|
/> |
|
|
|
}) |
|
|
|
<DeleteButton data-index={index} name='delete' |
|
|
|
|
|
|
|
onClick={this.bindValue.bind(this)} |
|
|
|
|
|
|
|
onBlur={this.props.onBlur} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</div>; |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
<AddButton name='add' style={{ float: 'right' }} |
|
|
|
<AddButton name='add' style={{ float: 'right' }} |
|
|
|
onClick={this.bindValue.bind(this)} /> |
|
|
|
onClick={this.bindValue.bind(this)} /> |
|
|
@ -41,7 +47,7 @@ class BlacklistForm extends React.Component<Props> { |
|
|
|
bindValue(e: any) { |
|
|
|
bindValue(e: any) { |
|
|
|
let name = e.target.name; |
|
|
|
let name = e.target.name; |
|
|
|
let index = e.target.getAttribute('data-index'); |
|
|
|
let index = e.target.getAttribute('data-index'); |
|
|
|
let next = this.props.value ? this.props.value.slice() : []; |
|
|
|
let next = this.props.value.slice(); |
|
|
|
|
|
|
|
|
|
|
|
if (name === 'url') { |
|
|
|
if (name === 'url') { |
|
|
|
next[index] = e.target.value; |
|
|
|
next[index] = e.target.value; |
|
|
|