Ver Fonte

Remove pagination

https://youtrack.weseek.co.jp/issue/GW-7908
- Remove pagination wrapper from PageHistory
- Create infinite swr data fetching for page revisions
Mudana-Grune há 3 anos atrás
pai
commit
2ebdbf9151

+ 0 - 16
packages/app/src/components/PageHistory.tsx

@@ -7,7 +7,6 @@ import { useSWRxPageRevisions, useCurrentPagePath } from '~/stores/page';
 import loggerFactory from '~/utils/logger';
 
 import { PageRevisionTable } from './PageHistory/PageRevisionTable';
-import PaginationWrapper from './PaginationWrapper';
 import { RevisionComparer } from './RevisionComparer/RevisionComparer';
 
 const logger = loggerFactory('growi:PageHistory');
@@ -45,18 +44,6 @@ export const PageHistory: React.FC<{ onClose: () => void }> = ({ onClose }) => {
     );
   }
 
-  const pager = () => {
-    return (
-      <PaginationWrapper
-        activePage={activePage}
-        changePage={setActivePage}
-        totalItemsCount={revisionsData.totalCounts}
-        pagingLimit={pagingLimit}
-        align="center"
-      />
-    );
-  };
-
   return (
     <div className="revision-history" data-testid="page-history">
       <PageRevisionTable
@@ -70,9 +57,6 @@ export const PageHistory: React.FC<{ onClose: () => void }> = ({ onClose }) => {
         onChangeTargetInvoked={setTargetRevision}
         onClose={onClose}
       />
-      <div className="my-3">
-        {pager()}
-      </div>
       <RevisionComparer
         sourceRevision={sourceRevision}
         targetRevision={targetRevision}

+ 24 - 0
packages/app/src/stores/page.tsx

@@ -6,6 +6,7 @@ import type {
 import { isClient, pagePathUtils } from '@growi/core';
 import useSWR, { Key, SWRResponse } from 'swr';
 import useSWRImmutable from 'swr/immutable';
+import useSWRInfinite, { SWRInfiniteResponse } from 'swr/infinite';
 
 import { apiGet } from '~/client/util/apiv1-client';
 import { apiv3Get } from '~/client/util/apiv3-client';
@@ -143,6 +144,29 @@ export const useSWRxPageRevisions = (
   );
 };
 
+export const useSWRxInfinitePageRevisions = (
+    pageId: string | null | undefined,
+) : SWRInfiniteResponse<(IRevisionsForPagination), Error> => {
+  const LIMIT = 10;
+  const getKey = (page: number) => {
+    return `/revisions/list?pageId=${pageId}&page=${page + 1}&limit=${LIMIT}`;
+  };
+  return useSWRInfinite(
+    getKey,
+    (endpoint: string) => apiv3Get(endpoint).then((response) => {
+      const revisions = {
+        revisions: response.data.docs,
+        totalCounts: response.data.totalDocs,
+      };
+      return revisions;
+    }),
+    {
+      revalidateFirstPage: false,
+      revalidateAll: false,
+    },
+  );
+};
+
 /*
  * Grant normalization fetching hooks
  */