1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00

Repo optimized (#2664)

This commit is contained in:
杨顺强
2018-12-18 17:21:01 +08:00
committed by Daniel Pan
parent 3b43d2d534
commit ed5439a4e3
15 changed files with 83 additions and 78 deletions

View File

@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import RepoListView from './repo-list-view';
import { seafileAPI } from '../../utils/seafile-api';
import { gettext } from '../../utils/constants';
import Repo from '../../models/repo';
import RepoInfo from '../../models/repo-info';
import '../../css/file-chooser.css';
@@ -22,7 +22,7 @@ class FileChooser extends React.Component {
isCurrentRepoShow: true,
isOtherRepoShow: false,
repoList: [],
currentRepo: null,
currentRepoInfo: null,
selectedRepo: null,
selectedPath: '',
};
@@ -31,22 +31,24 @@ class FileChooser extends React.Component {
componentDidMount() {
let repoID = this.props.repoID;
seafileAPI.getRepoInfo(repoID).then(res => {
let repo = new Repo(res.data);
// need to optimized
let repoInfo = new RepoInfo(res.data);
this.setState({
currentRepo: repo,
currentRepoInfo: repoInfo,
});
});
}
onOtherRepoToggle = () => {
if (!this.state.hasRequest) {
let { currentRepo } = this.state;
let { currentRepoInfo } = this.state;
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 === currentRepo.repo_name || repos[i].permission !== 'rw') {
if (repos[i].repo_name === currentRepoInfo.repo_name || repos[i].permission !== 'rw') {
continue;
}
if (repoIdList.indexOf(repos[i].repo_id) > -1) {
@@ -94,10 +96,10 @@ class FileChooser extends React.Component {
<span className="library">{gettext('Current Library')}</span>
</div>
{
this.state.isCurrentRepoShow && this.state.currentRepo &&
this.state.isCurrentRepoShow && this.state.currentRepoInfo &&
<RepoListView
initToShowChildren={true}
repo={this.state.currentRepo}
currentRepoInfo={this.state.currentRepoInfo}
selectedRepo={this.state.selectedRepo}
selectedPath={this.state.selectedPath}
onRepoItemClick={this.onRepoItemClick}

View File

@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import RepoListItem from './repo-list-item';
const propTypes = {
repo: PropTypes.object,
currentRepoInfo: PropTypes.object,
repoList: PropTypes.array,
selectedRepo: PropTypes.object,
initToShowChildren: PropTypes.bool.isRequired,
@@ -15,10 +15,10 @@ const propTypes = {
class RepoListView extends React.Component {
render() {
let { repo, repoList } = this.props;
if (repo) {
let { currentRepoInfo, repoList } = this.props;
if (currentRepoInfo) {
repoList = [];
repoList.push(repo);
repoList.push(currentRepoInfo);
}
return (
<ul className="list-view-content file-chooser-item">