Yuki Takei 4 лет назад
Родитель
Сommit
74856ced06

+ 3 - 3
packages/app/src/components/Navbar/SubNavButtons.tsx

@@ -5,7 +5,7 @@ import { apiv3Put } from '../../client/util/apiv3-client';
 
 import { IPageInfo, isExistPageInfo } from '~/interfaces/page';
 
-import { useSWRPageInfo } from '../../stores/page';
+import { useSWRxPageInfo } from '../../stores/page';
 import { useSWRBookmarkInfo } from '../../stores/bookmark';
 import { useSWRxUsersList } from '../../stores/user';
 import { useIsGuestUser } from '~/stores/context';
@@ -33,7 +33,7 @@ const SubNavButtonsSubstance = (props: SubNavButtonsSubstanceProps): JSX.Element
 
   const { data: isGuestUser } = useIsGuestUser();
 
-  const { mutate: mutatePageInfo } = useSWRPageInfo(pageId);
+  const { mutate: mutatePageInfo } = useSWRxPageInfo(pageId);
 
   const { data: likers } = useSWRxUsersList(pageInfo.likerIds);
   const { data: bookmarkInfo, error: bookmarkInfoError, mutate: mutateBookmarkInfo } = useSWRBookmarkInfo(pageId, true);
@@ -140,7 +140,7 @@ type SubNavButtonsProps= CommonProps & {
 export const SubNavButtons = (props: SubNavButtonsProps): JSX.Element => {
   const { pageId, isCompactMode } = props;
 
-  const { data: pageInfo, error } = useSWRPageInfo(pageId ?? null);
+  const { data: pageInfo, error } = useSWRxPageInfo(pageId ?? null);
 
   if (pageId == null || pageInfo == null || error != null) {
     return <></>;

+ 1 - 9
packages/app/src/stores/page.tsx

@@ -46,13 +46,6 @@ export const useSWRxPageList = (
   );
 };
 
-export const useSWRPageInfo = (pageId: string | null): SWRResponse<IPageInfoCommon | IPageInfo, Error> => {
-  return useSWR(
-    pageId != null ? `/page/info?pageId=${pageId}` : null,
-    endpoint => apiv3Get<IPageInfoCommon | IPageInfo>(endpoint).then(response => response.data),
-  );
-};
-
 export const useSWRTagsInfo = (pageId: string | null | undefined): SWRResponse<IPageTagsInfo, Error> => {
   const key = pageId == null ? null : `/pages.getPageTag?pageId=${pageId}`;
 
@@ -63,8 +56,7 @@ export const useSWRTagsInfo = (pageId: string | null | undefined): SWRResponse<I
   }));
 };
 
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-export const useSWRxPageInfo = <Data, Error>(pageId: string | undefined): SWRResponse<IPageInfo, Error> => {
+export const useSWRxPageInfo = (pageId: string | null | undefined): SWRResponse<IPageInfoCommon | IPageInfo, Error> => {
   return useSWR(
     pageId != null ? ['/page/info', pageId] : null,
     (endpoint, pageId) => apiv3Get(endpoint, { pageId }).then(response => response.data),