Просмотр исходного кода

Impl & setup useCurrentMarkdown

Taichi Masuyama 3 лет назад
Родитель
Сommit
578652224f

+ 1 - 0
packages/app/src/client/services/PageContainer.js

@@ -135,6 +135,7 @@ export default class PageContainer extends Container {
 
   /**
    * initialize state for markdown data
+   * [Already SWRized]
    */
   initStateMarkdown() {
     let pageContent = '';

+ 7 - 1
packages/app/src/pages/[[...path]].page.tsx

@@ -55,7 +55,7 @@ import {
   useHackmdUri,
   useIsAclEnabled, useIsUserPage, useIsNotCreatable,
   useCsrfToken, useIsSearchScopeChildrenAsDefault, useCurrentPageId, useCurrentPathname,
-  useIsSlackConfigured, useIsBlinkedHeaderAtBoot, useRendererConfig,
+  useIsSlackConfigured, useIsBlinkedHeaderAtBoot, useRendererConfig, useCurrentMarkdown,
 } from '../stores/context';
 import { useXss } from '../stores/xss';
 
@@ -130,6 +130,8 @@ type Props = CommonProps & {
   userUISettings: UserUISettingsDocument | null
   // Sidebar
   sidebarConfig: ISidebarConfig,
+  // Markdown
+  markdown: string,
 };
 
 const GrowiPage: NextPage<Props> = (props: Props) => {
@@ -173,6 +175,7 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
   // useIsAbleToDeleteCompletely(props.isAbleToDeleteCompletely);
   useIsEnabledStaleNotification(props.isEnabledStaleNotification);
   useIsBlinkedHeaderAtBoot(false);
+  useCurrentMarkdown(props.markdown);
 
   useIsSearchServiceConfigured(props.isSearchServiceConfigured);
   useIsSearchServiceReachable(props.isSearchServiceReachable);
@@ -516,6 +519,9 @@ export const getServerSideProps: GetServerSideProps = async(context: GetServerSi
   const userUISettings = user == null ? null : await UserUISettings.findOne({ user: user._id }).exec();
   props.userUISettings = JSON.parse(JSON.stringify(userUISettings));
 
+  // Markdown
+  props.markdown = pageWithMeta.revision.body;
+
   return {
     props,
   };

+ 4 - 0
packages/app/src/stores/context.tsx

@@ -232,6 +232,10 @@ export const useIsBlinkedHeaderAtBoot = (initialData?: boolean): SWRResponse<boo
   return useStaticSWR('isBlinkedAtBoot', initialData);
 };
 
+export const useCurrentMarkdown = (initialData?: string): SWRResponse<string, Error> => {
+  return useStaticSWR('currentMarkdown', initialData);
+};
+
 
 /** **********************************************************
  *                     Computed contexts