|
@@ -1,32 +1,53 @@
|
|
|
import React, {
|
|
import React, {
|
|
|
- forwardRef, ForwardRefRenderFunction,
|
|
|
|
|
|
|
+ forwardRef, ForwardRefRenderFunction, useCallback,
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
|
|
|
-import type { HasObjectId } from '@growi/core';
|
|
|
|
|
|
|
+import type { IPage, HasObjectId } from '@growi/core';
|
|
|
import { useRouter } from 'next/router';
|
|
import { useRouter } from 'next/router';
|
|
|
|
|
|
|
|
import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
|
|
import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
|
|
|
import type { IInAppNotification } from '~/interfaces/in-app-notification';
|
|
import type { IInAppNotification } from '~/interfaces/in-app-notification';
|
|
|
|
|
+import * as pageSerializers from '~/models/serializers/in-app-notification-snapshot/page';
|
|
|
|
|
|
|
|
import { ModelNotification } from './ModelNotification';
|
|
import { ModelNotification } from './ModelNotification';
|
|
|
import { useActionMsgAndIconForPageModelNotification } from './useActionAndMsg';
|
|
import { useActionMsgAndIconForPageModelNotification } from './useActionAndMsg';
|
|
|
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
|
- notification: IInAppNotification & HasObjectId
|
|
|
|
|
- actionUsers: string
|
|
|
|
|
|
|
+ notification: IInAppNotification<IPage> & HasObjectId
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const PageModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable, Props> = (props: Props, ref) => {
|
|
const PageModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable, Props> = (props: Props, ref) => {
|
|
|
|
|
|
|
|
- const {
|
|
|
|
|
- notification, actionUsers,
|
|
|
|
|
- } = props;
|
|
|
|
|
|
|
+ const { notification } = props;
|
|
|
|
|
|
|
|
const { actionMsg, actionIcon } = useActionMsgAndIconForPageModelNotification(notification);
|
|
const { actionMsg, actionIcon } = useActionMsgAndIconForPageModelNotification(notification);
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
|
|
+ const getActionUsers = useCallback(() => {
|
|
|
|
|
+ const latestActionUsers = notification.actionUsers.slice(0, 3);
|
|
|
|
|
+ const latestUsers = latestActionUsers.map((user) => {
|
|
|
|
|
+ return `@${user.name}`;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ let actionedUsers = '';
|
|
|
|
|
+ const latestUsersCount = latestUsers.length;
|
|
|
|
|
+ if (latestUsersCount === 1) {
|
|
|
|
|
+ actionedUsers = latestUsers[0];
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (notification.actionUsers.length >= 4) {
|
|
|
|
|
+ actionedUsers = `${latestUsers.slice(0, 2).join(', ')} and ${notification.actionUsers.length - 2} others`;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ actionedUsers = latestUsers.join(', ');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return actionedUsers;
|
|
|
|
|
+ }, [notification.actionUsers]);
|
|
|
|
|
+
|
|
|
|
|
+ const actionUsers = getActionUsers();
|
|
|
|
|
+
|
|
|
// publish open()
|
|
// publish open()
|
|
|
const publishOpen = () => {
|
|
const publishOpen = () => {
|
|
|
if (notification.target != null) {
|
|
if (notification.target != null) {
|
|
@@ -38,6 +59,8 @@ const PageModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ notification.parsedSnapshot = pageSerializers.parseSnapshot(notification.snapshot);
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<ModelNotification
|
|
<ModelNotification
|
|
|
notification={notification}
|
|
notification={notification}
|