Просмотр исходного кода

add appContainer.getConfig().recentCreatedLimit()

zahmis 5 лет назад
Родитель
Сommit
f3da717c4c
1 измененных файлов с 27 добавлено и 3 удалено
  1. 27 3
      src/client/js/components/PageAttachment.jsx

+ 27 - 3
src/client/js/components/PageAttachment.jsx

@@ -15,6 +15,7 @@ class PageAttachment extends React.Component {
     super(props);
 
     const { appContainer } = this.props;
+    this.showPages = this.showPages.bind(this);
     this.handlePage = this.handlePage.bind(this);
 
     this.state = {
@@ -24,14 +25,19 @@ class PageAttachment extends React.Component {
       deleting: false,
       deleteError: '',
       activePage: 1,
-      totalPage: 0,
-      limit: appContainer.getConfig(),
+      totalPages: 0,
+      limit: appContainer.getConfig().recentCreatedLimit,
+
     };
 
     this.onAttachmentDeleteClicked = this.onAttachmentDeleteClicked.bind(this);
     this.onAttachmentDeleteClickedConfirm = this.onAttachmentDeleteClickedConfirm.bind(this);
   }
 
+  // componentWillMount() {
+  //   this.showPages(1);
+  // }
+
   componentDidMount() {
     const { pageId } = this.props.pageContainer.state;
 
@@ -55,6 +61,24 @@ class PageAttachment extends React.Component {
       });
   }
 
+  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;
+    this.setState({
+      activePage,
+      totalPages,
+    });
+  }
+
   checkIfFileInUse(attachment) {
     const { markdown } = this.props.pageContainer.state;
 
@@ -143,7 +167,7 @@ class PageAttachment extends React.Component {
         <PaginationWrapper
           activePage={this.state.activePage}
           changePage={this.handlePage}
-          totalItemCount={this.state.totalPage}
+          totalItemCount={this.state.totalPages}
           pagingLimit={this.state.limit}
         />
       </div>