Browse Source

80623 ts type

Mao 4 years ago
parent
commit
e045e4dc4a

+ 1 - 2
packages/app/src/components/SearchPage/SearchResultContentSubNavigation.tsx

@@ -36,7 +36,6 @@ const SearchResultContentSubNavigation: FC<Props> = (props : Props) => {
     }
   };
 
-  const TAGS = tagInfoData.data.tags;
   const { isSharedUser } = appContainer;
   return (
     <div className={`grw-subnav container-fluid d-flex align-items-center justify-content-between ${isCompactMode ? 'grw-subnav-compact d-print-none' : ''}`}>
@@ -44,7 +43,7 @@ const SearchResultContentSubNavigation: FC<Props> = (props : Props) => {
       <div className="grw-path-nav-container">
         {!isSharedUser && !isCompactMode && (
           <div className="grw-taglabels-container">
-            <TagLabels tags={TAGS} tagsUpdateInvoked={tagsUpdatedHandler} />
+            <TagLabels tags={tagInfoData.tags} tagsUpdateInvoked={tagsUpdatedHandler} />
           </div>
         )}
         <PagePathNav pageId={pageId} pagePath={path} isCompactMode={isCompactMode} isSingleLineMode={isSignleLineMode} />

+ 3 - 0
packages/app/src/interfaces/pageTagsInfo.ts

@@ -0,0 +1,3 @@
+export type IPageTagsInfo = {
+  tags : string[],
+}

+ 6 - 12
packages/app/src/stores/page.tsx

@@ -5,6 +5,7 @@ import { apiGet } from '../client/util/apiv1-client';
 
 import { IPage } from '~/interfaces/page';
 import { IPagingResult } from '~/interfaces/paging-result';
+import { IPageTagsInfo } from '../interfaces/pageTagsInfo';
 
 
 // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -34,19 +35,12 @@ export const useSWRxPageList = (
 };
 
 
-// response
-// {"data":{"tags":["test","hello"],"ok":true}}
-interface ITagInfoData {
-  data : {
-    tags: string[];
-    ok : boolean;
-  };
-}
-
-export const useSWRTagsInfo = (pageId) => {
-  return useSWR(`/pages.getPageTag?pageId=${pageId}`, endpoint => apiGet(endpoint).then((response) => {
+export const useSWRTagsInfo = (pageId: string) : SWRResponse<IPageTagsInfo, Error> => {
+  // apiGet returns Promise<unknown>
+  // eslint-disable-next-line @typescript-eslint/no-explicit-any
+  return useSWR(`/pages.getPageTag?pageId=${pageId}`, endpoint => apiGet(endpoint).then((response: any) => {
     return {
-      data: response,
+      tags: response.data.tags,
     };
   }));
 };