|
@@ -43,12 +43,13 @@ import {
|
|
|
} from '~/stores/context';
|
|
} from '~/stores/context';
|
|
|
import { useEditingMarkdown } from '~/stores/editor';
|
|
import { useEditingMarkdown } from '~/stores/editor';
|
|
|
import {
|
|
import {
|
|
|
- useSWRxCurrentPage, useSWRMUTxCurrentPage, useCurrentPageId, useCurrentPageYjsDraft,
|
|
|
|
|
|
|
+ useSWRxCurrentPage, useSWRMUTxCurrentPage, useCurrentPageId,
|
|
|
useIsNotFound, useIsLatestRevision, useTemplateTagData, useTemplateBodyData,
|
|
useIsNotFound, useIsLatestRevision, useTemplateTagData, useTemplateBodyData,
|
|
|
} from '~/stores/page';
|
|
} from '~/stores/page';
|
|
|
import { useRedirectFrom } from '~/stores/page-redirect';
|
|
import { useRedirectFrom } from '~/stores/page-redirect';
|
|
|
import { useRemoteRevisionId } from '~/stores/remote-latest-page';
|
|
import { useRemoteRevisionId } from '~/stores/remote-latest-page';
|
|
|
import { useSetupGlobalSocket, useSetupGlobalSocketForPage } from '~/stores/websocket';
|
|
import { useSetupGlobalSocket, useSetupGlobalSocketForPage } from '~/stores/websocket';
|
|
|
|
|
+import { useCurrentPageYjsData, type CurrentPageYjsDataStates } from '~/stores/yjs';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
import { BasicLayout } from '../components/Layout/BasicLayout';
|
|
import { BasicLayout } from '../components/Layout/BasicLayout';
|
|
@@ -172,7 +173,7 @@ type Props = CommonProps & {
|
|
|
skipSSR: boolean,
|
|
skipSSR: boolean,
|
|
|
ssrMaxRevisionBodyLength: number,
|
|
ssrMaxRevisionBodyLength: number,
|
|
|
|
|
|
|
|
- hasYjsDraft: boolean,
|
|
|
|
|
|
|
+ yjsData: CurrentPageYjsDataStates,
|
|
|
|
|
|
|
|
rendererConfig: RendererConfig,
|
|
rendererConfig: RendererConfig,
|
|
|
};
|
|
};
|
|
@@ -224,8 +225,6 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
useIsUploadAllFileAllowed(props.isUploadAllFileAllowed);
|
|
useIsUploadAllFileAllowed(props.isUploadAllFileAllowed);
|
|
|
useIsUploadEnabled(props.isUploadEnabled);
|
|
useIsUploadEnabled(props.isUploadEnabled);
|
|
|
|
|
|
|
|
- useCurrentPageYjsDraft({ hasYjsDraft: props.hasYjsDraft });
|
|
|
|
|
-
|
|
|
|
|
const { pageWithMeta } = props;
|
|
const { pageWithMeta } = props;
|
|
|
|
|
|
|
|
const pageId = pageWithMeta?.data._id;
|
|
const pageId = pageWithMeta?.data._id;
|
|
@@ -248,6 +247,8 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
const { mutate: mutateTemplateTagData } = useTemplateTagData();
|
|
const { mutate: mutateTemplateTagData } = useTemplateTagData();
|
|
|
const { mutate: mutateTemplateBodyData } = useTemplateBodyData();
|
|
const { mutate: mutateTemplateBodyData } = useTemplateBodyData();
|
|
|
|
|
|
|
|
|
|
+ const { mutate: mutateCurrentPageYjsData } = useCurrentPageYjsData();
|
|
|
|
|
+
|
|
|
useSetupGlobalSocket();
|
|
useSetupGlobalSocket();
|
|
|
useSetupGlobalSocketForPage(pageId);
|
|
useSetupGlobalSocketForPage(pageId);
|
|
|
|
|
|
|
@@ -310,6 +311,10 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
mutateTemplateBodyData(props.templateBodyData);
|
|
mutateTemplateBodyData(props.templateBodyData);
|
|
|
}, [props.templateBodyData, mutateTemplateBodyData]);
|
|
}, [props.templateBodyData, mutateTemplateBodyData]);
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ mutateCurrentPageYjsData(props.yjsData);
|
|
|
|
|
+ }, [mutateCurrentPageYjsData, props.yjsData]);
|
|
|
|
|
+
|
|
|
// If the data on the page changes without router.push, pageWithMeta remains old because getServerSideProps() is not executed
|
|
// If the data on the page changes without router.push, pageWithMeta remains old because getServerSideProps() is not executed
|
|
|
// So preferentially take page data from useSWRxCurrentPage
|
|
// So preferentially take page data from useSWRxCurrentPage
|
|
|
const pagePath = currentPage?.path ?? pageWithMeta?.data.path ?? props.currentPathname;
|
|
const pagePath = currentPage?.path ?? pageWithMeta?.data.path ?? props.currentPathname;
|
|
@@ -490,7 +495,10 @@ async function injectRoutingInformation(context: GetServerSidePropsContext, prop
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- props.hasYjsDraft = crowi.pageService.hasYjsDraft(page._id);
|
|
|
|
|
|
|
+ props.yjsData = {
|
|
|
|
|
+ hasDraft: crowi.pageService.hasYjsDraft(page._id),
|
|
|
|
|
+ awarenessStateSize: crowi.pageService.getYjsAwarenessStateSize(page._id),
|
|
|
|
|
+ };
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|