forked from bangumi/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommentInfo.tsx
35 lines (29 loc) · 853 Bytes
/
CommentInfo.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import './style';
import dayjs from 'dayjs';
import type { FC } from 'react';
import React, { memo } from 'react';
export interface CommentInfoProps {
floor: string | number;
isSpecial?: boolean;
createdAt: number | string | Date;
id?: number;
}
const spaces = '\u00A0'.repeat(2);
const CommentInfo: FC<CommentInfoProps> = ({ floor, createdAt, isSpecial = false, id = '' }) => {
let date: string;
if (typeof createdAt === 'number') {
date = dayjs(createdAt * 1000).format('YYYY-M-D HH:mm');
} else {
date = dayjs(createdAt).format('YYYY-M-D HH:mm');
}
return !isSpecial ? (
<span className='bgm-topic__commentInfo'>
<a href={`#post_${id}`}>#{floor}</a>
{spaces}|{spaces}
{date}
</span>
) : (
<span className='bgm-topic__commentInfo'>{date}</span>
);
};
export default memo(CommentInfo);