Yuki Takei 3 лет назад
Родитель
Сommit
9a95628ecb
2 измененных файлов с 12 добавлено и 11 удалено
  1. 1 3
      packages/app/src/interfaces/attachment.ts
  2. 11 8
      packages/app/src/stores/attachment.tsx

+ 1 - 3
packages/app/src/interfaces/attachment.ts

@@ -4,7 +4,5 @@ import type { PaginateResult } from './mongoose-utils';
 
 
 
 
 export type IResAttachmentList = {
 export type IResAttachmentList = {
-  data: {
-    paginateResult: PaginateResult<IAttachment & HasObjectId>
-  }
+  paginateResult: PaginateResult<IAttachment & HasObjectId>
 };
 };

+ 11 - 8
packages/app/src/stores/attachment.tsx

@@ -6,7 +6,8 @@ import {
 } from '@growi/core';
 } from '@growi/core';
 import useSWR from 'swr';
 import useSWR from 'swr';
 
 
-import { apiGet, apiPost } from '~/client/util/apiv1-client';
+import { apiPost } from '~/client/util/apiv1-client';
+import { apiv3Get } from '~/client/util/apiv3-client';
 import { IResAttachmentList } from '~/interfaces/attachment';
 import { IResAttachmentList } from '~/interfaces/attachment';
 
 
 type Util = {
 type Util = {
@@ -22,17 +23,19 @@ type IDataAttachmentList = {
 export const useSWRxAttachments = (pageId?: Nullable<string>, pageNumber?: number): SWRResponseWithUtils<Util, IDataAttachmentList, Error> => {
 export const useSWRxAttachments = (pageId?: Nullable<string>, pageNumber?: number): SWRResponseWithUtils<Util, IDataAttachmentList, Error> => {
   const shouldFetch = pageId != null && pageNumber != null;
   const shouldFetch = pageId != null && pageNumber != null;
 
 
-  const fetcher = useCallback(async(endpoint) => {
-    const res = await apiGet<IResAttachmentList>(endpoint, { pageId, pageNumber });
+  const fetcher = useCallback(async(endpoint, pageId, pageNumber) => {
+    const res = await apiv3Get<IResAttachmentList>(endpoint, { pageId, pageNumber });
+    const resAttachmentList = res.data;
+    const { paginateResult } = resAttachmentList;
     return {
     return {
-      attachments: res.data.paginateResult.docs,
-      totalAttachments: res.data.paginateResult.totalDocs,
-      limit: res.data.paginateResult.limit,
+      attachments: paginateResult.docs,
+      totalAttachments: paginateResult.totalDocs,
+      limit: paginateResult.limit,
     };
     };
-  }, [pageId, pageNumber]);
+  }, []);
 
 
   const swrResponse = useSWR(
   const swrResponse = useSWR(
-    shouldFetch ? ['/attachments/list', pageId, pageNumber] : null,
+    shouldFetch ? ['/attachment/list', pageId, pageNumber] : null,
     fetcher,
     fetcher,
   );
   );