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

+ 29 - 20
src/client/js/components/PageAttachment.jsx

@@ -15,7 +15,7 @@ class PageAttachment extends React.Component {
     super(props);
 
     const { appContainer } = this.props;
-    this.handlePage = this.handlePage.bind(this);
+
     this.state = {
       activePage: 1,
       totalPages: 0,
@@ -26,47 +26,56 @@ class PageAttachment extends React.Component {
       deleting: false,
       deleteError: '',
     };
+    this.handlePage = this.handlePage.bind(this);
+    this.showPage = this.showPage.bind(this);
 
     this.onAttachmentDeleteClicked = this.onAttachmentDeleteClicked.bind(this);
     this.onAttachmentDeleteClickedConfirm = this.onAttachmentDeleteClickedConfirm.bind(this);
   }
 
   async handlePage(selectedPage) {
-    await this.showPages(selectedPage);
+    await this.showPage(selectedPage);
   }
 
-  async showPages(selectedPage) {
-    const { pageId } = this.props.pageContainer.state;
+  async showPage(selectedPage) {
+    const { appContainer, pageContainer } = this.props;
+    const { pageId } = pageContainer;
+    const { limit } = this.state.limit;
+    const offset = (selectedPage - 1) * limit;
+    const res = await appContainer.apiv3Get('/attachment/list', { pageId, limit, offset });
+    const pagination = res.data.result.pagination;
 
-    if (!pageId) {
-      return;
-    }
+    this.setState({
+      activePage: selectedPage,
+      totalPages: pagination.totalPages,
+      limit: pagination.limit,
+    });
+  }
 
-    const { limit } = this.props.appContainer.state;
-    const offset = (selectedPage - 1) * limit;
 
-    const res = await this.props.appContainer.apiv3Get('/attachment/list', { pageId, limit, offset });
+  async componentDidMount() {
 
-    const attachments = res.data.result.attachments;
-    const pagination = res.data.result.pagination;
+    const { appContainer } = this.props;
+    const { pageId } = this.props.pageContainer;
+    const { limit } = this.state.limit;
+    const offset = 0;
+
+    if (!pageId) { return }
     const inUse = {};
+    const res = await appContainer.apiv3Get('/attachment/list', { pageId, limit, offset });
+    const attachments = res.data.result.attachments;
+
+    console.log('hoge');
 
     for (const attachment of attachments) {
       inUse[attachment._id] = this.checkIfFileInUse(attachment);
     }
-
     this.setState({
-      activePage: selectedPage,
       attachments,
       inUse,
-      totalPages: pagination.totalPages,
-      limit: pagination.limit,
     });
-  }
 
-  async componentDidMount() {
-    this.showPages(0);
-    console.log(this.state.activePage);
+    this.showPage();
   }
 
   checkIfFileInUse(attachment) {