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

refactor: remove unused getActivityAction function and integrate activity action handling in server-side props

Shun Miyazawa 3 месяцев назад
Родитель
Сommit
a4874ae83f

+ 0 - 37
apps/app/src/pages/general-page/get-activity-action.ts

@@ -1,37 +0,0 @@
-import type {
-  IDataWithMeta,
-  IPageNotFoundInfo,
-} from '@growi/core/dist/interfaces';
-import { pagePathUtils } from '@growi/core/dist/utils';
-
-import type { SupportedActionType } from '~/interfaces/activity';
-import { SupportedAction } from '~/interfaces/activity';
-
-import type { IPageToShowRevisionWithMeta } from './types';
-
-export const getActivityAction = (props: {
-  isNotCreatable: boolean;
-  isForbidden: boolean;
-  isNotFound: boolean;
-  pageWithMeta?:
-    | IPageToShowRevisionWithMeta
-    | IDataWithMeta<null, IPageNotFoundInfo>
-    | null;
-}): SupportedActionType => {
-  if (props.isNotCreatable) {
-    return SupportedAction.ACTION_PAGE_NOT_CREATABLE;
-  }
-  if (props.isForbidden) {
-    return SupportedAction.ACTION_PAGE_FORBIDDEN;
-  }
-  if (props.isNotFound) {
-    return SupportedAction.ACTION_PAGE_NOT_FOUND;
-  }
-
-  // Type-safe access to page data - only access path if data is not null
-  const pagePath = props.pageWithMeta?.data?.path ?? '';
-  if (pagePathUtils.isUsersHomepage(pagePath)) {
-    return SupportedAction.ACTION_PAGE_USER_HOME_VIEW;
-  }
-  return SupportedAction.ACTION_PAGE_VIEW;
-};

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

@@ -2,7 +2,6 @@ export {
   getServerSideGeneralPageProps,
   getServerSideRendererConfigProps,
 } from './configuration-props';
-export { getActivityAction } from './get-activity-action';
 export { isValidGeneralPageInitialProps } from './type-guards';
 export type * from './types';
 export { useInitialCSRFetch } from './use-initial-skip-ssr-fetch';

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

@@ -1,11 +1,16 @@
 import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
 
+import {
+  SupportedAction,
+  type SupportedActionType,
+} from '~/interfaces/activity';
+import type { IShareLinkHasId } from '~/interfaces/share-link';
+
 import {
   getServerSideCommonInitialProps,
   getServerSideI18nProps,
 } from '../../common-props';
 import {
-  getActivityAction,
   getServerSideGeneralPageProps,
   getServerSideRendererConfigProps,
   isValidGeneralPageInitialProps,
@@ -23,6 +28,21 @@ const basisProps = {
   },
 };
 
+function getActivityAction(props: {
+  isExpired: boolean | undefined;
+  shareLink: IShareLinkHasId | undefined;
+}): SupportedActionType {
+  if (props.isExpired) {
+    return SupportedAction.ACTION_SHARE_LINK_EXPIRED_PAGE_VIEW;
+  }
+
+  if (props.shareLink == null) {
+    return SupportedAction.ACTION_SHARE_LINK_NOT_FOUND;
+  }
+
+  return SupportedAction.ACTION_SHARE_LINK_PAGE_VIEW;
+}
+
 export async function getServerSidePropsForInitial(
   context: GetServerSidePropsContext,
 ): Promise<GetServerSidePropsResult<Stage2InitialProps>> {
@@ -67,6 +87,8 @@ export async function getServerSidePropsForInitial(
     throw new Error('Invalid merged props structure');
   }
 
-  await addActivity(context, getActivityAction(mergedProps));
+  // Persist activity
+  addActivity(context, getActivityAction(mergedProps));
+
   return mergedResult;
 }