kaori 3 лет назад
Родитель
Сommit
bc2be833ca

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

@@ -2,7 +2,7 @@ import React, { FC, useState, useCallback } from 'react';
 
 import { useTranslation } from 'react-i18next';
 
-import { ITag } from '~/interfaces/tag';
+import { ITagCount } from '~/interfaces/tag';
 import { useSWRxTagsList } from '~/stores/tag';
 
 import TagCloudBox from '../TagCloudBox';
@@ -16,7 +16,7 @@ const Tag: FC = () => {
   const [offset, setOffset] = useState<number>(0);
 
   const { data: tagDataList, mutate: mutateTagDataList, error } = useSWRxTagsList(PAGING_LIMIT, offset);
-  const tagData: ITag[] = tagDataList?.data || [];
+  const tagData: ITagCount[] = tagDataList?.data || [];
   const totalCount: number = tagDataList?.totalCount || 0;
   const isLoading = tagDataList === undefined && error == null;
 

+ 3 - 3
packages/app/src/components/TagCloudBox.tsx

@@ -2,10 +2,10 @@ import React, { FC, memo } from 'react';
 
 import { TagCloud } from 'react-tagcloud';
 
-import { ITag } from '~/interfaces/tag';
+import { ITagCount } from '~/interfaces/tag';
 
 type Props = {
-  tags:ITag[],
+  tags:ITagCount[],
   minSize?: number,
   maxSize?: number,
   maxTagTextLength?: number,
@@ -31,7 +31,7 @@ const TagCloudBox: FC<Props> = memo((props:(Props & typeof defaultProps)) => {
       <TagCloud
         minSize={minSize ?? MIN_FONT_SIZE}
         maxSize={maxSize ?? MAX_FONT_SIZE}
-        tags={tags.map((tag:ITag) => {
+        tags={tags.map((tag:ITagCount) => {
           return {
             // text truncation
             value: (tag.name).length > maxTagTextLength ? `${(tag.name).slice(0, maxTagTextLength)}...` : tag.name,

+ 3 - 3
packages/app/src/components/TagList.tsx

@@ -4,12 +4,12 @@ import React, {
 
 import { useTranslation } from 'react-i18next';
 
-import { ITag } from '~/interfaces/tag';
+import { ITagCount } from '~/interfaces/tag';
 
 import PaginationWrapper from './PaginationWrapper';
 
 type TagListProps = {
-  tagData: ITag[],
+  tagData: ITagCount[],
   totalTags: number,
   activePage: number,
   onChangePage?: (selectedPageNumber: number) => void,
@@ -29,7 +29,7 @@ const TagList: FC<TagListProps> = (props:(TagListProps & typeof defaultProps)) =
   const { t } = useTranslation('');
 
   const generateTagList = useCallback((tagData) => {
-    return tagData.map((tag:ITag, index:number) => {
+    return tagData.map((tag:ITagCount, index:number) => {
       const tagListClasses: string = index === 0 ? 'list-group-item d-flex' : 'list-group-item d-flex border-top-0';
 
       return (

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

@@ -2,7 +2,7 @@ import React, { FC, useState, useCallback } from 'react';
 
 import { useTranslation } from 'react-i18next';
 
-import { ITag } from '~/interfaces/tag';
+import { ITagCount } from '~/interfaces/tag';
 import { useSWRxTagsList } from '~/stores/tag';
 
 import TagCloudBox from './TagCloudBox';
@@ -15,7 +15,7 @@ const TagPage: FC = () => {
   const [offset, setOffset] = useState<number>(0);
 
   const { data: tagDataList, error } = useSWRxTagsList(PAGING_LIMIT, offset);
-  const tagData: ITag[] = tagDataList?.data || [];
+  const tagData: ITagCount[] = tagDataList?.data || [];
   const totalCount: number = tagDataList?.totalCount || 0;
   const isLoading = tagDataList === undefined && error == null;
 

+ 4 - 3
packages/app/src/interfaces/tag.ts

@@ -1,10 +1,11 @@
 export type ITag<ID = string> = {
   _id: ID
   name: string,
-  createdAt: Date;
-  count: number;
 }
 
+export type ITagCount = ITag & {count: number}
+
+
 export type ITagsSearchApiv1Result = {
   ok: boolean,
   tags: string[]
@@ -12,6 +13,6 @@ export type ITagsSearchApiv1Result = {
 
 export type ITagsListApiv1Result = {
   ok: boolean,
-  data: ITag[],
+  data: ITagCount[],
   totalCount: number,
 }