Skip to content

Commit 55bdaa5

Browse files
committed
feat: clickable user names
1 parent 72b0d3b commit 55bdaa5

File tree

7 files changed

+63
-33
lines changed

7 files changed

+63
-33
lines changed

src/components/OperationCard.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useLevels } from '../apis/level'
1313
import { createCustomLevel, findLevelByStageName } from '../models/level'
1414
import { Paragraphs } from './Paragraphs'
1515
import { ReLinkDiv } from './ReLinkDiv'
16+
import { UserName } from './UserName'
1617
import { EDifficulty } from './entity/EDifficulty'
1718
import { EDifficultyLevel, NeoELevel } from './entity/ELevel'
1819

@@ -96,15 +97,13 @@ export const NeoOperationCard = ({ operation }: { operation: Operation }) => {
9697
</div>
9798
<div className="flex-1" />
9899
<div className="text-zinc-500">
99-
<Tooltip2 placement="top" content={`作者:${operation.uploader}`}>
100-
<div>
101-
<Icon icon="user" className="mr-1.5" />
102-
<span>{operation.uploader}</span>
103-
</div>
104-
</Tooltip2>
100+
<Icon icon="user" className="mr-1.5" />
101+
<UserName userId={operation.uploaderId}>
102+
{operation.uploader}
103+
</UserName>
105104
</div>
106105
</div>
107-
</ReLink>
106+
</ReLinkDiv>
108107

109108
<CardActions className="absolute top-4 right-4" operation={operation} />
110109
</Card>
@@ -170,12 +169,12 @@ export const OperationCard = ({ operation }: { operation: Operation }) => {
170169
/>
171170
</div>
172171

173-
<Tooltip2 placement="top" content={`作者:${operation.uploader}`}>
174-
<div>
175-
<Icon icon="user" className="mr-1.5" />
176-
<span>{operation.uploader}</span>
177-
</div>
178-
</Tooltip2>
172+
<div>
173+
<Icon icon="user" className="mr-1.5" />
174+
<UserName userId={operation.uploaderId}>
175+
{operation.uploader}
176+
</UserName>
177+
</div>
179178
</div>
180179
</div>
181180
<div className="flex md:flex-row flex-col gap-4">

src/components/OperationSetCard.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { RelativeTime } from 'components/RelativeTime'
88
import { OperationSetListItem } from 'models/operation-set'
99

1010
import { Paragraphs } from './Paragraphs'
11+
import { UserName } from './UserName'
1112

1213
export const NeoOperationSetCard = ({
1314
operationSet,
@@ -60,12 +61,10 @@ export const NeoOperationSetCard = ({
6061
</div>
6162
<div className="flex-1" />
6263
<div className="text-zinc-500">
63-
<Tooltip2 placement="top" content={`作者:${operationSet.creator}`}>
64-
<div>
65-
<Icon icon="user" className="mr-1.5" />
66-
<span>{operationSet.creator}</span>
67-
</div>
68-
</Tooltip2>
64+
<Icon icon="user" className="mr-1.5" />
65+
<UserName userId={operationSet.creatorId}>
66+
{operationSet.creator}
67+
</UserName>
6968
</div>
7069
</div>
7170
</ReLink>
@@ -117,12 +116,12 @@ export const OperationSetCard = ({
117116
moment={operationSet.createTime}
118117
/>
119118
</div>
120-
<Tooltip2 placement="top" content={`作者:${operationSet.creator}`}>
121-
<div>
122-
<Icon icon="user" className="mr-1.5" />
123-
<span>{operationSet.creator}</span>
124-
</div>
125-
</Tooltip2>
119+
<div>
120+
<Icon icon="user" className="mr-1.5" />
121+
<UserName userId={operationSet.creatorId}>
122+
{operationSet.creator}
123+
</UserName>
124+
</div>
126125
</div>
127126
</div>
128127
<div className="flex md:flex-row flex-col gap-4">

src/components/ReLink.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { isString } from '@sentry/utils'
22

3-
import clsx from 'clsx'
43
import { Link, LinkProps, useSearchParams } from 'react-router-dom'
54
import { SetOptional } from 'type-fest'
65

@@ -25,7 +24,7 @@ export function ReLink({ className, search, ...props }: ReLinkProps) {
2524
return (
2625
<Link
2726
{...props}
28-
className={clsx('hover:no-underline hover:text-inherit', className)}
27+
className={className}
2928
to={
3029
isString(props.to)
3130
? props.to

src/components/UserName.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { FC, ReactNode } from 'react'
2+
3+
import { ReLink } from './ReLink'
4+
5+
interface UserNameProps {
6+
className?: string
7+
userId: string
8+
children: ReactNode
9+
}
10+
11+
export const UserName: FC<UserNameProps> = ({
12+
className,
13+
userId,
14+
children,
15+
}) => {
16+
return (
17+
<ReLink className={className} to={`/profile/${userId}`}>
18+
{children}
19+
</ReLink>
20+
)
21+
}

src/components/viewer/OperationSetViewer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { authAtom } from 'store/auth'
3434
import { wrapErrorMessage } from 'utils/wrapErrorMessage'
3535

3636
import { formatError } from '../../utils/error'
37+
import { UserName } from '../UserName'
3738

3839
const ManageMenu: FC<{
3940
operationSet: OperationSet
@@ -225,9 +226,12 @@ function OperationSetViewerInner({
225226
</FactItem>
226227

227228
<FactItem title="作者" icon="user">
228-
<span className="text-gray-800 dark:text-slate-100 font-bold">
229+
<UserName
230+
className="text-gray-800 dark:text-slate-100 font-bold"
231+
userId={operationSet.creatorId}
232+
>
229233
{operationSet.creator}
230-
</span>
234+
</UserName>
231235
</FactItem>
232236
</div>
233237
</div>

src/components/viewer/OperationViewer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { createCustomLevel, findLevelByStageName } from '../../models/level'
4545
import { Level } from '../../models/operation'
4646
import { formatError } from '../../utils/error'
4747
import { ActionCard } from '../ActionCard'
48+
import { UserName } from '../UserName'
4849
import { CommentArea } from './comment/CommentArea'
4950

5051
const ManageMenu: FC<{
@@ -351,9 +352,12 @@ function OperationViewerInner({
351352
</FactItem>
352353

353354
<FactItem title="作者" icon="user">
354-
<span className="text-gray-800 dark:text-slate-100 font-bold">
355+
<UserName
356+
className="text-gray-800 dark:text-slate-100 font-bold"
357+
userId={operation.uploaderId}
358+
>
355359
{operation.uploader}
356-
</span>
360+
</UserName>
357361
</FactItem>
358362
</div>
359363
</div>

src/components/viewer/comment/CommentArea.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { wrapErrorMessage } from '../../../utils/wrapErrorMessage'
3737
import { Markdown } from '../../Markdown'
3838
import { OutlinedIcon } from '../../OutlinedIcon'
3939
import { withSuspensable } from '../../Suspensable'
40+
import { UserName } from '../../UserName'
4041
import { CommentForm } from './CommentForm'
4142

4243
interface CommentAreaProps {
@@ -194,7 +195,10 @@ const SubComment = ({
194195
{fromComment && (
195196
<>
196197
<Tag minimal className="mr-px">
197-
回复 @{fromComment.uploader}
198+
回复
199+
<UserName userId={fromComment.uploaderId}>
200+
@{fromComment.uploader}
201+
</UserName>
198202
</Tag>
199203
:&nbsp;
200204
</>
@@ -228,7 +232,7 @@ const CommentHeader = ({
228232
)}
229233
>
230234
<div className={clsx('mr-2', userId === uploaderId && 'font-bold')}>
231-
{uploader}
235+
<UserName userId={uploaderId}>{uploader}</UserName>
232236
</div>
233237
<div className="text-slate-500" title={formatDateTime(uploadTime)}>
234238
{formatRelativeTime(uploadTime)}

0 commit comments

Comments
 (0)