Jelajahi Sumber

fix: update DisplaySwitcher and OldRevisionAlert to use useRevisionIdFromUrl

Shun Miyazawa 4 bulan lalu
induk
melakukan
0cf2177a43

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

@@ -3,9 +3,8 @@ import type { JSX } from 'react';
 import dynamic from 'next/dynamic';
 import dynamic from 'next/dynamic';
 
 
 import { useHashChangedEffect } from '~/client/services/side-effects/hash-changed';
 import { useHashChangedEffect } from '~/client/services/side-effects/hash-changed';
-import { useIsEditable } from '~/states/page';
+import { useIsEditable, useRevisionIdFromUrl } from '~/states/page';
 import { EditorMode, useEditorMode, useReservedNextCaretLine } from '~/states/ui/editor';
 import { EditorMode, useEditorMode, useReservedNextCaretLine } from '~/states/ui/editor';
-import { useSWRxIsLatestRevision } from '~/stores/page';
 
 
 import { LazyRenderer } from '../Common/LazyRenderer';
 import { LazyRenderer } from '../Common/LazyRenderer';
 
 
@@ -18,14 +17,16 @@ export const DisplaySwitcher = (): JSX.Element => {
 
 
   const { editorMode } = useEditorMode();
   const { editorMode } = useEditorMode();
   const isEditable = useIsEditable();
   const isEditable = useIsEditable();
-  const { data: isLatestRevision } = useSWRxIsLatestRevision();
+
+  const revisionIdFromUrl = useRevisionIdFromUrl();
 
 
   useHashChangedEffect();
   useHashChangedEffect();
   useReservedNextCaretLine();
   useReservedNextCaretLine();
 
 
   return (
   return (
     <LazyRenderer shouldRender={isEditable === true && editorMode === EditorMode.Editor}>
     <LazyRenderer shouldRender={isEditable === true && editorMode === EditorMode.Editor}>
-      { isLatestRevision !== false
+      {/* Display <PageEditorReadOnly /> when the user is intentionally viewing a specific (past) revision. */}
+      { revisionIdFromUrl == null
         ? <PageEditor />
         ? <PageEditor />
         : <PageEditorReadOnly />
         : <PageEditorReadOnly />
       }
       }

+ 4 - 5
apps/app/src/components/PageView/PageAlerts/OldRevisionAlert.tsx

@@ -3,14 +3,13 @@ import { useRouter } from 'next/router';
 import { returnPathForURL } from '@growi/core/dist/utils/path-utils';
 import { returnPathForURL } from '@growi/core/dist/utils/path-utils';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 
 
-import { useCurrentPageData, useFetchCurrentPage } from '~/states/page';
-import { useSWRxIsLatestRevision } from '~/stores/page';
+import { useCurrentPageData, useFetchCurrentPage, useRevisionIdFromUrl } from '~/states/page';
 
 
 export const OldRevisionAlert = (): JSX.Element => {
 export const OldRevisionAlert = (): JSX.Element => {
   const router = useRouter();
   const router = useRouter();
   const { t } = useTranslation();
   const { t } = useTranslation();
 
 
-  const { data: isLatestRevision } = useSWRxIsLatestRevision();
+  const revisionIdFromUrl = useRevisionIdFromUrl();
   const page = useCurrentPageData();
   const page = useCurrentPageData();
   const { fetchCurrentPage } = useFetchCurrentPage();
   const { fetchCurrentPage } = useFetchCurrentPage();
 
 
@@ -24,8 +23,8 @@ export const OldRevisionAlert = (): JSX.Element => {
     fetchCurrentPage({ force: true });
     fetchCurrentPage({ force: true });
   }, [fetchCurrentPage, page, router]);
   }, [fetchCurrentPage, page, router]);
 
 
-  // Show alert only when viewing an old revision (isLatestRevision === false)
-  if (isLatestRevision !== false) {
+  // Show alert only when intentionally viewing a specific (past) revision (revisionIdFromUrl != null)
+  if (revisionIdFromUrl == null) {
     // biome-ignore lint/complexity/noUselessFragments: ignore
     // biome-ignore lint/complexity/noUselessFragments: ignore
     return <></>;
     return <></>;
   }
   }