import React from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Alert } from 'reactstrap';
import { Utils } from '../../utils/utils';
import { seafileAPI } from '../../utils/seafile-api.js';
import { gettext, siteRoot } from '../../utils/constants';
const propTypes = {
repoID: PropTypes.string.isRequired,
repoName: PropTypes.string.isRequired,
toggleDialog: PropTypes.func.isRequired
};
class SearchFileDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
isSubmitDisabled: true,
isSubmitting: false,
q: '',
errMessage: '',
fileList: null
};
}
searchFile = () => {
const { q } = this.state;
if (!q.trim()) {
return false;
}
this.setState({
isSubmitDisabled: true,
isSubmitting: true
});
seafileAPI.searchFileInRepo(this.props.repoID, q).then((res) => {
this.setState({
fileList: res.data.data,
errMessage: '',
isSubmitDisabled: false,
isSubmitting: false
});
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
this.setState({
errMessage: errMessage,
isSubmitDisabled: false,
isSubmitting: false
});
});
}
handleKeyDown = (e) => {
if (e.key == 'Enter') {
e.preventDefault();
this.searchFile();
}
}
toggle = () => {
this.props.toggleDialog();
}
handleInputChange = (e) => {
const q = e.target.value;
this.setState({
q: q,
isSubmitDisabled: !q.trim()
});
}
render() {
const { q, errMessage, fileList, isSubmitDisabled, isSubmitting } = this.state;
return (
{gettext('No result')}
}
{fileList.map((item, index) => {
return (
{gettext('Name')}
{gettext('Size')}
{gettext('Last Update')}