import React from 'react';
import PropTypes from 'prop-types';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import { Button, Modal, ModalBody, ModalFooter, Alert } from 'reactstrap';
import { Utils } from '../../utils/utils';
import { seafileAPI } from '../../utils/seafile-api';
import { gettext, siteRoot } from '../../utils/constants';
import SeahubModalHeader from '@/components/common/seahub-modal-header';
const propTypes = {
repoID: PropTypes.string.isRequired,
repoName: PropTypes.string.isRequired,
toggleDialog: PropTypes.func.isRequired
};
dayjs.extend(relativeTime);
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')}