Skip to content

Commit 49683dd

Browse files
committed
fix: page navigating when clicking buttons in item cards (#275)
Also updated the layout of OperationCard and OperationSetCard in list layout
1 parent 5eb699e commit 49683dd

File tree

3 files changed

+137
-141
lines changed

3 files changed

+137
-141
lines changed

src/components/OperationCard.tsx

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Button, Card, Elevation, H4, H5, Icon, Tag } from '@blueprintjs/core'
22
import { Tooltip2 } from '@blueprintjs/popover2'
33

4+
import clsx from 'clsx'
45
import { handleCopyShortCode, handleDownloadJSON } from 'services/operation'
56

67
import { ReLink } from 'components/ReLink'
@@ -19,22 +20,21 @@ export const NeoOperationCard = ({ operation }: { operation: Operation }) => {
1920
const { data: levels } = useLevels()
2021

2122
return (
22-
<ReLink search={{ op: operation.id }} className="no-underline">
23-
<Card
24-
interactive={true}
25-
elevation={Elevation.TWO}
26-
className="flex flex-col gap-2"
27-
>
23+
<Card
24+
interactive={true}
25+
elevation={Elevation.TWO}
26+
className="relative flex flex-col gap-2"
27+
>
28+
<ReLink search={{ op: operation.id }} className="block no-underline">
2829
<div className="flex">
2930
<Tooltip2
3031
content={operation.parsedContent.doc.title}
3132
className="grow flex-1 whitespace-nowrap overflow-hidden text-ellipsis"
3233
>
33-
<H4 className="p-0 m-0 whitespace-nowrap overflow-hidden text-ellipsis">
34+
<H4 className="p-0 m-0 mr-20 whitespace-nowrap overflow-hidden text-ellipsis">
3435
{operation.parsedContent.doc.title}
3536
</H4>
3637
</Tooltip2>
37-
<CardActions operation={operation} />
3838
</div>
3939
<div className="flex items-center text-slate-900">
4040
<div className="flex flex-wrap">
@@ -105,28 +105,30 @@ export const NeoOperationCard = ({ operation }: { operation: Operation }) => {
105105
</Tooltip2>
106106
</div>
107107
</div>
108-
</Card>
109-
</ReLink>
108+
</ReLink>
109+
110+
<CardActions className="absolute top-4 right-4" operation={operation} />
111+
</Card>
110112
)
111113
}
112114

113115
export const OperationCard = ({ operation }: { operation: Operation }) => {
114116
const { data: levels } = useLevels()
115117

116118
return (
117-
<ReLink
118-
search={{ op: operation.id }}
119-
className="block mb-4 sm:mb-2 last:mb-0 no-underline"
119+
<Card
120+
interactive={true}
121+
elevation={Elevation.TWO}
122+
className="relative mb-4 sm:mb-2 last:mb-0"
120123
>
121-
<Card interactive={true} elevation={Elevation.TWO}>
124+
<ReLink search={{ op: operation.id }} className="block no-underline">
122125
<div className="flex flex-wrap mb-4 sm:mb-2">
123126
{/* title */}
124127
<div className="flex flex-col gap-3">
125128
<div className="flex gap-2">
126129
<H4 className="inline-block pb-1 border-b-2 border-zinc-200 border-solid mb-2">
127130
{operation.parsedContent.doc.title}
128131
</H4>
129-
<CardActions operation={operation} />
130132
</div>
131133
<H5 className="flex items-center text-slate-900 -mt-3">
132134
<EDifficultyLevel
@@ -141,43 +143,40 @@ export const OperationCard = ({ operation }: { operation: Operation }) => {
141143
</H5>
142144
</div>
143145

144-
<div className="lg:flex-1 hidden" />
146+
<div className="grow basis-full xl:basis-0" />
145147

146148
{/* meta */}
147-
<div className="flex flex-col flex-1 gap-y-1.5 gap-x-4">
148-
<div className="flex flex-wrap sm:justify-end items-center gap-x-4 gap-y-1 text-zinc-500">
149-
<div className="flex items-center gap-1.5">
150-
<Icon icon="star" />
151-
<OperationRating
152-
className="text-sm"
153-
operation={operation}
154-
layout="horizontal"
155-
/>
149+
<div className="flex flex-wrap items-start gap-x-4 gap-y-1 text-zinc-500">
150+
<div className="flex items-center gap-1.5">
151+
<Icon icon="star" />
152+
<OperationRating
153+
className="text-sm"
154+
operation={operation}
155+
layout="horizontal"
156+
/>
157+
</div>
158+
159+
<Tooltip2 placement="top" content={`访问量:${operation.views}`}>
160+
<div>
161+
<Icon icon="eye-open" className="mr-1.5" />
162+
<span>{operation.views}</span>
156163
</div>
164+
</Tooltip2>
157165

158-
<Tooltip2 placement="top" content={`访问量:${operation.views}`}>
159-
<div>
160-
<Icon icon="eye-open" className="mr-1.5" />
161-
<span>{operation.views}</span>
162-
</div>
163-
</Tooltip2>
166+
<div>
167+
<Icon icon="time" className="mr-1.5" />
168+
<RelativeTime
169+
Tooltip2Props={{ placement: 'top' }}
170+
moment={operation.uploadTime}
171+
/>
172+
</div>
164173

174+
<Tooltip2 placement="top" content={`作者:${operation.uploader}`}>
165175
<div>
166-
<Icon icon="time" className="mr-1.5" />
167-
<RelativeTime
168-
Tooltip2Props={{ placement: 'top' }}
169-
moment={operation.uploadTime}
170-
/>
176+
<Icon icon="user" className="mr-1.5" />
177+
<span>{operation.uploader}</span>
171178
</div>
172-
</div>
173-
<div className="text-zinc-500 self-end">
174-
<Tooltip2 placement="top" content={`作者:${operation.uploader}`}>
175-
<div>
176-
<Icon icon="user" className="mr-1.5" />
177-
<span>{operation.uploader}</span>
178-
</div>
179-
</Tooltip2>
180-
</div>
179+
</Tooltip2>
181180
</div>
182181
</div>
183182
<div className="flex md:flex-row flex-col gap-4">
@@ -195,8 +194,13 @@ export const OperationCard = ({ operation }: { operation: Operation }) => {
195194
<OperatorTags operation={operation} />
196195
</div>
197196
</div>
198-
</Card>
199-
</ReLink>
197+
</ReLink>
198+
199+
<CardActions
200+
className="absolute top-4 xl:top-12 right-[18px]"
201+
operation={operation}
202+
/>
203+
</Card>
200204
)
201205
}
202206

@@ -230,16 +234,15 @@ const OperatorTags = ({ operation }: { operation: Operation }) => {
230234
)
231235
}
232236

233-
const CardActions = ({ operation }: { operation: Operation }) => {
237+
const CardActions = ({
238+
className,
239+
operation,
240+
}: {
241+
className?: string
242+
operation: Operation
243+
}) => {
234244
return (
235-
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
236-
<div
237-
className="flex gap-1"
238-
onClick={(e) => {
239-
// 避免点击按钮时触发卡片的链接跳转
240-
e.stopPropagation()
241-
}}
242-
>
245+
<div className={clsx('flex gap-1', className)}>
243246
<Tooltip2
244247
placement="bottom"
245248
content={
@@ -249,10 +252,7 @@ const CardActions = ({ operation }: { operation: Operation }) => {
249252
<Button
250253
small
251254
icon="download"
252-
onClick={(e) => {
253-
e.stopPropagation()
254-
handleDownloadJSON(operation.parsedContent)
255-
}}
255+
onClick={() => handleDownloadJSON(operation.parsedContent)}
256256
/>
257257
</Tooltip2>
258258
<Tooltip2
@@ -264,10 +264,7 @@ const CardActions = ({ operation }: { operation: Operation }) => {
264264
<Button
265265
small
266266
icon="clipboard"
267-
onClick={(e) => {
268-
e.stopPropagation()
269-
handleCopyShortCode(operation)
270-
}}
267+
onClick={() => handleCopyShortCode(operation)}
271268
/>
272269
</Tooltip2>
273270
<Tooltip2

0 commit comments

Comments
 (0)