soumaeda 2 лет назад
Родитель
Сommit
b0fd0bdc4e

+ 0 - 5
apps/app/src/components/PageSideContents/PageSideContents.tsx

@@ -6,9 +6,6 @@ import { useTranslation } from 'next-i18next';
 import dynamic from 'next/dynamic';
 import { Link } from 'react-scroll';
 
-import { useUpdateStateAfterSave } from '~/client/services/page-operation';
-import { apiPost } from '~/client/util/apiv1-client';
-import { toastSuccess, toastError } from '~/client/util/toastr';
 import { useIsGuestUser, useIsReadOnlyUser } from '~/stores/context';
 import { useDescendantsPageListModal } from '~/stores/modal';
 import { useSWRxPageInfo, useSWRxTagsInfo } from '~/stores/page';
@@ -46,8 +43,6 @@ const Tags = (props: TagsProps): JSX.Element => {
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
 
-  const updateStateAfterSave = useUpdateStateAfterSave(pageId);
-
   if (!showTagLabel) {
     return <></>;
   }

+ 13 - 11
apps/app/src/components/PageTags/RenderTagLabels.tsx

@@ -30,16 +30,18 @@ const RenderTagLabels = React.memo((props: RenderTagLabelsProps) => {
 
   return (
     <>
-      {tags.map(tag => (
-        <a
-          key={tag}
-          type="button"
-          className="grw-tag-label badge bg-primary me-2"
-          onClick={() => pushState(`tag:${tag}`)}
-        >
-          {tag}
-        </a>
-      ))}
+      {tags.map((tag) => {
+        return (
+          <a
+            key={tag}
+            type="button"
+            className="grw-tag-label badge bg-primary me-2"
+            onClick={() => pushState(`tag:${tag}`)}
+          >
+            {tag}
+          </a>
+        );
+      })}
       <NotAvailableForGuest>
         <NotAvailableForReadOnlyUser>
           <div id="edit-tags-btn-wrapper-for-tooltip">
@@ -51,7 +53,7 @@ const RenderTagLabels = React.memo((props: RenderTagLabelsProps) => {
               }
               onClick={() => openTagEditModal(tagsInfoData?.tags, pageId, revisionId)}
             >
-              {isTagsEmpty && <> {t('Add tags for this page')}</>}
+              {isTagsEmpty && <>{ t('Add tags for this page') }</>}
               <i className={`icon-plus ${isTagsEmpty && 'ms-1'}`} />
             </a>
           </div>

+ 4 - 6
apps/app/src/components/PageTags/TagEditModal.tsx

@@ -9,7 +9,6 @@ import { useUpdateStateAfterSave } from '~/client/services/page-operation';
 import { apiPost } from '~/client/util/apiv1-client';
 import { toastError, toastSuccess } from '~/client/util/toastr';
 import { useTagEditModal } from '~/stores/modal';
-import { useSWRxTagsInfo } from '~/stores/page';
 
 import { TagsInput } from './TagsInput';
 
@@ -22,16 +21,15 @@ export const TagEditModal: React.FC = () => {
   const pageId = tagEditModalData?.pageId;
   const revisionId = tagEditModalData?.revisionId;
   const updateStateAfterSave = useUpdateStateAfterSave(pageId);
-  const { data: tagsInfoData } = useSWRxTagsInfo(pageId);
 
   useEffect(() => {
     setTags(tags);
   }, [tags]);
 
-  const handleSubmit = useCallback(async() => {
+  const handleSubmit = useCallback(async(newTags: string[]) => {
 
     try {
-      await apiPost('/tags.update', { pageId, revisionId, tags });
+      await apiPost('/tags.update', { pageId, revisionId, tags: newTags });
       updateStateAfterSave?.();
 
       toastSuccess('updated tags successfully');
@@ -40,7 +38,7 @@ export const TagEditModal: React.FC = () => {
       toastError(err);
     }
     closeTagEditModal();
-  }, [closeTagEditModal, pageId, revisionId, tags, updateStateAfterSave]);
+  }, [closeTagEditModal, pageId, revisionId, updateStateAfterSave]);
 
   return (
     <Modal isOpen={isOpen} toggle={closeTagEditModal} id="edit-tag-modal" autoFocus={false}>
@@ -51,7 +49,7 @@ export const TagEditModal: React.FC = () => {
         <TagsInput tags={tags} onTagsUpdated={tags => setTags(tags)} autoFocus />
       </ModalBody>
       <ModalFooter>
-        <button type="button" className="btn btn-primary" onClick={handleSubmit}>
+        <button type="button" className="btn btn-primary" onClick={() => handleSubmit(tags)}>
           {t('tag_edit_modal.done')}
         </button>
       </ModalFooter>