Shun Miyazawa 4 лет назад
Родитель
Сommit
65064b1425

+ 2 - 2
packages/app/src/components/Sidebar/Tag.tsx

@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
 import TagList from '../TagList';
 import TagCloudBox from '../TagCloudBox';
 
-import { useSWRxTagDataList } from '~/stores/tag';
+import { useSWRxTagsList } from '~/stores/tag';
 import { ITagCountHasId } from '~/interfaces/tag';
 
 const LIMIT = 10;
@@ -12,7 +12,7 @@ const LIMIT = 10;
 const Tag: FC = () => {
   const [offset, setOffset] = useState<number>(0);
 
-  const { data: tagDataList, mutate: mutateTagDataList, error } = useSWRxTagDataList(LIMIT, offset);
+  const { data: tagDataList, mutate: mutateTagDataList, error } = useSWRxTagsList(LIMIT, offset);
   const tagData: ITagCountHasId[] = tagDataList?.data || [];
   const totalCount: number = tagDataList?.totalCount || 0;
   const isLoading = tagDataList === undefined && error == null;

+ 2 - 2
packages/app/src/components/TagPage.tsx

@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
 import TagList from './TagList';
 import TagCloudBox from './TagCloudBox';
 
-import { useSWRxTagDataList } from '~/stores/tag';
+import { useSWRxTagsList } from '~/stores/tag';
 import { ITagCountHasId } from '~/interfaces/tag';
 
 const LIMIT = 10;
@@ -12,7 +12,7 @@ const LIMIT = 10;
 const TagPage: FC = () => {
   const [offset, setOffset] = useState<number>(0);
 
-  const { data: tagDataList, error } = useSWRxTagDataList(LIMIT, offset);
+  const { data: tagDataList, error } = useSWRxTagsList(LIMIT, offset);
   const tagData: ITagCountHasId[] = tagDataList?.data || [];
   const totalCount: number = tagDataList?.totalCount || 0;
   const isLoading = tagDataList === undefined && error == null;

+ 1 - 2
packages/app/src/interfaces/tag.ts

@@ -8,7 +8,6 @@ export type ITag = {
 export type ITagCount = Omit<ITag, 'createdAt'> & {count: number}
 
 export type ITagCountHasId = ITagCount & HasObjectId
-export type ITagHasCount = ITag & { count: number }
 
 export type ITagsSearchApiv1Result = {
   ok: boolean,
@@ -17,6 +16,6 @@ export type ITagsSearchApiv1Result = {
 
 export type ITagsListApiv1Result = {
   ok: boolean,
-  data: ITagHasCount[],
+  data: ITagCountHasId[],
   totalCount: number,
 }

+ 2 - 20
packages/app/src/stores/tag.tsx

@@ -1,26 +1,8 @@
 import useSWR, { SWRResponse } from 'swr';
 import useSWRImmutable from 'swr/immutable';
-import { ITagCountHasId } from '~/interfaces/tag';
-import { apiGet } from '~/client/util/apiv1-client';
-
-type ITagDataListResponse = {
-  data: ITagCountHasId[],
-  totalCount: number,
-}
-
-export const useSWRxTagDataList = (
-    limit: number,
-    offset: number,
-): SWRResponse<ITagDataListResponse, Error> => {
-  return useSWR(
-    `/tags.list?limit=${limit}&offset=${offset}`,
-    endpoint => apiGet(endpoint).then((response: ITagDataListResponse) => {
-      return {
-        data: response.data,
-        totalCount: response.totalCount,
-      };
-}))};
 
+import { ITagsListApiv1Result } from '~/interfaces/tag';
+import { apiGet } from '~/client/util/apiv1-client';
 
 export const useSWRxTagsList = (limit?: number, offset?: number): SWRResponse<ITagsListApiv1Result, Error> => {
   return useSWRImmutable(