|
|
@@ -26,6 +26,8 @@ import { DrawioViewerScript } from '~/components/Script/DrawioViewerScript';
|
|
|
import { SupportedAction, type SupportedActionType } from '~/interfaces/activity';
|
|
|
import type { CrowiRequest } from '~/interfaces/crowi-request';
|
|
|
import type { RendererConfig } from '~/interfaces/services/renderer';
|
|
|
+import type { ISidebarConfig } from '~/interfaces/sidebar-config';
|
|
|
+import type { CurrentPageYjsData } from '~/interfaces/yjs';
|
|
|
import type { PageModel, PageDocument } from '~/server/models/page';
|
|
|
import type { PageRedirectModel } from '~/server/models/page-redirect';
|
|
|
import {
|
|
|
@@ -42,12 +44,13 @@ import {
|
|
|
} from '~/stores/context';
|
|
|
import { useEditingMarkdown } from '~/stores/editor';
|
|
|
import {
|
|
|
- useSWRxCurrentPage, useSWRMUTxCurrentPage, useCurrentPageId, useCurrentPageYjsDraft,
|
|
|
+ useSWRxCurrentPage, useSWRMUTxCurrentPage, useCurrentPageId,
|
|
|
useIsNotFound, useIsLatestRevision, useTemplateTagData, useTemplateBodyData,
|
|
|
} from '~/stores/page';
|
|
|
import { useRedirectFrom } from '~/stores/page-redirect';
|
|
|
import { useRemoteRevisionId } from '~/stores/remote-latest-page';
|
|
|
import { useSetupGlobalSocket, useSetupGlobalSocketForPage } from '~/stores/websocket';
|
|
|
+import { useCurrentPageYjsData, useSWRMUTxCurrentPageYjsData } from '~/stores/yjs';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
import { BasicLayout } from '../components/Layout/BasicLayout';
|
|
|
@@ -148,6 +151,8 @@ type Props = CommonProps & {
|
|
|
isSearchScopeChildrenAsDefault: boolean,
|
|
|
isEnabledMarp: boolean,
|
|
|
|
|
|
+ sidebarConfig: ISidebarConfig,
|
|
|
+
|
|
|
isSlackConfigured: boolean,
|
|
|
// isMailerSetup: boolean,
|
|
|
isAclEnabled: boolean,
|
|
|
@@ -169,7 +174,7 @@ type Props = CommonProps & {
|
|
|
skipSSR: boolean,
|
|
|
ssrMaxRevisionBodyLength: number,
|
|
|
|
|
|
- yjsDraft?: string
|
|
|
+ yjsData: CurrentPageYjsData,
|
|
|
|
|
|
rendererConfig: RendererConfig,
|
|
|
};
|
|
|
@@ -221,8 +226,6 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
useIsUploadAllFileAllowed(props.isUploadAllFileAllowed);
|
|
|
useIsUploadEnabled(props.isUploadEnabled);
|
|
|
|
|
|
- useCurrentPageYjsDraft({ hasYjsDraft: props.yjsDraft != null });
|
|
|
-
|
|
|
const { pageWithMeta } = props;
|
|
|
|
|
|
const pageId = pageWithMeta?.data._id;
|
|
|
@@ -233,6 +236,8 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
const { data: currentPage } = useSWRxCurrentPage(pageWithMeta?.data ?? null); // store initial data
|
|
|
|
|
|
const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
|
|
|
+ const { trigger: mutateCurrentPageYjsDataFromApi } = useSWRMUTxCurrentPageYjsData();
|
|
|
+
|
|
|
const { mutate: mutateEditingMarkdown } = useEditingMarkdown();
|
|
|
const { data: currentPageId, mutate: mutateCurrentPageId } = useCurrentPageId();
|
|
|
|
|
|
@@ -245,6 +250,8 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
const { mutate: mutateTemplateTagData } = useTemplateTagData();
|
|
|
const { mutate: mutateTemplateBodyData } = useTemplateBodyData();
|
|
|
|
|
|
+ const { mutate: mutateCurrentPageYjsData } = useCurrentPageYjsData();
|
|
|
+
|
|
|
useSetupGlobalSocket();
|
|
|
useSetupGlobalSocketForPage(pageId);
|
|
|
|
|
|
@@ -257,14 +264,15 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
if (currentPageId != null && !props.isNotFound) {
|
|
|
const mutatePageData = async() => {
|
|
|
const pageData = await mutateCurrentPage();
|
|
|
- mutateEditingMarkdown(props.yjsDraft ?? pageData?.revision?.body);
|
|
|
+ mutateEditingMarkdown(pageData?.revision?.body);
|
|
|
+ mutateCurrentPageYjsDataFromApi();
|
|
|
};
|
|
|
|
|
|
// If skipSSR is true, use the API to retrieve page data.
|
|
|
// Because pageWIthMeta does not contain revision.body
|
|
|
mutatePageData();
|
|
|
}
|
|
|
- }, [currentPageId, mutateCurrentPage, mutateEditingMarkdown, props.isNotFound, props.skipSSR, props.yjsDraft]);
|
|
|
+ }, [currentPageId, mutateCurrentPage, mutateCurrentPageYjsDataFromApi, mutateEditingMarkdown, props.isNotFound, props.skipSSR]);
|
|
|
|
|
|
// sync pathname by Shallow Routing https://nextjs.org/docs/routing/shallow-routing
|
|
|
useEffect(() => {
|
|
|
@@ -277,11 +285,11 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
|
|
|
// initialize mutateEditingMarkdown only once per page
|
|
|
// need to include useCurrentPathname not useCurrentPagePath
|
|
|
- useEffect(() => {
|
|
|
- if (props.currentPathname != null) {
|
|
|
- mutateEditingMarkdown(props.yjsDraft ?? revisionBody);
|
|
|
- }
|
|
|
- }, [mutateEditingMarkdown, revisionBody, props.currentPathname, props.yjsDraft]);
|
|
|
+ // useEffect(() => {
|
|
|
+ // if (props.currentPathname != null) {
|
|
|
+ // mutateEditingMarkdown(props.yjsDraft ?? revisionBody);
|
|
|
+ // }
|
|
|
+ // }, [mutateEditingMarkdown, revisionBody, props.currentPathname, props.yjsDraft]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
mutateRemoteRevisionId(pageWithMeta?.data.revision?._id);
|
|
|
@@ -307,6 +315,10 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
mutateTemplateBodyData(props.templateBodyData);
|
|
|
}, [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
|
|
|
// So preferentially take page data from useSWRxCurrentPage
|
|
|
const pagePath = currentPage?.path ?? pageWithMeta?.data.path ?? props.currentPathname;
|
|
|
@@ -487,7 +499,9 @@ async function injectRoutingInformation(context: GetServerSidePropsContext, prop
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- props.yjsDraft = crowi.pageService.getYjsDraft(page._id);
|
|
|
+ if (!props.skipSSR) {
|
|
|
+ props.yjsData = await crowi.pageService.getYjsData(page._id);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -535,6 +549,11 @@ function injectServerConfigurations(context: GetServerSidePropsContext, props: P
|
|
|
|
|
|
props.isEnabledAttachTitleHeader = configManager.getConfig('crowi', 'customize:isEnabledAttachTitleHeader');
|
|
|
|
|
|
+ props.sidebarConfig = {
|
|
|
+ isSidebarCollapsedMode: configManager.getConfig('crowi', 'customize:isSidebarCollapsedMode'),
|
|
|
+ isSidebarClosedAtDockMode: configManager.getConfig('crowi', 'customize:isSidebarClosedAtDockMode'),
|
|
|
+ };
|
|
|
+
|
|
|
props.rendererConfig = {
|
|
|
isEnabledLinebreaks: configManager.getConfig('markdown', 'markdown:isEnabledLinebreaks'),
|
|
|
isEnabledLinebreaksInComments: configManager.getConfig('markdown', 'markdown:isEnabledLinebreaksInComments'),
|