import React from 'react'; import PropTypes from 'prop-types'; import { gettext, siteRoot } from '../../utils/constants'; import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; import { seafileAPI } from '../../utils/seafile-api'; import moment from 'moment'; import Repo from '../../models/repo'; import { Utils } from '../../utils/utils'; const propTypes = { toggleCancel: PropTypes.func.isRequired, addWiki: PropTypes.func.isRequired, }; class WikiSelectDialog extends React.Component { constructor(props) { super(props); this.state = { repos: [], repoID: '', }; } componentDidMount() { seafileAPI.listRepos().then(res => { let repoList = res.data.repos.map(item => { let repo = new Repo(item); return repo; }); repoList = Utils.sortRepos(repoList, 'name', 'asc'); this.setState({repos: repoList}); }); } onChange = (repo) => { this.setState({ repoID: repo.repo_id, }); } handleSubmit = () => { let { repoID } = this.state; this.props.addWiki(repoID); this.props.toggleCancel(); } toggle = () => { this.props.toggleCancel(); } render() { return ( {gettext('Publish a Library')} {this.state.repos.map((repo, index) => { return ( ); })}
{/* select */} {/* icon */} {gettext('Name')} {gettext('Last Update')}
{gettext('icon')} {repo.repo_name} {moment(repo.last_modified).fromNow()}
{this.state.repoID ? : }
); } } WikiSelectDialog.propTypes = propTypes; export default WikiSelectDialog;