Răsfoiți Sursa

set initial data to useStaticPageTags arg and clean code

kaori 3 ani în urmă
părinte
comite
8d83ccefbc

+ 4 - 5
packages/app/src/components/Navbar/GrowiContextualSubNavigation.tsx

@@ -167,7 +167,7 @@ const GrowiContextualSubNavigation = (props) => {
   const { data: isAbleToShowPageAuthors } = useIsAbleToShowPageAuthors();
 
   const { mutate: mutateSWRTagsInfo, data: tagsInfoData } = useSWRxTagsInfo(pageId);
-  const { data: tagsOnEditorMode, mutate: mutateEditorContainerTags } = useStaticPageTags(pageId);
+  const { data: tagsOnEditorMode, mutate: mutateEditorContainerTags } = useStaticPageTags(tagsInfoData?.tags);
 
   const { open: openDuplicateModal } = usePageDuplicateModal();
   const { open: openRenameModal } = usePageRenameModal();
@@ -185,7 +185,6 @@ const GrowiContextualSubNavigation = (props) => {
     // It will not be reflected in the DB until the page is refreshed
     if (editorMode === EditorMode.Editor) {
       console.log('newTags', newTags);
-      // return editorContainer.setState({ tags: newTags });
       return mutateEditorContainerTags(newTags);
     }
 
@@ -194,9 +193,7 @@ const GrowiContextualSubNavigation = (props) => {
 
       // revalidate SWRTagsInfo
       mutateSWRTagsInfo();
-      mutateEditorContainerTags(newTags);
-      // update editorContainer.state
-      // editorContainer.setState({ tags });
+      mutateEditorContainerTags(newTags, false);
 
       toastSuccess('updated tags successfully');
     }
@@ -318,6 +315,8 @@ const GrowiContextualSubNavigation = (props) => {
     updatedAt: updatedAt ?? undefined,
   };
 
+  console.log('tagsOnEditorMode', tagsOnEditorMode);
+
   return (
     <GrowiSubNavigation
       page={currentPage}

+ 3 - 3
packages/app/src/stores/editor.tsx

@@ -94,7 +94,7 @@ export const useIsSlackEnabled = (): SWRResponse<boolean, Error> => {
   );
 };
 
-export const useStaticPageTags = (): SWRResponse<ITagNames, Error> => {
-  const { data: pageTags } = useSWRxPageTags();
-  return useStaticSWR<ITagNames, Error>('pageTags', undefined, { fallbackData: pageTags });
+export const useStaticPageTags = (initialTags?: ITagNames): SWRResponse<ITagNames, Error> => {
+  // const { data: pageTags } = useSWRxPageTags();
+  return useStaticSWR<ITagNames, Error>('pageTags', undefined, { fallbackData: initialTags || [] });
 };