1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 17:33:18 +00:00

optimized code

This commit is contained in:
shanshuirenjia
2018-12-17 14:42:49 +08:00
parent 03c227f3e1
commit 2a3169c7cf
2 changed files with 22 additions and 15 deletions

View File

@@ -27,9 +27,7 @@ class ShareToGroup extends React.Component {
} }
handleSelectChange = (option) => { handleSelectChange = (option) => {
this.setState({ this.setState({selectedOption: option});
selectedOption: option,
});
} }
componentDidMount() { componentDidMount() {
@@ -115,7 +113,8 @@ class ShareToGroup extends React.Component {
}); });
this.setState({ this.setState({
sharedItems: this.state.sharedItems.concat(items) sharedItems: this.state.sharedItems.concat(items),
selectedOption: null,
}); });
}); });
} else { } else {
@@ -131,7 +130,8 @@ class ShareToGroup extends React.Component {
} }
this.setState({ this.setState({
sharedItems: this.state.sharedItems.concat(res.data.success) sharedItems: this.state.sharedItems.concat(res.data.success),
selectedOption: null,
}); });
}); });
} }
@@ -173,6 +173,7 @@ class ShareToGroup extends React.Component {
options={this.options} options={this.options}
components={makeAnimated()} components={makeAnimated()}
inputId={'react-select-2-input'} inputId={'react-select-2-input'}
value={this.state.selectedOption}
/> />
</td> </td>
<td> <td>
@@ -213,7 +214,7 @@ function GroupList(props) {
<tr key={index}> <tr key={index}>
<td>{item.group_info.name}</td> <td>{item.group_info.name}</td>
<td>{Utils.sharePerms[item.permission]}</td> <td>{Utils.sharePerms[item.permission]}</td>
<td><i onClick={(e) => {props.deleteShareItem(e, item.group_info.id);}} className="sf2-icon-delete" title="Delete"></i></td> <td><a href="#" onClick={(e) => {props.deleteShareItem(e, item.group_info.id);}} className="sf2-icon-x3 sf2-x op-icon" title={gettext('Delete')}></a></td>
</tr> </tr>
))} ))}
</tbody> </tbody>

View File

@@ -113,9 +113,10 @@ class ShareToUser extends React.Component {
return sharedItem; return sharedItem;
}); });
this.setState({ this.setState({
sharedItems: this.state.sharedItems.concat(items) sharedItems: this.state.sharedItems.concat(items),
selectedOption: null,
}); });
}) });
} else { } else {
seafileAPI.shareFolder(repoID, path, 'user', this.state.permission, users).then(res => { seafileAPI.shareFolder(repoID, path, 'user', this.state.permission, users).then(res => {
if (res.data.failed.length > 0) { if (res.data.failed.length > 0) {
@@ -126,7 +127,8 @@ class ShareToUser extends React.Component {
this.setState({errorMsg: errorMsg}); this.setState({errorMsg: errorMsg});
} }
this.setState({ this.setState({
sharedItems: this.state.sharedItems.concat(res.data.success) sharedItems: this.state.sharedItems.concat(res.data.success),
selectedOption: null,
}); });
}); });
} }
@@ -164,12 +166,16 @@ class ShareToUser extends React.Component {
<tr> <tr>
<td> <td>
<AsyncSelect <AsyncSelect
className='reviewer-select' isMulti isFocused
loadOptions={this.loadOptions}
placeholder={gettext('Please enter 1 or more character')}
onChange={this.handleSelectChange}
isClearable classNamePrefix
inputId={'react-select-1-input'} inputId={'react-select-1-input'}
className='reviewer-select'
placeholder={gettext('Please enter 1 or more character')}
loadOptions={this.loadOptions}
onChange={this.handleSelectChange}
value={this.state.selectedOption}
isMulti
isFocused
isClearable
classNamePrefix
/> />
</td> </td>
<td> <td>
@@ -211,7 +217,7 @@ function UserList(props) {
<tr key={index}> <tr key={index}>
<td>{item.user_info.nickname}</td> <td>{item.user_info.nickname}</td>
<td>{Utils.sharePerms[item.permission]}</td> <td>{Utils.sharePerms[item.permission]}</td>
<td><i onClick={(e) => {props.deleteShareItem(e, item.user_info.name);}} className="sf2-icon-delete" title="Delete"></i></td> <td><a href="#" onClick={(e) => {props.deleteShareItem(e, item.user_info.name);}} className="sf2-icon-x3 sf2-x op-icon" title={gettext('Delete')}></a></td>
</tr> </tr>
))} ))}
</tbody> </tbody>