Просмотр исходного кода

rename pageId to currentPageId

keigo-h 3 лет назад
Родитель
Сommit
fb1189f9cc

+ 4 - 4
packages/app/src/components/ShareLink/ShareLink.tsx

@@ -17,9 +17,9 @@ const ShareLink = (): JSX.Element => {
   const { t } = useTranslation();
   const [isOpenShareLinkForm, setIsOpenShareLinkForm] = useState<boolean>(false);
 
-  const { data: pageId } = useCurrentPageId();
+  const { data: currentPageId } = useCurrentPageId();
 
-  const { data, mutate } = useSWRxSharelink();
+  const { data, mutate } = useSWRxSharelink(currentPageId);
 
   const toggleShareLinkFormHandler = useCallback(() => {
     setIsOpenShareLinkForm(prev => !prev);
@@ -28,7 +28,7 @@ const ShareLink = (): JSX.Element => {
 
   const deleteAllLinksButtonHandler = useCallback(async() => {
     try {
-      const res = await apiv3Delete('/share-links/', { relatedPage: pageId });
+      const res = await apiv3Delete('/share-links/', { relatedPage: currentPageId });
       const count = res.data.n;
       toastSuccess(t('toaster.remove_share_link', { count }));
       mutate();
@@ -36,7 +36,7 @@ const ShareLink = (): JSX.Element => {
     catch (err) {
       toastError(err);
     }
-  }, [mutate, pageId, t]);
+  }, [mutate, currentPageId, t]);
 
   const deleteLinkById = useCallback(async(shareLinkId) => {
     try {

+ 4 - 7
packages/app/src/stores/share-link.tsx

@@ -1,17 +1,14 @@
 import useSWR, { SWRResponse } from 'swr';
 
 import { apiv3Get } from '~/client/util/apiv3-client';
+import { Nullable } from '~/interfaces/common';
 import { IResShareLinkList } from '~/interfaces/share-link';
 
-import { useCurrentPageId } from './context';
-
-
-const fetchShareLinks = async(endpoint, pageId): Promise<IResShareLinkList['shareLinksResult']> => {
+const fetchShareLinks = async(endpoint, pageId) => {
   const res = await apiv3Get<IResShareLinkList>(endpoint, { relatedPage: pageId });
   return res.data.shareLinksResult;
 };
 
-export const useSWRxSharelink = (): SWRResponse<IResShareLinkList['shareLinksResult'], Error> => {
-  const { data: currentPageId } = useCurrentPageId();
-  return useSWR('/share-links/', (endpoint => fetchShareLinks(endpoint, currentPageId)));
+export const useSWRxSharelink = (currentPageId: Nullable<string>): SWRResponse<IResShareLinkList['shareLinksResult'], Error> => {
+  return useSWR(['/share-links/', currentPageId], (endpoint => fetchShareLinks(endpoint, currentPageId)));
 };