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

Use pageWithMeta directly & Renamed useCurrentMarkdown => useEditingMarkdown

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

+ 2 - 2
packages/app/src/components/PageAttachment.tsx

@@ -3,7 +3,7 @@ import React, { useCallback, useEffect, useState } from 'react';
 import { useTranslation } from 'next-i18next';
 
 import { useSWRxAttachments } from '~/stores/attachment';
-import { useCurrentMarkdown, useCurrentPageId, useIsGuestUser } from '~/stores/context';
+import { useEditingMarkdown, useCurrentPageId, useIsGuestUser } from '~/stores/context';
 
 import DeleteAttachmentModal from './PageAttachment/DeleteAttachmentModal';
 import PageAttachmentList from './PageAttachment/PageAttachmentList';
@@ -16,7 +16,7 @@ const checkIfFileInUse = (markdown: string, attachment) => {
 
 // Custom hook that handles processes related to inUseAttachments
 const useInUseAttachments = (attachments) => {
-  const { data: markdown } = useCurrentMarkdown();
+  const { data: markdown } = useEditingMarkdown();
   const [inUse, setInUse] = useState<any>({});
 
   // Update inUse when either of attachments or markdown is updated

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

@@ -55,7 +55,7 @@ import {
   useHackmdUri,
   useIsAclEnabled, useIsUserPage, useIsNotCreatable,
   useCsrfToken, useIsSearchScopeChildrenAsDefault, useCurrentPageId, useCurrentPathname,
-  useIsSlackConfigured, useIsBlinkedHeaderAtBoot, useRendererConfig, useCurrentMarkdown,
+  useIsSlackConfigured, useIsBlinkedHeaderAtBoot, useRendererConfig, useEditingMarkdown,
 } from '../stores/context';
 import { useXss } from '../stores/xss';
 
@@ -130,8 +130,6 @@ type Props = CommonProps & {
   userUISettings: UserUISettingsDocument | null
   // Sidebar
   sidebarConfig: ISidebarConfig,
-  // Markdown
-  markdown: string,
 };
 
 const GrowiPage: NextPage<Props> = (props: Props) => {
@@ -175,7 +173,6 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
   // useIsAbleToDeleteCompletely(props.isAbleToDeleteCompletely);
   useIsEnabledStaleNotification(props.isEnabledStaleNotification);
   useIsBlinkedHeaderAtBoot(false);
-  useCurrentMarkdown(props.markdown);
 
   useIsSearchServiceConfigured(props.isSearchServiceConfigured);
   useIsSearchServiceReachable(props.isSearchServiceReachable);
@@ -218,6 +215,7 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
   useIsNotCreatable(props.isForbidden || !isCreatablePage(pageWithMeta?.data.path ?? '')); // TODO: need to include props.isIdentical
   useCurrentPagePath(pageWithMeta?.data.path);
   useCurrentPathname(props.currentPathname);
+  useEditingMarkdown(pageWithMeta?.data.revision.body);
 
   // sync pathname by Shallow Routing https://nextjs.org/docs/routing/shallow-routing
   useEffect(() => {
@@ -519,9 +517,6 @@ 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,
   };

+ 1 - 1
packages/app/src/stores/context.tsx

@@ -232,7 +232,7 @@ export const useIsBlinkedHeaderAtBoot = (initialData?: boolean): SWRResponse<boo
   return useStaticSWR('isBlinkedAtBoot', initialData);
 };
 
-export const useCurrentMarkdown = (initialData?: string): SWRResponse<string, Error> => {
+export const useEditingMarkdown = (initialData?: string): SWRResponse<string, Error> => {
   return useStaticSWR('currentMarkdown', initialData);
 };