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

Merge pull request #7281 from weseek/fix/500-at-comments

fix: Type guard comment.createdAt
Haku Mizuki 3 лет назад
Родитель
Сommit
35e41cc171
1 измененных файлов с 8 добавлено и 2 удалено
  1. 8 2
      packages/app/src/components/PageComment/Comment.tsx

+ 8 - 2
packages/app/src/components/PageComment/Comment.tsx

@@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react';
 
 
 import { IUser, pathUtils } from '@growi/core';
 import { IUser, pathUtils } from '@growi/core';
 import { UserPicture } from '@growi/ui';
 import { UserPicture } from '@growi/ui';
-import { format } from 'date-fns';
+import { format, parseISO } from 'date-fns';
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import Link from 'next/link';
 import Link from 'next/link';
 import { UncontrolledTooltip } from 'reactstrap';
 import { UncontrolledTooltip } from 'reactstrap';
@@ -79,12 +79,18 @@ export const Comment = (props: CommentProps): JSX.Element => {
   const getRootClassName = (comment: ICommentHasId) => {
   const getRootClassName = (comment: ICommentHasId) => {
     let className = 'page-comment flex-column';
     let className = 'page-comment flex-column';
 
 
+    // TODO: fix so that `comment.createdAt` to be type Date https://redmine.weseek.co.jp/issues/113876
+    let commentCreatedAt = comment.createdAt;
+    if (typeof commentCreatedAt === 'string') {
+      commentCreatedAt = parseISO(commentCreatedAt);
+    }
+
     // Conditional for called from SearchResultContext
     // Conditional for called from SearchResultContext
     if (revisionId != null && revisionCreatedAt != null) {
     if (revisionId != null && revisionCreatedAt != null) {
       if (comment.revision === revisionId) {
       if (comment.revision === revisionId) {
         className += ' page-comment-current';
         className += ' page-comment-current';
       }
       }
-      else if (comment.createdAt.getTime() > revisionCreatedAt.getTime()) {
+      else if (commentCreatedAt.getTime() > revisionCreatedAt.getTime()) {
         className += ' page-comment-newer';
         className += ' page-comment-newer';
       }
       }
       else {
       else {