소스 검색

create swr

Shun Miyazawa 4 년 전
부모
커밋
d2e0dd5fda
2개의 변경된 파일20개의 추가작업 그리고 0개의 파일을 삭제
  1. 7 0
      packages/app/src/components/Admin/AuditLog.tsx
  2. 13 0
      packages/app/src/stores/activity.ts

+ 7 - 0
packages/app/src/components/Admin/AuditLog.tsx

@@ -1,6 +1,13 @@
 import React, { FC } from 'react';
 
+import { useSWRxActivityList } from '~/stores/activity';
+
 const AuditLog: FC = () => {
+  const { data: activityListData } = useSWRxActivityList(5, 0);
+
+  // eslint-disable-next-line @typescript-eslint/no-unused-vars
+  const activityList = activityListData != null ? activityListData : null;
+
   return (
     <>Hello, AuditLog</>
   );

+ 13 - 0
packages/app/src/stores/activity.ts

@@ -0,0 +1,13 @@
+import { SWRResponse } from 'swr';
+import useSWRImmutable from 'swr/immutable';
+
+import { apiv3Get } from '../client/util/apiv3-client';
+import { IActivity } from '../interfaces/activity';
+import { PaginateResult } from '../interfaces/mongoose-utils';
+
+export const useSWRxActivityList = (limit?: number, offset?: number): SWRResponse<PaginateResult<IActivity>, Error> => {
+  return useSWRImmutable(
+    ['/activity/list', limit, offset],
+    (endpoint, limit, offset) => apiv3Get(endpoint, { limit, offset }).then(result => result.data.paginatedActivity),
+  );
+};