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

Revert "Use SWR hook to determine if old revisions are being displayed"

This reverts commit 61765bbb71ff7bc2be333e4d329d7ca734410062.
Shun Miyazawa 2 лет назад
Родитель
Сommit
7243b3c175

+ 6 - 5
apps/app/src/components/Page/DisplaySwitcher.tsx

@@ -4,7 +4,8 @@ import dynamic from 'next/dynamic';
 
 import { useHashChangedEffect } from '~/client/services/side-effects/hash-changed';
 import { usePageUpdatedEffect } from '~/client/services/side-effects/page-updated';
-import { useIsEditable, useIsOldRevisionPage } from '~/stores/context';
+import { useIsEditable } from '~/stores/context';
+import { useIsLatestRevision } from '~/stores/page';
 import { EditorMode, useEditorMode } from '~/stores/ui';
 
 import { LazyRenderer } from '../Common/LazyRenderer';
@@ -21,7 +22,7 @@ export const DisplaySwitcher = (props: Props): JSX.Element => {
 
   const { data: editorMode = EditorMode.View } = useEditorMode();
   const { data: isEditable } = useIsEditable();
-  const { data: isOldRevisionPage } = useIsOldRevisionPage();
+  const { data: isLatestRevision } = useIsLatestRevision();
 
   usePageUpdatedEffect();
   useHashChangedEffect();
@@ -33,9 +34,9 @@ export const DisplaySwitcher = (props: Props): JSX.Element => {
       { isViewMode && pageView }
 
       <LazyRenderer shouldRender={isEditable === true && editorMode === EditorMode.Editor}>
-        { isOldRevisionPage
-          ? <PageEditorReadOnly />
-          : <PageEditor />
+        { isLatestRevision
+          ? <PageEditor />
+          : <PageEditorReadOnly />
         }
       </LazyRenderer>
     </>

+ 3 - 4
apps/app/src/components/PageAlert/OldRevisionAlert.tsx

@@ -4,16 +4,15 @@ import { returnPathForURL } from '@growi/core/dist/utils/path-utils';
 import Link from 'next/link';
 import { useTranslation } from 'react-i18next';
 
-import { useIsOldRevisionPage } from '~/stores/context';
-import { useSWRxCurrentPage } from '~/stores/page';
+import { useSWRxCurrentPage, useIsLatestRevision } from '~/stores/page';
 
 export const OldRevisionAlert = (): JSX.Element => {
 
   const { t } = useTranslation();
+  const { data: isLatestRevision } = useIsLatestRevision();
   const { data: page } = useSWRxCurrentPage();
-  const { data: isOldRevisionPage } = useIsOldRevisionPage();
 
-  if (page == null || !isOldRevisionPage) {
+  if (page == null || isLatestRevision == null || isLatestRevision) {
     return <></>;
   }
 

+ 3 - 4
apps/app/src/components/PageEditor/PageEditorReadOnly.tsx

@@ -5,9 +5,8 @@ import { useRect } from '@growi/ui/dist/utils';
 import { throttle } from 'throttle-debounce';
 
 import { useShouldExpandContent } from '~/client/services/layout';
-import { useIsOldRevisionPage } from '~/stores/context';
 import { useEditingMarkdown } from '~/stores/editor';
-import { useSWRxCurrentPage } from '~/stores/page';
+import { useSWRxCurrentPage, useIsLatestRevision } from '~/stores/page';
 import { usePreviewOptions } from '~/stores/renderer';
 
 import { EditorNavbar } from './EditorNavbar';
@@ -21,7 +20,7 @@ export const PageEditorReadOnly = react.memo((): JSX.Element => {
   const { data: currentPage } = useSWRxCurrentPage();
   const { data: rendererOptions } = usePreviewOptions();
   const { data: editingMarkdown } = useEditingMarkdown();
-  const { data: isOldRevisionPage } = useIsOldRevisionPage();
+  const { data: isLatestRevision } = useIsLatestRevision();
   const shouldExpandContent = useShouldExpandContent(currentPage);
 
   const { scrollEditorHandler, scrollPreviewHandler } = useScrollSync(GlobalCodeMirrorEditorKey.READONLY, previewRef);
@@ -39,7 +38,7 @@ export const PageEditorReadOnly = react.memo((): JSX.Element => {
     return { paddingBottom: `calc(${previewRectHeight}px - 2em)` };
   }, [previewRect]);
 
-  if (rendererOptions == null || !isOldRevisionPage) {
+  if (rendererOptions == null || isLatestRevision) {
     return <></>;
   }
 

+ 1 - 7
apps/app/src/pages/[[...path]].page.tsx

@@ -40,7 +40,7 @@ import {
   useCsrfToken, useIsSearchScopeChildrenAsDefault, useIsEnabledMarp, useCurrentPathname,
   useIsSlackConfigured, useRendererConfig, useGrowiCloudUri,
   useIsAllReplyShown, useIsContainerFluid, useIsNotCreatable,
-  useIsUploadAllFileAllowed, useIsUploadEnabled, useIsOldRevisionPage,
+  useIsUploadAllFileAllowed, useIsUploadEnabled,
 } from '~/stores/context';
 import { useEditingMarkdown } from '~/stores/editor';
 import {
@@ -175,8 +175,6 @@ type Props = CommonProps & {
   grantData?: IPageGrantData,
 
   rendererConfig: RendererConfig,
-
-  isOldRevisionPage: boolean,
 };
 
 const Page: NextPageWithLayout<Props> = (props: Props) => {
@@ -226,8 +224,6 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
   useIsUploadAllFileAllowed(props.isUploadAllFileAllowed);
   useIsUploadEnabled(props.isUploadEnabled);
 
-  useIsOldRevisionPage(props.isOldRevisionPage);
-
   const { pageWithMeta } = props;
 
   const pageId = pageWithMeta?.data._id;
@@ -415,8 +411,6 @@ async function injectPageData(context: GetServerSidePropsContext, props: Props):
   const { crowi } = req;
   const { revisionId } = req.query;
 
-  props.isOldRevisionPage = revisionId != null;
-
   const Page = crowi.model('Page') as PageModel;
   const PageRedirect = mongooseModel('PageRedirect') as PageRedirectModel;
   const { pageService, configManager, pageGrantService } = crowi;

+ 0 - 5
apps/app/src/stores/context.tsx

@@ -192,11 +192,6 @@ export const useIsContainerFluid = (initialData?: boolean): SWRResponse<boolean,
   return useStaticSWR('isContainerFluid', initialData);
 };
 
-export const useIsOldRevisionPage = (initialData?: boolean): SWRResponse<boolean, Error> => {
-  return useContextSWR('isOldRevisionPage', initialData);
-};
-
-
 /** **********************************************************
  *                     Computed contexts
  *********************************************************** */