Skip to content

Commit d0b3d60

Browse files
committed
feat: better UX for comments
1 parent 52cc74d commit d0b3d60

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

src/components/viewer/comment/CommentArea.tsx

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import { Operation } from '../../../models/operation'
2929
import { authAtom } from '../../../store/auth'
3030
import { formatError } from '../../../utils/error'
31-
import { formatDateTime } from '../../../utils/times'
31+
import { formatDateTime, formatRelativeTime } from '../../../utils/times'
3232
import { wrapErrorMessage } from '../../../utils/wrapErrorMessage'
3333
import { Markdown } from '../../Markdown'
3434
import { OutlinedIcon } from '../../OutlinedIcon'
@@ -104,9 +104,9 @@ export const CommentArea = withSuspensable(function ViewerComments({
104104
))}
105105
{isReachingEnd && comments.length === 0 && (
106106
<NonIdealState
107-
icon="slash"
108-
title="没有找到任何作业"
109-
description="(つД`)・゚・"
107+
icon="comment"
108+
title="还没有评论,发一条评论鼓励作者吧!"
109+
description="(。・ω・。)ノ♡"
110110
/>
111111
)}
112112

@@ -141,15 +141,10 @@ const MainComment = ({
141141
comment: MainCommentInfo
142142
children?: ReactNode
143143
}) => {
144-
const { uploader, uploadTime } = comment
145-
146144
return (
147145
<Card className={clsx(className)}>
148-
<div className="">
149-
<div className="mb-2 flex text-slate-500">
150-
<div className="font-bold mr-2">{uploader}</div>
151-
<div>{formatDateTime(uploadTime)}</div>
152-
</div>
146+
<div>
147+
<CommentHeader comment={comment} />
153148
<CommentContent comment={comment} />
154149
<CommentActions comment={comment} />
155150
</div>
@@ -167,14 +162,9 @@ const SubComment = ({
167162
comment: SubCommentInfo
168163
fromComment?: SubCommentInfo
169164
}) => {
170-
const { uploader, uploadTime } = comment
171-
172165
return (
173166
<div className={clsx(className, 'pl-8')}>
174-
<div className="mb-2 flex text-slate-500">
175-
<div className="font-bold mr-2">{uploader}</div>
176-
<div>{formatDateTime(uploadTime)}</div>
177-
</div>
167+
<CommentHeader comment={comment} />
178168
{comment.deleted ? (
179169
<div className="italic text-gray-500">(已删除)</div>
180170
) : (
@@ -197,6 +187,27 @@ const SubComment = ({
197187
)
198188
}
199189

190+
const CommentHeader = ({
191+
className,
192+
comment: { uploader, uploaderId, uploadTime },
193+
}: {
194+
className?: string
195+
comment: CommentInfo
196+
}) => {
197+
const [{ userId }] = useAtom(authAtom)
198+
199+
return (
200+
<div className={clsx(className, 'mb-2 flex items-center text-xs')}>
201+
<div className={clsx('mr-2', userId === uploaderId && 'font-bold')}>
202+
{uploader}
203+
</div>
204+
<div className="text-slate-500" title={formatDateTime(uploadTime)}>
205+
{formatRelativeTime(uploadTime)}
206+
</div>
207+
</div>
208+
)
209+
}
210+
200211
const CommentContent = ({
201212
className,
202213
comment: { message },

src/components/viewer/comment/CommentForm.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ export const CommentForm = ({
5959
})(),
6060
)
6161

62+
AppToaster.show({
63+
intent: 'success',
64+
message: `发表成功`,
65+
})
66+
6267
setMessage('')
6368
reload()
6469
} finally {

0 commit comments

Comments
 (0)