|
|
@@ -1,4 +1,4 @@
|
|
|
-import { useEffect, useMemo } from 'react';
|
|
|
+import { useEffect, useMemo, useCallback } from 'react';
|
|
|
|
|
|
import type {
|
|
|
IPageInfoForEntity, IPagePopulatedToShowRevision, Nullable,
|
|
|
@@ -135,13 +135,34 @@ export const useSWRxPageInfo = (
|
|
|
return swrResult;
|
|
|
};
|
|
|
|
|
|
+const useSWRxPageRevision = (revisionId: Ref<IRevision>): SWRResponse<IRevisionHasId> => {
|
|
|
+ const key = `/revisions/${revisionId}`;
|
|
|
+
|
|
|
+ return useSWR(key, null, {
|
|
|
+ keepPreviousData: true,
|
|
|
+ });
|
|
|
+};
|
|
|
|
|
|
export const useSWRMUTxPageRevision = (pageId: string, revisionId: Ref<IRevision>): SWRMutationResponse<IRevisionHasId> => {
|
|
|
- const key = 'pageRevision';
|
|
|
+ const key = `/revisions/${revisionId}`;
|
|
|
+
|
|
|
+ const { data: pageRevisionData } = useSWRxPageRevision(revisionId);
|
|
|
+
|
|
|
+ const fetcher = useCallback(async() => {
|
|
|
+ if (pageRevisionData != null) {
|
|
|
+ return pageRevisionData;
|
|
|
+ }
|
|
|
+
|
|
|
+ const res = await apiv3Get<{ revision: IRevisionHasId }>(`/revisions/${revisionId}`, { pageId });
|
|
|
+ return res.data.revision;
|
|
|
+ }, [pageId, pageRevisionData, revisionId]);
|
|
|
|
|
|
return useSWRMutation(
|
|
|
key,
|
|
|
- () => apiv3Get<{ revision: IRevisionHasId }>(`/revisions/${revisionId}`, { pageId }).then(result => result.data.revision),
|
|
|
+ fetcher,
|
|
|
+ {
|
|
|
+ populateCache: true,
|
|
|
+ },
|
|
|
);
|
|
|
};
|
|
|
|