فهرست منبع

comment update

jam411 3 سال پیش
والد
کامیت
698be3805d

+ 9 - 13
packages/app/src/components/Page.tsx

@@ -5,6 +5,7 @@ import React, {
 
 import EventEmitter from 'events';
 
+import { MaxConcurrentPercentage } from 'aws-sdk/clients/cloudformation';
 import dynamic from 'next/dynamic';
 // import { debounce } from 'throttle-debounce';
 
@@ -13,7 +14,7 @@ import { HtmlElementNode } from 'rehype-toc';
 import { toastSuccess, toastError } from '~/client/util/apiNotification';
 import { getOptionsToSave } from '~/client/util/editor';
 import {
-  useIsGuestUser, useCurrentPageTocNode, useShareLinkId, useIsLatestRevision, useEditingMarkdown,
+  useIsGuestUser, useCurrentPageTocNode, useShareLinkId, useIsLatestRevision, useStaticPageData,
 } from '~/stores/context';
 import {
   useSWRxSlackChannels, useIsSlackEnabled, usePageTagsForEditors, useIsEnabledUnsavedWarning,
@@ -50,8 +51,6 @@ type PageSubstanceProps = {
   isMobile?: boolean,
   isSlackEnabled: boolean,
   slackChannels: string,
-  revisionMarkdown: string,
-  isLatestRevision: boolean,
 };
 
 class PageSubstance extends React.Component<PageSubstanceProps> {
@@ -174,11 +173,10 @@ class PageSubstance extends React.Component<PageSubstanceProps> {
 
   override render() {
     const {
-      rendererOptions, page, isMobile, isGuestUser, revisionMarkdown, isLatestRevision,
+      rendererOptions, page, isMobile, isGuestUser,
     } = this.props;
     const { path } = page;
-    const { _id: revisionId } = page.revision;
-    const markdown = isLatestRevision ? page.revision.body : revisionMarkdown;
+    const { _id: revisionId, body: markdown } = page.revision;
 
     return (
       <div className={`mb-5 ${isMobile ? 'page-mobile' : ''}`}>
@@ -226,10 +224,9 @@ export const Page = (props) => {
   const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
   const { mutate: mutateCurrentPageTocNode } = useCurrentPageTocNode();
 
-  // TODO: Refactor useSWRxCurrentPage for keep mutate value.
-  // for History "View this version"
+  // for History "View this version" function on PageAccessoryModal
   const { data: isLatestRevision } = useIsLatestRevision();
-  const { data: markdown } = useEditingMarkdown();
+  const { data: pageWithMetaData } = useStaticPageData();
 
   const pageRef = useRef(null);
 
@@ -266,7 +263,7 @@ export const Page = (props) => {
   //   };
   // }, []);
 
-  if (currentPage == null || editorMode == null || isGuestUser == null || rendererOptions == null || markdown == null || isLatestRevision == null) {
+  if (currentPage == null || editorMode == null || isGuestUser == null || rendererOptions == null) {
     const entries = Object.entries({
       currentPage, editorMode, isGuestUser, rendererOptions,
     })
@@ -277,13 +274,14 @@ export const Page = (props) => {
     return null;
   }
 
+  const page = ((pageWithMetaData != null && isLatestRevision != null) && !isLatestRevision) ? pageWithMetaData : currentPage;
 
   return (
     <PageSubstance
       {...props}
       ref={pageRef}
       rendererOptions={rendererOptions}
-      page={currentPage}
+      page={page}
       editorMode={editorMode}
       isGuestUser={isGuestUser}
       isMobile={isMobile}
@@ -291,8 +289,6 @@ export const Page = (props) => {
       pageTags={pageTags}
       slackChannels={slackChannelsData?.toString()}
       mutateIsEnabledUnsavedWarning={mutateIsEnabledUnsavedWarning}
-      revisionMarkdown={markdown}
-      isLatestRevision={isLatestRevision}
     />
   );
 };

+ 3 - 1
packages/app/src/pages/[[...path]].page.tsx

@@ -66,6 +66,7 @@ import {
   useCsrfToken, useIsSearchScopeChildrenAsDefault, useCurrentPageId, useCurrentPathname,
   useIsSlackConfigured, useRendererConfig, useEditingMarkdown,
   useEditorConfig, useIsAllReplyShown, useIsUploadableFile, useIsUploadableImage, useCustomizedLogoSrc,
+  useStaticPageData,
 } from '../stores/context';
 
 import {
@@ -242,8 +243,9 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
   useCurrentPagePath(pagePath);
   useCurrentPathname(props.currentPathname);
 
-  // useSWRxCurrentPage(undefined, pageWithMeta?.data ?? null); // store initial data
+  useSWRxCurrentPage(undefined, pageWithMeta?.data ?? null); // store initial data
   useEditingMarkdown(pageWithMeta?.data.revision?.body ?? '');
+  useStaticPageData(pageWithMeta?.data); // store page data statically for History function on PageAccessoryModal
 
   const { data: dataPageInfo } = useSWRxPageInfo(pageId);
   const { data: grantData } = useSWRxIsGrantNormalized(pageId);

+ 5 - 1
packages/app/src/stores/context.tsx

@@ -1,4 +1,4 @@
-import { IUser, pagePathUtils } from '@growi/core';
+import { IUser, pagePathUtils, IPagePopulatedToShowRevision } from '@growi/core';
 import { HtmlElementNode } from 'rehype-toc';
 import { Key, SWRResponse } from 'swr';
 import useSWRImmutable from 'swr/immutable';
@@ -216,6 +216,10 @@ export const useCustomizedLogoSrc = (initialData?: string): SWRResponse<string,
   return useStaticSWR('customizedLogoSrc', initialData);
 };
 
+export const useStaticPageData = (initialData?: IPagePopulatedToShowRevision): SWRResponse<IPagePopulatedToShowRevision, Error> => {
+  return useStaticSWR('staticPageData', initialData);
+};
+
 /** **********************************************************
  *                     Computed contexts
  *********************************************************** */

+ 5 - 5
packages/app/src/stores/page.tsx

@@ -46,11 +46,11 @@ export const useSWRxCurrentPage = (
 
   const swrResult = useSWRxPage(currentPageId, shareLinkId);
 
-  // // use mutate because fallbackData does not work
-  // // see: https://github.com/weseek/growi/commit/5038473e8d6028c9c91310e374a7b5f48b921a15
-  // if (initialData !== undefined) {
-  //   swrResult.mutate(initialData);
-  // }
+  // use mutate because fallbackData does not work
+  // see: https://github.com/weseek/growi/commit/5038473e8d6028c9c91310e374a7b5f48b921a15
+  if (initialData !== undefined) {
+    swrResult.mutate(initialData);
+  }
 
   return swrResult;
 };