Mao 4 лет назад
Родитель
Сommit
e565c1c5c5

+ 6 - 8
packages/app/src/components/SearchPage/SearchResultContentSubNavigation.tsx

@@ -1,4 +1,4 @@
-import React, { FC, useEffect, useState } from 'react';
+import React, { FC } from 'react';
 import PagePathNav from '../PagePathNav';
 import { withUnstatedContainers } from '../UnstatedUtils';
 import AppContainer from '../../client/services/AppContainer';
@@ -21,24 +21,22 @@ const SearchResultContentSubNavigation: FC<Props> = (props : Props) => {
     appContainer, pageId, path, isCompactMode, isSignleLineMode,
   } = props;
 
-  const { data: tagData, error, mutate } = useSWRTagsInfo(pageId);
-  let TAGS;
-
-  if (tagData != null) {
-    TAGS = tagData.data.tags;
-    console.log(JSON.stringify(tagData.data.tags));
+  const { data: tagInfoData, error: tagInfoError, mutate: mutateTagInfo } = useSWRTagsInfo(pageId);
+  if (tagInfoError != null || tagInfoData == null) {
+    return <></>;
   }
   const tagsUpdatedHandler = async(newTags) => {
     try {
       await apiPost('/tags.update', { pageId, tags: newTags });
       toastSuccess('updated tags successfully');
-      mutate();
+      mutateTagInfo();
     }
     catch (err) {
       toastError(err, 'fail to update tags');
     }
   };
 
+  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' : ''}`}>

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

@@ -34,22 +34,18 @@ export const useSWRxPageList = (
 };
 
 
-// res
+// response
 // {"data":{"tags":["test","hello"],"ok":true}}
-interface DataInRes {
-  tags: string[];
-  ok : boolean;
-}
-interface Res {
-  data: DataInRes;
+interface ITagInfoData {
+  data : {
+    tags: string[];
+    ok : boolean;
+  };
 }
 
 export const useSWRTagsInfo = (pageId) => {
   return useSWR(`/pages.getPageTag?pageId=${pageId}`, endpoint => apiGet(endpoint).then((response) => {
-    // const res = response as Res;
     return {
-      // res: response,
-      // tags: res.data.tags,
       data: response,
     };
   }));