import React from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalHeader, ModalBody } from 'reactstrap';
import dayjs from 'dayjs';
import { Utils } from '../../utils/utils';
import { gettext, wikiId } from '../../utils/constants';
import wikiAPI from '../../utils/wiki-api';
import ModalPortal from '../../components/modal-portal';
import toaster from '../../components/toast';
import Paginator from '../../components/paginator';
import WikiCleanTrash from '../../components/dialog/wiki-clean-trash';
import NavItemIcon from './common/nav-item-icon';
import '../../css/toolbar.css';
import '../../css/search.css';
import '../../css/wiki-trash-dialog.css';
const propTypes = {
showTrashDialog: PropTypes.bool.isRequired,
toggleTrashDialog: PropTypes.func.isRequired,
getWikiConfig: PropTypes.func.isRequired
};
class WikiTrashDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
errorMsg: '',
items: [],
isCleanTrashDialogOpen: false,
currentPage: 1,
perPage: 100,
hasNextPage: false
};
}
componentDidMount() {
this.getItems();
}
getItems = (page) => {
wikiAPI.getWikiTrash(wikiId, page, this.state.perPage).then((res) => {
const { items, total_count } = res.data;
if (!page) {
page = 1;
}
this.setState({
currentPage: page,
hasNextPage: total_count - page * this.state.perPage > 0,
isLoading: false,
items: items,
});
});
};
resetPerPage = (perPage) => {
this.setState({
perPage: perPage
}, () => {
this.getItems(1);
});
};
cleanTrash = () => {
this.toggleCleanTrashDialog();
};
toggleCleanTrashDialog = () => {
this.setState({
isCleanTrashDialogOpen: !this.state.isCleanTrashDialogOpen
});
};
refreshTrash = () => {
this.setState({
isLoading: true,
errorMsg: '',
items: []
});
this.getItems();
};
render() {
const { showTrashDialog, toggleTrashDialog } = this.props;
const { isCleanTrashDialogOpen } = this.state;
const { isAdmin, enableUserCleanTrash, repoName } = window.wiki.config;
let title = gettext('{placeholder} Wiki Trash');
title = title.replace('{placeholder}', '' + Utils.HTMLescape(repoName) + '');
return (
{this.theadData.map((item, index) => {
return
{items.map((item, index) => {
return (
{item.text} ;
})}