import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import AppContainer from '../services/AppContainer';
import PageContainer from '../services/PageContainer';
import PaginationWrapper from './PaginationWrapper';
import { withUnstatedContainers } from './UnstatedUtils';
import RevisionLoader from './Page/RevisionLoader';
class PageTimeline extends React.Component {
constructor(props) {
super(props);
const { appContainer } = this.props;
this.showPages = this.showPages.bind(this);
this.handlePage = this.handlePage.bind(this);
this.state = {
activePage: 1,
totalPages: 0,
limit: appContainer.getConfig().recentCreatedLimit,
// TODO: remove after when timeline is implemented with React and inject data with props
pages: this.props.pages,
};
}
async handlePage(selectedPage) {
await this.showPages(selectedPage);
}
async showPages(selectedPage) {
const { appContainer, pageContainer } = this.props;
const { path } = pageContainer.state;
const limit = this.state.limit;
const offset = (selectedPage - 1) * limit;
const res = await appContainer.apiv3Get('/pages/list', { path, limit, offset });
const activePage = selectedPage;
const totalPages = res.data.totalCount;
const pages = res.data.pages;
this.setState({
activePage,
totalPages,
pages,
});
}
componentWillMount() {
const { appContainer } = this.props;
// initialize GrowiRenderer
this.growiRenderer = appContainer.getRenderer('timeline');
this.showPages(1);
}
render() {
const { pages } = this.state;
if (pages == null) {
return