mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 23:20:51 +00:00
init shared file view (#2748)
This commit is contained in:
@@ -9,7 +9,7 @@ import '../../css/file-chooser.css';
|
||||
|
||||
const propTypes = {
|
||||
isShowFile: PropTypes.bool,
|
||||
repoID: PropTypes.string.isRequired,
|
||||
repoID: PropTypes.string,
|
||||
onDirentItemClick: PropTypes.func,
|
||||
onRepoItemClick: PropTypes.func,
|
||||
};
|
||||
@@ -30,26 +30,31 @@ class FileChooser extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
let repoID = this.props.repoID;
|
||||
seafileAPI.getRepoInfo(repoID).then(res => {
|
||||
// need to optimized
|
||||
let repoInfo = new RepoInfo(res.data);
|
||||
this.setState({
|
||||
currentRepoInfo: repoInfo,
|
||||
if (this.props.repoID) {
|
||||
let repoID = this.props.repoID;
|
||||
seafileAPI.getRepoInfo(repoID).then(res => {
|
||||
// need to optimized
|
||||
let repoInfo = new RepoInfo(res.data);
|
||||
this.setState({
|
||||
currentRepoInfo: repoInfo,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onOtherRepoToggle = () => {
|
||||
if (!this.state.hasRequest) {
|
||||
let { currentRepoInfo } = this.state;
|
||||
let that = this;
|
||||
seafileAPI.listRepos().then(res => {
|
||||
// todo optimized code
|
||||
let repos = res.data.repos;
|
||||
let repoList = [];
|
||||
let repoIdList = [];
|
||||
for(let i = 0; i < repos.length; i++) {
|
||||
if (repos[i].repo_name === currentRepoInfo.repo_name || repos[i].permission !== 'rw') {
|
||||
if (repos[i].permission !== 'rw') {
|
||||
continue;
|
||||
}
|
||||
if (that.props.repoID && (repos[i].repo_name === that.state.currentRepoInfo.repo_name)) {
|
||||
continue;
|
||||
}
|
||||
if (repoIdList.indexOf(repos[i].repo_id) > -1) {
|
||||
@@ -63,7 +68,8 @@ class FileChooser extends React.Component {
|
||||
isOtherRepoShow: !this.state.isOtherRepoShow,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.setState({isOtherRepoShow: !this.state.isOtherRepoShow});
|
||||
}
|
||||
}
|
||||
@@ -93,24 +99,27 @@ class FileChooser extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div className="file-chooser-container">
|
||||
<div className="list-view">
|
||||
<div className="list-view-header">
|
||||
<span className={`item-toggle fa ${this.state.isCurrentRepoShow ? 'fa-caret-down' : 'fa-caret-right'}`} onClick={this.onCurrentRepoToggle}></span>
|
||||
<span className="library">{gettext('Current Library')}</span>
|
||||
{
|
||||
this.props.repoID &&
|
||||
<div className="list-view">
|
||||
<div className="list-view-header">
|
||||
<span className={`item-toggle fa ${this.state.isCurrentRepoShow ? 'fa-caret-down' : 'fa-caret-right'}`} onClick={this.onCurrentRepoToggle}></span>
|
||||
<span className="library">{gettext('Current Library')}</span>
|
||||
</div>
|
||||
{
|
||||
this.state.isCurrentRepoShow && this.state.currentRepoInfo &&
|
||||
<RepoListView
|
||||
initToShowChildren={true}
|
||||
currentRepoInfo={this.state.currentRepoInfo}
|
||||
selectedRepo={this.state.selectedRepo}
|
||||
selectedPath={this.state.selectedPath}
|
||||
onRepoItemClick={this.onRepoItemClick}
|
||||
onDirentItemClick={this.onDirentItemClick}
|
||||
isShowFile={this.props.isShowFile}
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
{
|
||||
this.state.isCurrentRepoShow && this.state.currentRepoInfo &&
|
||||
<RepoListView
|
||||
initToShowChildren={true}
|
||||
currentRepoInfo={this.state.currentRepoInfo}
|
||||
selectedRepo={this.state.selectedRepo}
|
||||
selectedPath={this.state.selectedPath}
|
||||
onRepoItemClick={this.onRepoItemClick}
|
||||
onDirentItemClick={this.onDirentItemClick}
|
||||
isShowFile={this.props.isShowFile}
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<div className="list-view">
|
||||
<div className="list-view-header">
|
||||
<span className={`item-toggle fa ${this.state.isOtherRepoShow ? 'fa-caret-down' : 'fa-caret-right'}`} onClick={this.onOtherRepoToggle}></span>
|
||||
|
Reference in New Issue
Block a user