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

+ 10 - 17
src/client/js/components/PageAttachment.jsx

@@ -14,12 +14,10 @@ class PageAttachment extends React.Component {
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
 
 
-    const { appContainer } = this.props;
-
     this.state = {
     this.state = {
       activePage: 1,
       activePage: 1,
       totalPages: 0,
       totalPages: 0,
-      limit: appContainer.getConfig().recentCreatedLimit,
+      limit: 10,
       attachments: [],
       attachments: [],
       inUse: {},
       inUse: {},
       attachmentToDelete: null,
       attachmentToDelete: null,
@@ -27,47 +25,43 @@ class PageAttachment extends React.Component {
       deleteError: '',
       deleteError: '',
     };
     };
     this.handlePage = this.handlePage.bind(this);
     this.handlePage = this.handlePage.bind(this);
-    this.showPage = this.showPage.bind(this);
-
+    this.showPages = this.showPages.bind(this);
     this.onAttachmentDeleteClicked = this.onAttachmentDeleteClicked.bind(this);
     this.onAttachmentDeleteClicked = this.onAttachmentDeleteClicked.bind(this);
     this.onAttachmentDeleteClickedConfirm = this.onAttachmentDeleteClickedConfirm.bind(this);
     this.onAttachmentDeleteClickedConfirm = this.onAttachmentDeleteClickedConfirm.bind(this);
   }
   }
 
 
   async handlePage(selectedPage) {
   async handlePage(selectedPage) {
-    await this.showPage(selectedPage);
+    await this.showPages(selectedPage);
   }
   }
 
 
-  async showPage(selectedPage) {
+  async showPages(selectedPage) {
     const { appContainer, pageContainer } = this.props;
     const { appContainer, pageContainer } = this.props;
     const { pageId } = pageContainer.state;
     const { pageId } = pageContainer.state;
     const { limit } = this.state;
     const { limit } = this.state;
-    const offset = (selectedPage - 1) * limit;
+    const offset = (selectedPage - 1) * limit || 0;
     const res = await appContainer.apiv3Get('/attachment/list', { pageId, limit, offset });
     const res = await appContainer.apiv3Get('/attachment/list', { pageId, limit, offset });
     const pagination = res.data.result.pagination;
     const pagination = res.data.result.pagination;
-
-    this.setState({
+    await this.setState({
       activePage: selectedPage,
       activePage: selectedPage,
       totalPages: pagination.totalPages,
       totalPages: pagination.totalPages,
       limit: pagination.limit,
       limit: pagination.limit,
     });
     });
   }
   }
 
 
+  componentWillMount() {
+    this.showPages(1);
+  }
 
 
   async componentDidMount() {
   async componentDidMount() {
 
 
-    this.showPage();
-
     const { appContainer } = this.props;
     const { appContainer } = this.props;
     const { pageId } = this.props.pageContainer.state;
     const { pageId } = this.props.pageContainer.state;
-    const { limit } = this.state.limit;
-    const offset = 0;
 
 
     if (!pageId) { return }
     if (!pageId) { return }
 
 
     const inUse = {};
     const inUse = {};
-    const res = await appContainer.apiv3Get('/attachment/list', { pageId, limit, offset });
+    const res = await appContainer.apiv3Get('/attachment/list', { pageId });
     const attachments = res.data.result.attachments;
     const attachments = res.data.result.attachments;
-    console.log(this.state.totalPages);
 
 
 
 
     for (const attachment of attachments) {
     for (const attachment of attachments) {
@@ -77,7 +71,6 @@ class PageAttachment extends React.Component {
       attachments,
       attachments,
       inUse,
       inUse,
     });
     });
-
   }
   }
 
 
   checkIfFileInUse(attachment) {
   checkIfFileInUse(attachment) {