|
|
@@ -27,7 +27,7 @@ import type {
|
|
|
IResCurrentGrantData,
|
|
|
} from '~/interfaces/page-grant';
|
|
|
import { useIsGuestUser, useIsReadOnlyUser } from '~/states/context';
|
|
|
-import { usePageNotFound } from '~/states/page';
|
|
|
+import { useCurrentPageData, usePageNotFound } from '~/states/page';
|
|
|
import { useShareLinkId } from '~/states/page/hooks';
|
|
|
|
|
|
import type { IPageTagsInfo } from '../interfaces/tag';
|
|
|
@@ -154,6 +154,42 @@ export const useSWRMUTxPageInfo = (
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Hook to check if the current page is displaying the latest revision
|
|
|
+ * Returns SWRResponse with boolean value:
|
|
|
+ * - data: undefined - not yet determined (no currentPage data)
|
|
|
+ * - data: true - viewing the latest revision (or latestRevisionId not available)
|
|
|
+ * - data: false - viewing an old revision
|
|
|
+ */
|
|
|
+export const useIsLatestRevision = (): SWRResponse<boolean, Error> => {
|
|
|
+ const currentPage = useCurrentPageData();
|
|
|
+ const pageId = currentPage?._id;
|
|
|
+ const shareLinkId = useShareLinkId();
|
|
|
+ const { data: pageInfo } = useSWRxPageInfo(pageId, shareLinkId);
|
|
|
+
|
|
|
+ // Extract latestRevisionId if available (only exists in IPageInfoForEntity)
|
|
|
+ const latestRevisionId = pageInfo && 'latestRevisionId' in pageInfo ? pageInfo.latestRevisionId : undefined;
|
|
|
+
|
|
|
+ const key = useMemo(() => {
|
|
|
+ // Cannot determine without currentPage
|
|
|
+ if (currentPage?.revision?._id == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return ['isLatestRevision', currentPage.revision._id, latestRevisionId ?? null];
|
|
|
+ }, [currentPage?.revision?._id, latestRevisionId]);
|
|
|
+
|
|
|
+ return useSWRImmutable(
|
|
|
+ key,
|
|
|
+ ([, currentRevisionId, latestRevisionId]) => {
|
|
|
+ // If latestRevisionId is not available, assume it's the latest
|
|
|
+ if (latestRevisionId == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return latestRevisionId === currentRevisionId;
|
|
|
+ },
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
export const useSWRxPageRevision = (
|
|
|
pageId: string,
|
|
|
revisionId: Ref<IRevision>,
|