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

move hooks to a separated file

WNomunomu 2 лет назад
Родитель
Сommit
422e98a346

+ 3 - 76
apps/app/src/components/InAppNotification/PageNotification/PageModelNotification.tsx

@@ -6,97 +6,24 @@ import type { HasObjectId } from '@growi/core';
 import { useRouter } from 'next/router';
 
 import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
-import { SupportedAction } from '~/interfaces/activity';
 import type { IInAppNotification } from '~/interfaces/in-app-notification';
 
 import { ModelNotification } from './ModelNotification';
+import { useActionMsgAndIconForPageModelNotification } from './useActionAndMsg';
+
 
 interface Props {
   notification: IInAppNotification & HasObjectId
   actionUsers: string
 }
 
-export type ActionMsgAndIconType = {
-  actionMsg: string
-  actionIcon: string
-}
-
-const useActionMsgAndIcon = (notification: IInAppNotification & HasObjectId): ActionMsgAndIconType => {
-  const actionType: string = notification.action;
-  let actionMsg: string;
-  let actionIcon: string;
-
-  switch (actionType) {
-    case SupportedAction.ACTION_PAGE_LIKE:
-      actionMsg = 'liked';
-      actionIcon = 'icon-like';
-      break;
-    case SupportedAction.ACTION_PAGE_BOOKMARK:
-      actionMsg = 'bookmarked on';
-      actionIcon = 'icon-star';
-      break;
-    case SupportedAction.ACTION_PAGE_UPDATE:
-      actionMsg = 'updated on';
-      actionIcon = 'ti ti-agenda';
-      break;
-    case SupportedAction.ACTION_PAGE_RENAME:
-      actionMsg = 'renamed';
-      actionIcon = 'icon-action-redo';
-      break;
-    case SupportedAction.ACTION_PAGE_DUPLICATE:
-      actionMsg = 'duplicated';
-      actionIcon = 'icon-docs';
-      break;
-    case SupportedAction.ACTION_PAGE_DELETE:
-      actionMsg = 'deleted';
-      actionIcon = 'icon-trash';
-      break;
-    case SupportedAction.ACTION_PAGE_DELETE_COMPLETELY:
-      actionMsg = 'completely deleted';
-      actionIcon = 'icon-fire';
-      break;
-    case SupportedAction.ACTION_PAGE_REVERT:
-      actionMsg = 'reverted';
-      actionIcon = 'icon-action-undo';
-      break;
-    case SupportedAction.ACTION_PAGE_RECURSIVELY_RENAME:
-      actionMsg = 'renamed under';
-      actionIcon = 'icon-action-redo';
-      break;
-    case SupportedAction.ACTION_PAGE_RECURSIVELY_DELETE:
-      actionMsg = 'deleted under';
-      actionIcon = 'icon-trash';
-      break;
-    case SupportedAction.ACTION_PAGE_RECURSIVELY_DELETE_COMPLETELY:
-      actionMsg = 'deleted completely under';
-      actionIcon = 'icon-fire';
-      break;
-    case SupportedAction.ACTION_PAGE_RECURSIVELY_REVERT:
-      actionMsg = 'reverted under';
-      actionIcon = 'icon-action-undo';
-      break;
-    case SupportedAction.ACTION_COMMENT_CREATE:
-      actionMsg = 'commented on';
-      actionIcon = 'icon-bubble';
-      break;
-    default:
-      actionMsg = '';
-      actionIcon = '';
-  }
-
-  return {
-    actionMsg,
-    actionIcon,
-  };
-};
-
 const PageModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable, Props> = (props: Props, ref) => {
 
   const {
     notification, actionUsers,
   } = props;
 
-  const { actionMsg, actionIcon } = useActionMsgAndIcon(notification);
+  const { actionMsg, actionIcon } = useActionMsgAndIconForPageModelNotification(notification);
 
   const router = useRouter();
 

+ 3 - 24
apps/app/src/components/InAppNotification/PageNotification/UserModelNotification.tsx

@@ -6,32 +6,11 @@ import type { HasObjectId } from '@growi/core';
 import { useRouter } from 'next/router';
 
 import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
-import { SupportedAction } from '~/interfaces/activity';
 import type { IInAppNotification } from '~/interfaces/in-app-notification';
 
 import { ModelNotification } from './ModelNotification';
-import type { ActionMsgAndIconType } from './PageModelNotification';
-
-const useActionMsgAndIcon = (notification: IInAppNotification & HasObjectId): ActionMsgAndIconType => {
-  const actionType: string = notification.action;
-  let actionMsg: string;
-  let actionIcon: string;
-
-  switch (actionType) {
-    case SupportedAction.ACTION_USER_REGISTRATION_APPROVAL_REQUEST:
-      actionMsg = 'requested registration approval';
-      actionIcon = 'icon-bubble';
-      break;
-    default:
-      actionMsg = '';
-      actionIcon = '';
-  }
-
-  return {
-    actionMsg,
-    actionIcon,
-  };
-};
+import { useActionMsgAndIconForUserModelNotification } from './useActionAndMsg';
+
 
 const UserModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable, {
   notification: IInAppNotification & HasObjectId
@@ -41,7 +20,7 @@ const UserModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable
 }, ref) => {
   const router = useRouter();
 
-  const { actionMsg, actionIcon } = useActionMsgAndIcon(notification);
+  const { actionMsg, actionIcon } = useActionMsgAndIconForUserModelNotification(notification);
 
   // publish open()
   const publishOpen = () => {

+ 99 - 0
apps/app/src/components/InAppNotification/PageNotification/useActionAndMsg.ts

@@ -0,0 +1,99 @@
+import type { HasObjectId } from '@growi/core';
+
+import { SupportedAction } from '~/interfaces/activity';
+import type { IInAppNotification } from '~/interfaces/in-app-notification';
+
+export type ActionMsgAndIconType = {
+  actionMsg: string
+  actionIcon: string
+}
+
+export const useActionMsgAndIconForPageModelNotification = (notification: IInAppNotification & HasObjectId): ActionMsgAndIconType => {
+  const actionType: string = notification.action;
+  let actionMsg: string;
+  let actionIcon: string;
+
+  switch (actionType) {
+    case SupportedAction.ACTION_PAGE_LIKE:
+      actionMsg = 'liked';
+      actionIcon = 'icon-like';
+      break;
+    case SupportedAction.ACTION_PAGE_BOOKMARK:
+      actionMsg = 'bookmarked on';
+      actionIcon = 'icon-star';
+      break;
+    case SupportedAction.ACTION_PAGE_UPDATE:
+      actionMsg = 'updated on';
+      actionIcon = 'ti ti-agenda';
+      break;
+    case SupportedAction.ACTION_PAGE_RENAME:
+      actionMsg = 'renamed';
+      actionIcon = 'icon-action-redo';
+      break;
+    case SupportedAction.ACTION_PAGE_DUPLICATE:
+      actionMsg = 'duplicated';
+      actionIcon = 'icon-docs';
+      break;
+    case SupportedAction.ACTION_PAGE_DELETE:
+      actionMsg = 'deleted';
+      actionIcon = 'icon-trash';
+      break;
+    case SupportedAction.ACTION_PAGE_DELETE_COMPLETELY:
+      actionMsg = 'completely deleted';
+      actionIcon = 'icon-fire';
+      break;
+    case SupportedAction.ACTION_PAGE_REVERT:
+      actionMsg = 'reverted';
+      actionIcon = 'icon-action-undo';
+      break;
+    case SupportedAction.ACTION_PAGE_RECURSIVELY_RENAME:
+      actionMsg = 'renamed under';
+      actionIcon = 'icon-action-redo';
+      break;
+    case SupportedAction.ACTION_PAGE_RECURSIVELY_DELETE:
+      actionMsg = 'deleted under';
+      actionIcon = 'icon-trash';
+      break;
+    case SupportedAction.ACTION_PAGE_RECURSIVELY_DELETE_COMPLETELY:
+      actionMsg = 'deleted completely under';
+      actionIcon = 'icon-fire';
+      break;
+    case SupportedAction.ACTION_PAGE_RECURSIVELY_REVERT:
+      actionMsg = 'reverted under';
+      actionIcon = 'icon-action-undo';
+      break;
+    case SupportedAction.ACTION_COMMENT_CREATE:
+      actionMsg = 'commented on';
+      actionIcon = 'icon-bubble';
+      break;
+    default:
+      actionMsg = '';
+      actionIcon = '';
+  }
+
+  return {
+    actionMsg,
+    actionIcon,
+  };
+};
+
+export const useActionMsgAndIconForUserModelNotification = (notification: IInAppNotification & HasObjectId): ActionMsgAndIconType => {
+  const actionType: string = notification.action;
+  let actionMsg: string;
+  let actionIcon: string;
+
+  switch (actionType) {
+    case SupportedAction.ACTION_USER_REGISTRATION_APPROVAL_REQUEST:
+      actionMsg = 'requested registration approval';
+      actionIcon = 'icon-bubble';
+      break;
+    default:
+      actionMsg = '';
+      actionIcon = '';
+  }
+
+  return {
+    actionMsg,
+    actionIcon,
+  };
+};