Shun Miyazawa 3 лет назад
Родитель
Сommit
258797bf02

+ 1 - 2
packages/app/src/components/InAppNotification/InAppNotificationList.tsx

@@ -3,7 +3,6 @@ import React, { FC } from 'react';
 import { HasObjectId } from '@growi/core';
 import { HasObjectId } from '@growi/core';
 
 
 import type { IInAppNotification, PaginateResult } from '~/interfaces/in-app-notification';
 import type { IInAppNotification, PaginateResult } from '~/interfaces/in-app-notification';
-import { isIPageSnapshot } from '~/models/serializers/in-app-notification-snapshot/page';
 
 
 import InAppNotificationElm from './InAppNotificationElm';
 import InAppNotificationElm from './InAppNotificationElm';
 
 
@@ -27,7 +26,7 @@ const InAppNotificationList: FC<Props> = (props: Props) => {
     );
     );
   }
   }
 
 
-  const notifications = inAppNotificationData.docs.filter((notification) => { return isIPageSnapshot(notification.snapshot) });
+  const notifications = inAppNotificationData.docs.filter((notification) => { return notification.parsedSnapshot != null });
 
 
   return (
   return (
     <>
     <>

+ 1 - 5
packages/app/src/components/InAppNotification/PageNotification/PageModelNotification.tsx

@@ -8,7 +8,6 @@ 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 type { IPageSnapshot } from '~/models/serializers/in-app-notification-snapshot/page';
 
 
 import FormattedDistanceDate from '../../FormattedDistanceDate';
 import FormattedDistanceDate from '../../FormattedDistanceDate';
 
 
@@ -27,9 +26,6 @@ const PageModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable
 
 
   const router = useRouter();
   const router = useRouter();
 
 
-  // Type is determined by type guard in InAppNotificationList.tsx
-  const snapshot = notification.snapshot as IPageSnapshot;
-
   // publish open()
   // publish open()
   useImperativeHandle(ref, () => ({
   useImperativeHandle(ref, () => ({
     open() {
     open() {
@@ -46,7 +42,7 @@ const PageModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable
   return (
   return (
     <div className="p-2 overflow-hidden">
     <div className="p-2 overflow-hidden">
       <div className="text-truncate">
       <div className="text-truncate">
-        <b>{actionUsers}</b> {actionMsg} <PagePathLabel path={snapshot.path} />
+        <b>{actionUsers}</b> {actionMsg} <PagePathLabel path={notification.parsedSnapshot?.path ?? ''} />
       </div>
       </div>
       <i className={`${actionIcon} mr-2`} />
       <i className={`${actionIcon} mr-2`} />
       <FormattedDistanceDate
       <FormattedDistanceDate

+ 2 - 1
packages/app/src/interfaces/in-app-notification.ts

@@ -17,7 +17,8 @@ export interface IInAppNotification {
   status: InAppNotificationStatuses
   status: InAppNotificationStatuses
   actionUsers: IUser[]
   actionUsers: IUser[]
   createdAt: Date
   createdAt: Date
-  snapshot: string | IPageSnapshot;
+  snapshot: string
+  parsedSnapshot?: IPageSnapshot
 }
 }
 
 
 /*
 /*

+ 1 - 1
packages/app/src/stores/in-app-notification.ts

@@ -22,7 +22,7 @@ export const useSWRxInAppNotifications = <Data, Error>(
       const inAppNotificationPaginateResult = response.data as inAppNotificationPaginateResult;
       const inAppNotificationPaginateResult = response.data as inAppNotificationPaginateResult;
       inAppNotificationPaginateResult.docs.forEach((doc) => {
       inAppNotificationPaginateResult.docs.forEach((doc) => {
         try {
         try {
-          doc.snapshot = parseSnapshot(doc.snapshot as string);
+          doc.parsedSnapshot = parseSnapshot(doc.snapshot as string);
         }
         }
         catch (err) {
         catch (err) {
           logger.warn('Failed to parse snapshot', err);
           logger.warn('Failed to parse snapshot', err);