yuken 3 лет назад
Родитель
Сommit
e3d2dd4cd0

+ 6 - 4
packages/app/src/components/PageAlert/TrashPageAlert.tsx

@@ -1,10 +1,11 @@
 import React from 'react';
 import React from 'react';
 
 
 import { UserPicture } from '@growi/ui';
 import { UserPicture } from '@growi/ui';
+import { format } from 'date-fns';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 
 
 import {
 import {
-  useCurrentUpdatedAt, useIsTrashPage, useShareLinkId, useLastUpdateUsername, useDeletedAt, useRevisionId,
+  useCurrentUpdatedAt, useIsTrashPage, useShareLinkId,
 } from '~/stores/context';
 } from '~/stores/context';
 import { usePageDeleteModal, usePutBackPageModal } from '~/stores/modal';
 import { usePageDeleteModal, usePutBackPageModal } from '~/stores/modal';
 import { useSWRxPageInfo, useSWRxCurrentPage } from '~/stores/page';
 import { useSWRxPageInfo, useSWRxCurrentPage } from '~/stores/page';
@@ -25,9 +26,6 @@ export const TrashPageAlert = (): JSX.Element => {
   const { data: shareLinkId } = useShareLinkId();
   const { data: shareLinkId } = useShareLinkId();
   const { data: pageData } = useSWRxCurrentPage();
   const { data: pageData } = useSWRxCurrentPage();
   const { data: isTrashPage } = useIsTrashPage();
   const { data: isTrashPage } = useIsTrashPage();
-  const { data: lastUpdateUserName } = useLastUpdateUsername();
-  const { data: deletedAt } = useDeletedAt();
-  const { data: revisionId } = useRevisionId();
   const pageId = pageData?._id;
   const pageId = pageData?._id;
   const pagePath = pageData?.path;
   const pagePath = pageData?.path;
   const { data: pageInfo } = useSWRxPageInfo(pageId ?? null, shareLinkId);
   const { data: pageInfo } = useSWRxPageInfo(pageId ?? null, shareLinkId);
@@ -37,6 +35,10 @@ export const TrashPageAlert = (): JSX.Element => {
   const { open: openDeleteModal } = usePageDeleteModal();
   const { open: openDeleteModal } = usePageDeleteModal();
   const { open: openPutBackPageModal } = usePutBackPageModal();
   const { open: openPutBackPageModal } = usePutBackPageModal();
 
 
+  const lastUpdateUserName = pageData?.lastUpdateUser.name;
+  const deletedAt = pageData?.deletedAt ? format(new Date(pageData?.deletedAt), 'yyyy/MM/dd HH:mm') : '';
+  const revisionId = pageData?.revision._id;
+
   if (!isTrashPage) {
   if (!isTrashPage) {
     return <></>;
     return <></>;
   }
   }

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

@@ -1,7 +1,6 @@
 import React, { useEffect } from 'react';
 import React, { useEffect } from 'react';
 
 
 import { pagePathUtils } from '@growi/core';
 import { pagePathUtils } from '@growi/core';
-import { format } from 'date-fns';
 import { isValidObjectId } from 'mongoose';
 import { isValidObjectId } from 'mongoose';
 import {
 import {
   NextPage, GetServerSideProps, GetServerSidePropsContext,
   NextPage, GetServerSideProps, GetServerSidePropsContext,
@@ -42,7 +41,7 @@ import {
   useAppTitle, useSiteUrl, useConfidential, useIsEnabledStaleNotification,
   useAppTitle, useSiteUrl, useConfidential, useIsEnabledStaleNotification,
   useIsSearchServiceConfigured, useIsSearchServiceReachable, useIsMailerSetup,
   useIsSearchServiceConfigured, useIsSearchServiceReachable, useIsMailerSetup,
   useAclEnabled, useHasSlackConfig, useDrawioUri, useHackmdUri, useMathJax, useNoCdn, useEditorConfig, useCsrfToken,
   useAclEnabled, useHasSlackConfig, useDrawioUri, useHackmdUri, useMathJax, useNoCdn, useEditorConfig, useCsrfToken,
-  useCurrentPageId, useLastUpdateUsername, useDeletedAt, useRevisionId,
+  useCurrentPageId,
 } from '../stores/context';
 } from '../stores/context';
 import { useXss } from '../stores/xss';
 import { useXss } from '../stores/xss';
 
 
@@ -59,10 +58,6 @@ type Props = CommonProps & {
   currentUser: string,
   currentUser: string,
 
 
   pageWithMetaStr: string,
   pageWithMetaStr: string,
-  lastUpdateUserName: string,
-  deletedAt: string,
-  revisionId: string,
-  currentPagePath: string,
   // pageUser?: any,
   // pageUser?: any,
   // redirectTo?: string;
   // redirectTo?: string;
   // redirectFrom?: string;
   // redirectFrom?: string;
@@ -115,9 +110,6 @@ const GrowiPage: NextPage<Props> = (props: Props) => {
   // useShareLinkId(props.shareLinkId);
   // useShareLinkId(props.shareLinkId);
   // useIsAbleToDeleteCompletely(props.isAbleToDeleteCompletely);
   // useIsAbleToDeleteCompletely(props.isAbleToDeleteCompletely);
   // useIsSharedUser(props.currentUser == null && isSharedPage(props.currentPagePath));
   // useIsSharedUser(props.currentUser == null && isSharedPage(props.currentPagePath));
-  useLastUpdateUsername(props.lastUpdateUserName);
-  useDeletedAt(props.deletedAt);
-  useRevisionId(props.revisionId);
   useIsEnabledStaleNotification(props.isEnabledStaleNotification);
   useIsEnabledStaleNotification(props.isEnabledStaleNotification);
 
 
   useIsSearchServiceConfigured(props.isSearchServiceConfigured);
   useIsSearchServiceConfigured(props.isSearchServiceConfigured);
@@ -257,12 +249,8 @@ async function injectPageInformation(context: GetServerSidePropsContext, props:
     logger.warn(`Page is ${props.isForbidden ? 'forbidden' : 'not found'}`, currentPathname);
     logger.warn(`Page is ${props.isForbidden ? 'forbidden' : 'not found'}`, currentPathname);
   }
   }
 
 
+  await (page as unknown as PageModel).populateDataToShowRevision();
   props.pageWithMetaStr = JSON.stringify(result);
   props.pageWithMetaStr = JSON.stringify(result);
-
-  const populatedPage = await (page as unknown as PageModel).populateDataToShowRevision();
-  props.lastUpdateUserName = populatedPage.lastUpdateUser.name;
-  props.deletedAt = page.deletedAt ? format(page.deletedAt, 'yyyy/MM/dd HH:mm') : '';
-  props.revisionId = populatedPage.revision._id.toString();
 }
 }
 
 
 // async function injectPageUserInformation(context: GetServerSidePropsContext, props: Props): Promise<void> {
 // async function injectPageUserInformation(context: GetServerSidePropsContext, props: Props): Promise<void> {