Skip to content

Commit a9fdfa5

Browse files
committed
refactor: refactor patch resource page
1 parent f21b029 commit a9fdfa5

File tree

10 files changed

+459
-523
lines changed

10 files changed

+459
-523
lines changed

components/kun/PatchAttribute.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ export const KunPatchAttribute = ({
5959
{modelName}
6060
</Chip>
6161
)}
62-
{!!downloadCount && (
63-
<Chip variant="flat" color="default" size={size}>
64-
{`${downloadCount} 人下载`}
65-
</Chip>
66-
)}
6762
{storage && (
6863
<Chip
6964
color="secondary"
@@ -74,10 +69,19 @@ export const KunPatchAttribute = ({
7469
</Chip>
7570
)}
7671
{storageSize && (
77-
<Chip variant="flat" startContent={<Database className="w-4 h-4" />}>
72+
<Chip
73+
variant="flat"
74+
color="warning"
75+
startContent={<Database className="w-4 h-4" />}
76+
>
7877
{storageSize}
7978
</Chip>
8079
)}
80+
{!!downloadCount && (
81+
<Chip variant="flat" color="default" size={size}>
82+
{`${downloadCount} 人下载`}
83+
</Chip>
84+
)}
8185
</div>
8286
)
8387
}

components/patch/resource/Resource.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ import { kunFetchDelete, kunFetchPut } from '~/utils/kunFetch'
3030
import { PublishResource } from './publish/PublishResource'
3131
import { EditResourceDialog } from './edit/EditResourceDialog'
3232
import { useUserStore } from '~/store/userStore'
33-
import { ResourceInfo } from './ResourceInfo'
3433
import { ResourceDownload } from './ResourceDownload'
3534
import toast from 'react-hot-toast'
3635
import { kunCopy } from '~/utils/kunCopy'
3736
import { kunMoyuMoe } from '~/config/moyu-moe'
3837
import type { PatchResourceHtml } from '~/types/api/patch'
3938
import { cn } from '~/utils/cn'
39+
import { KunPatchAttribute } from '~/components/kun/PatchAttribute'
4040

4141
interface Props {
4242
initialResources: PatchResourceHtml[]
@@ -159,7 +159,15 @@ export const Resources = ({ initialResources, id }: Props) => {
159159
>
160160
<CardBody className="space-y-2">
161161
<div className="flex items-start justify-between">
162-
<ResourceInfo resource={resource} />
162+
<KunPatchAttribute
163+
types={resource.type}
164+
languages={resource.language}
165+
platforms={resource.platform}
166+
modelName={resource.modelName}
167+
downloadCount={resource.download}
168+
storageSize={resource.size}
169+
storage={resource.storage}
170+
/>
163171

164172
<Dropdown>
165173
<DropdownTrigger>

components/patch/resource/ResourceDownload.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import DOMPurify from 'isomorphic-dompurify'
44
import { useState, useRef, useLayoutEffect } from 'react'
5-
import { Button } from '@heroui/react'
5+
import { Button, Link } from '@heroui/react'
66
import { KunUser } from '~/components/kun/floating-card/KunUser'
77
import { Download, ChevronDown, ChevronUp, Ban } from 'lucide-react'
88
import { formatDistanceToNow } from '~/utils/formatDistanceToNow'
@@ -109,7 +109,10 @@ export const ResourceDownload = ({ resource }: Props) => {
109109
color={resource.status ? 'danger' : 'primary'}
110110
variant={resource.status ? 'solid' : 'flat'}
111111
isIconOnly
112+
as={Link}
113+
href={`/resource/${resource.id}`}
112114
aria-label={`下载 Galgame 补丁资源`}
115+
disabled={!!resource.status}
113116
>
114117
{resource.status ? (
115118
<Ban className="size-4" />

components/patch/resource/ResourceInfo.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
1-
import { useState } from 'react'
2-
import { kunFetchPut } from '~/utils/kunFetch'
3-
import { Button } from '@heroui/button'
4-
import { Tooltip } from '@heroui/tooltip'
5-
import { Heart } from 'lucide-react'
6-
import { useUserStore } from '~/store/userStore'
7-
import toast from 'react-hot-toast'
8-
import { kunErrorHandler } from '~/utils/kunErrorHandler'
9-
import { cn } from '~/utils/cn'
10-
import { PatchResourceHtml } from '~/types/api/patch'
11-
12-
interface Props {
13-
resource: PatchResourceHtml
14-
}
15-
16-
export const ResourceLikeButton = ({ resource }: Props) => {
17-
const { user } = useUserStore((state) => state)
18-
19-
const [liked, setLiked] = useState(resource.isLike)
20-
const [likeCount, setLikeCount] = useState(resource.likeCount)
21-
const [loading, setLoading] = useState(false)
22-
23-
const toggleLike = async () => {
24-
if (!user.uid) {
25-
toast.error('请登录以点赞')
26-
return
27-
}
28-
29-
if (resource.user.id === user.uid) {
30-
toast.error('您不能给自己点赞')
31-
return
32-
}
33-
34-
setLoading(true)
35-
36-
const res = await kunFetchPut<KunResponse<boolean>>(
37-
'/patch/resource/like',
38-
{ resourceId: resource.id }
39-
)
40-
41-
setLoading(false)
42-
kunErrorHandler(res, (value) => {
43-
setLiked(value)
44-
setLikeCount((prev) => (value ? prev + 1 : prev - 1))
45-
})
46-
}
47-
48-
return (
49-
<Tooltip key="like" color="default" content="点赞" placement="bottom">
50-
<Button
51-
variant="light"
52-
disabled={loading}
53-
onPress={toggleLike}
54-
className="min-w-0 px-2"
55-
>
56-
<Heart
57-
fill={liked ? '#f31260' : '#00000000'}
58-
className={cn('w-4 h-4', liked ? 'text-danger-500' : '')}
59-
/>
60-
{likeCount}
61-
</Button>
62-
</Tooltip>
63-
)
64-
}
1+
import { useState } from 'react'
2+
import { kunFetchPut } from '~/utils/kunFetch'
3+
import { Button } from '@heroui/button'
4+
import { Tooltip } from '@heroui/tooltip'
5+
import { Heart } from 'lucide-react'
6+
import { useUserStore } from '~/store/userStore'
7+
import toast from 'react-hot-toast'
8+
import { kunErrorHandler } from '~/utils/kunErrorHandler'
9+
import { cn } from '~/utils/cn'
10+
import { PatchResourceHtml } from '~/types/api/patch'
11+
12+
interface Props {
13+
resource: PatchResourceHtml
14+
}
15+
16+
export const ResourceLikeButton = ({ resource }: Props) => {
17+
const { user } = useUserStore((state) => state)
18+
19+
const [liked, setLiked] = useState(resource.isLike)
20+
const [likeCount, setLikeCount] = useState(resource.likeCount)
21+
const [loading, setLoading] = useState(false)
22+
23+
const toggleLike = async () => {
24+
if (!user.uid) {
25+
toast.error('请登录以点赞')
26+
return
27+
}
28+
29+
if (resource.user.id === user.uid) {
30+
toast.error('您不能给自己点赞')
31+
return
32+
}
33+
34+
setLoading(true)
35+
36+
const res = await kunFetchPut<KunResponse<boolean>>(
37+
'/patch/resource/like',
38+
{ resourceId: resource.id }
39+
)
40+
41+
setLoading(false)
42+
kunErrorHandler(res, (value) => {
43+
setLiked(value)
44+
setLikeCount((prev) => (value ? prev + 1 : prev - 1))
45+
})
46+
}
47+
48+
return (
49+
<Tooltip key="like" color="default" content="点赞" placement="bottom">
50+
<Button
51+
variant="flat"
52+
disabled={loading}
53+
onPress={toggleLike}
54+
className="min-w-0 px-2"
55+
>
56+
<Heart
57+
fill={liked ? '#f31260' : '#00000000'}
58+
className={cn('w-4 h-4', liked ? 'text-danger-500' : '')}
59+
/>
60+
{likeCount}
61+
</Button>
62+
</Tooltip>
63+
)
64+
}

0 commit comments

Comments
 (0)