Yuki Takei 7 месяцев назад
Родитель
Сommit
457cb6fdb2

+ 5 - 5
apps/app/src/pages/[[...path]]/index.page.tsx

@@ -32,9 +32,9 @@ import { useHydrateSidebarAtoms } from '~/states/ui/sidebar/hydrate';
 import { useSWRMUTxCurrentPageYjsData } from '~/stores/yjs';
 
 import type { NextPageWithLayout } from '../_app.page';
-import type { CommonEachProps, UserUISettingsProps } from '../common-props';
+import type { UserUISettingsProps } from '../common-props';
 import type { InitialProps, SidebarConfigProps } from '../general-page';
-import { useInitialCSRFetch, useSameRouteNavigation } from '../general-page';
+import { useInitialCSRFetch } from '../general-page';
 import { registerPageToShowRevisionWithMeta } from '../general-page/superjson';
 import { NextjsRoutingType, detectNextjsRoutingType } from '../utils/nextjs-routing-utils';
 import { useCustomTitleForPage } from '../utils/page-title-customization';
@@ -42,6 +42,7 @@ import { useCustomTitleForPage } from '../utils/page-title-customization';
 import { NEXT_JS_ROUTING_PAGE } from './consts';
 import { getServerSidePropsForInitial, getServerSidePropsForSameRoute } from './server-side-props';
 import type { EachProps } from './types';
+import { useSameRouteNavigation } from './use-same-route-navigation';
 import { useShallowRouting } from './use-shallow-routing';
 
 // call superjson custom register
@@ -74,10 +75,9 @@ const ConflictDiffModal = dynamic(() => import('~/client/components/PageEditor/C
 const EditablePageEffects = dynamic(() => import('~/client/components/Page/EditablePageEffects').then(mod => mod.EditablePageEffects), { ssr: false });
 
 
-type SameRouteEachProps = CommonEachProps & EachProps;
-type Props = SameRouteEachProps | (SameRouteEachProps & InitialProps & UserUISettingsProps & SidebarConfigProps);
+type Props = EachProps | (EachProps & InitialProps & UserUISettingsProps & SidebarConfigProps);
 
-const isInitialProps = (props: Props): props is (UserUISettingsProps & SidebarConfigProps & InitialProps & SameRouteEachProps) => {
+const isInitialProps = (props: Props): props is (UserUISettingsProps & SidebarConfigProps & InitialProps & EachProps) => {
   return 'isNextjsRoutingTypeInitial' in props && props.isNextjsRoutingTypeInitial;
 };
 

+ 2 - 3
apps/app/src/pages/[[...path]]/page-data-props.ts

@@ -60,8 +60,7 @@ export async function getPageDataForInitial(
     context: GetServerSidePropsContext,
 ): Promise<GetServerSidePropsResult<
   Pick<InitialProps, 'pageWithMeta' | 'isNotFound' | 'isNotCreatable' | 'isForbidden' | 'skipSSR'> &
-  Pick<CommonEachProps, 'currentPathname'> &
-  EachProps
+  Pick<EachProps, 'currentPathname' | 'isIdenticalPathPage' | 'redirectFrom'>
 >> {
   const req: CrowiRequest = context.req as CrowiRequest;
   const { crowi, user } = req;
@@ -167,7 +166,7 @@ export async function getPageDataForSameRoute(
     context: GetServerSidePropsContext,
 ): Promise<GetServerSidePropsResult<
     Pick<CommonEachProps, 'currentPathname'> &
-    EachProps
+    Pick<EachProps, 'currentPathname' | 'isIdenticalPathPage' | 'redirectFrom'>
 >> {
   const req: CrowiRequest = context.req as CrowiRequest;
   const { user } = req;

+ 3 - 1
apps/app/src/pages/[[...path]]/types.ts

@@ -1,4 +1,6 @@
-export type EachProps = {
+import type { CommonEachProps } from '../common-props';
+
+export type EachProps = CommonEachProps & {
   redirectFrom?: string;
 
   isIdenticalPathPage: boolean,

+ 0 - 0
apps/app/src/pages/general-page/use-same-route-navigation.spec.tsx → apps/app/src/pages/[[...path]]/use-same-route-navigation.spec.tsx


+ 0 - 0
apps/app/src/pages/general-page/use-same-route-navigation.ts → apps/app/src/pages/[[...path]]/use-same-route-navigation.ts


+ 0 - 1
apps/app/src/pages/general-page/index.ts

@@ -3,4 +3,3 @@ export { getActivityAction } from './get-activity-action';
 export type * from './types';
 export { isValidInitialAndSameRouteProps } from './type-guards';
 export { useInitialCSRFetch } from './use-initial-skip-ssr-fetch';
-export { useSameRouteNavigation } from './use-same-route-navigation';

+ 22 - 25
apps/app/src/pages/share/[[...path]]/index.page.tsx

@@ -10,8 +10,6 @@ import Head from 'next/head';
 import { ShareLinkLayout } from '~/components/Layout/ShareLinkLayout';
 import { DrawioViewerScript } from '~/components/Script/DrawioViewerScript';
 import { ShareLinkPageView } from '~/components/ShareLinkPageView';
-import type { SupportedActionType } from '~/interfaces/activity';
-import { SupportedAction } from '~/interfaces/activity';
 import type { CommonEachProps } from '~/pages/common-props';
 import { NextjsRoutingType, detectNextjsRoutingType } from '~/pages/utils/nextjs-routing-utils';
 import { useCustomTitleForPage } from '~/pages/utils/page-title-customization';
@@ -31,7 +29,7 @@ import { registerPageToShowRevisionWithMeta } from '../../general-page/superjson
 
 import { NEXT_JS_ROUTING_PAGE } from './consts';
 import { getServerSidePropsForInitial, getServerSidePropsForSameRoute } from './server-side-props';
-import type { ShareLinkPageProps } from './types';
+import type { ShareLinkInitialProps } from './types';
 
 // call superjson custom register
 registerPageToShowRevisionWithMeta();
@@ -42,21 +40,20 @@ const GrowiContextualSubNavigation = dynamic(() => import('~/client/components/N
 
 const logger = loggerFactory('growi:next-page:share');
 
-type Props = ShareLinkPageProps &
-  (CommonEachProps | (CommonEachProps & InitialProps));
+type Props = CommonEachProps | (CommonEachProps & InitialProps & ShareLinkInitialProps);
 
-const isInitialProps = (props: Props): props is (ShareLinkPageProps & InitialProps & CommonEachProps) => {
+const isInitialProps = (props: Props): props is (ShareLinkInitialProps & InitialProps & CommonEachProps) => {
   return 'isNextjsRoutingTypeInitial' in props && props.isNextjsRoutingTypeInitial;
 };
 
 const SharedPage: NextPageWithLayout<Props> = (props: Props) => {
 
-  const { shareLink, isExpired } = props;
-
   // Initialize Jotai atoms with initial data - must be called unconditionally
+  const shareLink = isInitialProps(props) ? props.shareLink : undefined;
+  const isExpired = isInitialProps(props) ? props.isExpired : undefined;
   const pageData = isInitialProps(props) ? props.pageWithMeta?.data : undefined;
   useHydratePageAtoms(pageData, {
-    shareLinkId: props.shareLink?._id,
+    shareLinkId: shareLink?._id,
   });
 
   const [currentPage] = useCurrentPageData();
@@ -130,22 +127,22 @@ SharedPage.getLayout = function getLayout(page) {
   );
 };
 
-function getAction(props: Props): SupportedActionType {
-  let action: SupportedActionType;
-  if (props.isExpired) {
-    action = SupportedAction.ACTION_SHARE_LINK_EXPIRED_PAGE_VIEW;
-  }
-  else if (props.shareLink == null) {
-    action = SupportedAction.ACTION_SHARE_LINK_NOT_FOUND;
-  }
-  else {
-    action = SupportedAction.ACTION_SHARE_LINK_PAGE_VIEW;
-  }
-
-  return action;
-}
-
-export const getServerSideProps: GetServerSideProps<ShareLinkPageProps> = async(context: GetServerSidePropsContext) => {
+// function getAction(props: Props): SupportedActionType {
+//   let action: SupportedActionType;
+//   if (props.isExpired) {
+//     action = SupportedAction.ACTION_SHARE_LINK_EXPIRED_PAGE_VIEW;
+//   }
+//   else if (props.shareLink == null) {
+//     action = SupportedAction.ACTION_SHARE_LINK_NOT_FOUND;
+//   }
+//   else {
+//     action = SupportedAction.ACTION_SHARE_LINK_PAGE_VIEW;
+//   }
+
+//   return action;
+// }
+
+export const getServerSideProps: GetServerSideProps<Props> = async(context: GetServerSidePropsContext) => {
   // detect Next.js routing type
   const nextjsRoutingType = detectNextjsRoutingType(context, NEXT_JS_ROUTING_PAGE);
 

+ 5 - 9
apps/app/src/pages/share/[[...path]]/server-side-props.ts

@@ -1,5 +1,6 @@
 import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
 
+import type { CommonEachProps } from '../../common-props';
 import {
   getServerSideI18nProps, getServerSideCommonInitialProps, getServerSideCommonEachProps,
 } from '../../common-props';
@@ -13,7 +14,7 @@ import { mergeGetServerSidePropsResults } from '../../utils/server-side-props';
 
 import { NEXT_JS_ROUTING_PAGE } from './consts';
 import { getPageDataForInitial } from './page-data-props';
-import type { ShareLinkPageProps } from './types';
+import type { ShareLinkInitialProps } from './types';
 
 
 const nextjsRoutingProps = {
@@ -31,7 +32,7 @@ const basisProps = {
 };
 
 export async function getServerSidePropsForInitial(context: GetServerSidePropsContext):
-    Promise<GetServerSidePropsResult<InitialProps & ShareLinkPageProps>> {
+    Promise<GetServerSidePropsResult<InitialProps & ShareLinkInitialProps & CommonEachProps>> {
 
   //
   // STAGE 1
@@ -97,7 +98,7 @@ export async function getServerSidePropsForInitial(context: GetServerSidePropsCo
   return mergedResult;
 }
 
-export async function getServerSidePropsForSameRoute(context: GetServerSidePropsContext): Promise<GetServerSidePropsResult<SameRouteEachProps>> {
+export async function getServerSidePropsForSameRoute(context: GetServerSidePropsContext): Promise<GetServerSidePropsResult<CommonEachProps>> {
   //
   // STAGE 1
   //
@@ -124,12 +125,7 @@ export async function getServerSidePropsForSameRoute(context: GetServerSideProps
   //
 
   // Merge results in a type-safe manner
-  const mergedResult = mergeGetServerSidePropsResults(commonEachPropsResult,
-    mergeGetServerSidePropsResults({
-      props: {
-        isIdenticalPathPage: false,
-      },
-    }, nextjsRoutingProps));
+  const mergedResult = mergeGetServerSidePropsResults(commonEachPropsResult, nextjsRoutingProps);
 
   // -- TODO: persist activity
 

+ 1 - 1
apps/app/src/pages/share/[[...path]]/types.ts

@@ -1,6 +1,6 @@
 import type { IShareLinkHasId } from '~/interfaces/share-link';
 
-export type ShareLinkPageProps = {
+export type ShareLinkInitialProps = {
   isNotFound: true,
   isExpired: undefined
   shareLink: undefined,