Update: addrule & removerule

This commit is contained in:
Jason 2018-10-06 13:09:34 +08:00
parent 2be0eb448f
commit 0c3324e55a

View File

@ -68,6 +68,27 @@ class Rules extends React.Component<I18nProps, RulesState> {
}) })
} }
private addRule = () => {
const { rules } = this.state
const newRule = { type: RuleType['DOMAIN-SUFFIX'], payload: 'google.com.hk', proxy: 'DIRECT' }
const newRules = produce(rules, draftState => {
draftState.unshift(newRule)
})
this.setState({
rules: newRules,
modifiedIndex: 0
})
}
private removeRule = (index) => {
const { rules } = this.state
this.setState({
rules: rules.filter((r, idx) => idx !== index)
})
}
onSortEnd = ({ oldIndex, newIndex }) => { onSortEnd = ({ oldIndex, newIndex }) => {
this.setState({ this.setState({
rules: arrayMove(this.state.rules, oldIndex, newIndex) rules: arrayMove(this.state.rules, oldIndex, newIndex)
@ -156,7 +177,7 @@ class Rules extends React.Component<I18nProps, RulesState> {
</Select> </Select>
</Col> </Col>
<Col className="delete-btn" span={2} offset={3}> <Col className="delete-btn" span={2} offset={3}>
{!isFinal && <span></span>} {!isFinal && <span onClick={() => this.removeRule(index)}></span>}
</Col> </Col>
</Row> </Row>
</li> </li>
@ -171,7 +192,7 @@ class Rules extends React.Component<I18nProps, RulesState> {
return ( return (
<div className="page"> <div className="page">
<Header title={t('title')} > <Header title={t('title')} >
<Icon type="plus" size={20} style={{ fontWeight: 'bold', cursor: 'pointer' }} /> <Icon type="plus" size={20} style={{ fontWeight: 'bold', cursor: 'pointer' }} onClick={this.addRule}/>
</Header> </Header>
<Card className="rules-card"> <Card className="rules-card">