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.state = {
activePage: 1,
totalPageItems: 0,
limit: appContainer.getConfig().recentCreatedLimit,
// TODO: remove after when timeline is implemented with React and inject data with props
pages: this.props.pages,
};
this.handlePage = this.handlePage.bind(this);
}
async handlePage(selectedPage) {
const { appContainer, pageContainer } = this.props;
const { path } = pageContainer.state;
const { limit } = this.state;
const offset = (selectedPage - 1) * limit;
const activePage = selectedPage;
const res = await appContainer.apiv3Get('/pages/list', { path, limit, offset });
const totalPageItems = res.data.totalCount;
const pages = res.data.pages;
this.setState({
activePage,
totalPageItems,
pages,
});
}
componentWillMount() {
const { appContainer } = this.props;
// initialize GrowiRenderer
this.growiRenderer = appContainer.getRenderer('timeline');
}
async componentDidMount() {
await this.handlePage(1);
this.setState({
activePage: 1,
});
}
render() {
const { pages } = this.state;
if (pages == null) {
return