Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc987f8b

Browse files
committed
feat: create a galgame rating
1 parent0234293 commitc987f8b

File tree

14 files changed

+733
-13
lines changed

14 files changed

+733
-13
lines changed

‎app/api/patch/rating/create.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import{z}from'zod'
22
import{prisma}from'~/prisma/index'
33
import{patchRatingCreateSchema}from'~/validations/patch'
4+
importtype{KunPatchRating}from'~/types/api/galgame'
45

56
exportconstcreatePatchRating=async(
67
input:z.infer<typeofpatchRatingCreateSchema>,
@@ -21,7 +22,7 @@ export const createPatchRating = async (
2122
}
2223
})
2324
if(exists){
24-
return'您已经评价过该补丁'
25+
return'您已经评价过该游戏'
2526
}
2627

2728
constdata=awaitprisma.patch_rating.create({
@@ -62,8 +63,8 @@ export const createPatchRating = async (
6263
likeCount:0,
6364
userId:data.user_id,
6465
patchId:data.patch_id,
65-
created:String(data.created),
66-
updated:String(data.updated),
66+
created:data.created,
67+
updated:data.updated,
6768
user:data.user
68-
}
69+
}satisfiesKunPatchRating
6970
}

‎app/api/patch/rating/get.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import{z}from'zod'
22
import{prisma}from'~/prisma/index'
3+
importtype{KunPatchRating}from'~/types/api/galgame'
34

45
constpatchIdSchema=z.object({
56
patchId:z.coerce.number().min(1).max(9999999)
@@ -15,7 +16,13 @@ export const getPatchRating = async (
1516
where:{patch_id:patchId},
1617
include:{
1718
patch:{select:{unique_id:true}},
18-
user:true,
19+
user:{
20+
select:{
21+
id:true,
22+
name:true,
23+
avatar:true
24+
}
25+
},
1926
_count:{
2027
select:{like:true}
2128
},
@@ -27,7 +34,7 @@ export const getPatchRating = async (
2734
}
2835
})
2936

30-
constratings=data.map((rating)=>({
37+
constratings:KunPatchRating[]=data.map((rating)=>({
3138
id:rating.id,
3239
uniqueId:rating.patch.unique_id,
3340
recommend:rating.recommend,
@@ -39,8 +46,8 @@ export const getPatchRating = async (
3946
likeCount:rating._count.like,
4047
userId:rating.user_id,
4148
patchId:rating.patch_id,
42-
created:String(rating.created),
43-
updated:String(rating.updated),
49+
created:rating.created,
50+
updated:rating.updated,
4451
user:{
4552
id:rating.user.id,
4653
name:rating.user.name,

‎app/api/patch/rating/update.ts‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import{z}from'zod'
22
import{prisma}from'~/prisma/index'
33
import{patchRatingUpdateSchema}from'~/validations/patch'
4+
importtype{KunPatchRating}from'~/types/api/galgame'
45

56
exportconstupdatePatchRating=async(
67
input:z.infer<typeofpatchRatingUpdateSchema>,
@@ -28,7 +29,7 @@ export const updatePatchRating = async (
2829
return'您没有权限更新该评价'
2930
}
3031

31-
awaitprisma.patch_rating.update({
32+
constdata=awaitprisma.patch_rating.update({
3233
where:{id:ratingId,user_id:ratingUserUid},
3334
data:{
3435
patch_id:patchId,
@@ -37,8 +38,41 @@ export const updatePatchRating = async (
3738
play_status:playStatus,
3839
short_summary:shortSummary,
3940
spoiler_level:spoilerLevel
41+
},
42+
include:{
43+
patch:{select:{unique_id:true}},
44+
user:{
45+
select:{
46+
id:true,
47+
name:true,
48+
avatar:true
49+
}
50+
},
51+
_count:{
52+
select:{like:true}
53+
},
54+
like:{
55+
where:{
56+
user_id:uid
57+
}
58+
}
4059
}
4160
})
4261

43-
return{}
62+
return{
63+
id:data.id,
64+
uniqueId:data.patch.unique_id,
65+
recommend:data.recommend,
66+
overall:data.overall,
67+
playStatus:data.play_status,
68+
shortSummary:data.short_summary,
69+
spoilerLevel:data.spoiler_level,
70+
isLike:data.like.length>0,
71+
likeCount:data._count.like,
72+
userId:data.user_id,
73+
patchId:data.patch_id,
74+
created:data.created,
75+
updated:data.updated,
76+
user:data.user
77+
}satisfiesKunPatchRating
4478
}

‎components/kun/floating-card/KunUser.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const KunUser = ({ user, userProps }: KunUserProps) => {
4040
name:username,
4141
alt:altString,
4242
className:
43-
'transition-transformborderduration-200 cursor-pointer shrink-0 hover:scale-110',
43+
'transition-transform duration-200 cursor-pointer shrink-0 hover:scale-110',
4444
...restAvatar
4545
}}
4646
className="cursor-pointer"

‎components/patch/header/Actions.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { kunCopy } from '~/utils/kunCopy'
1818
import{kunMoyuMoe}from'~/config/moyu-moe'
1919
importtoastfrom'react-hot-toast'
2020
import{FavoriteButton}from'./button/favorite/FavoriteButton'
21+
import{RatingButton}from'./button/rating/RatingButton'
2122
import{FeedbackButton}from'./button/FeedbackButton'
2223
importtype{Patch}from'~/types/api/patch'
2324

@@ -81,6 +82,8 @@ export const PatchHeaderActions = ({
8182
</Button>
8283
</Tooltip>
8384

85+
<RatingButtonpatchId={patch.id}/>
86+
8487
<FavoriteButtonpatchId={patch.id}isFavorite={patch.isFavorite}/>
8588

8689
<Tooltipcontent="复制分享链接">

‎components/patch/header/Tabs.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Tab, Tabs } from '@heroui/tabs'
22
import{IntroductionTab}from'~/components/patch/introduction/IntroductionTab'
33
import{ResourceTab}from'~/components/patch/resource/ResourceTab'
44
import{CommentTab}from'~/components/patch/comment/CommentTab'
5+
import{RatingTab}from'~/components/patch/rating/RatingTab'
56
importtype{PatchIntroduction}from'~/types/api/patch'
67
importtype{Dispatch,SetStateAction}from'react'
78

@@ -44,7 +45,9 @@ export const PatchHeaderTabs = ({
4445
<CommentTabid={id}/>
4546
</Tab>
4647

47-
<Tabkey="rating"title="游戏评价"className="p-0 min-w-20"></Tab>
48+
<Tabkey="rating"title="游戏评价"className="p-0 min-w-20">
49+
<RatingTabid={id}/>
50+
</Tab>
4851
</Tabs>
4952
)
5053
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use client'
2+
3+
import{Button,Tooltip,Modal,useDisclosure}from'@heroui/react'
4+
import{Star}from'lucide-react'
5+
importtoastfrom'react-hot-toast'
6+
import{useUserStore}from'~/store/userStore'
7+
import{RatingModal}from'~/components/patch/rating/RatingModal'
8+
9+
interfaceProps{
10+
patchId:number
11+
}
12+
13+
exportconstRatingButton=({ patchId}:Props)=>{
14+
const{ user}=useUserStore((state)=>state)
15+
const{ isOpen, onOpen, onClose}=useDisclosure()
16+
17+
constonPress=()=>{
18+
if(!user.uid){
19+
toast.error('请登陆后再评分')
20+
return
21+
}
22+
onOpen()
23+
}
24+
25+
return(
26+
<>
27+
<Tooltipcontent="提交评分">
28+
<Button
29+
variant="flat"
30+
color="primary"
31+
startContent={<StarclassName="size-4"/>}
32+
size="sm"
33+
onPress={onPress}
34+
>
35+
评分
36+
</Button>
37+
</Tooltip>
38+
39+
<Modal
40+
isOpen={isOpen}
41+
onClose={onClose}
42+
isDismissable={false}
43+
isKeyboardDismissDisabled={true}
44+
>
45+
<RatingModalisOpen={isOpen}onClose={onClose}patchId={patchId}/>
46+
</Modal>
47+
</>
48+
)
49+
}

‎components/patch/introduction/IntroductionTab.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { KunLink } from '~/components/kun/milkdown/plugins/components/link/KunLi
1313
import{KunExternalLink}from'~/components/kun/external-link/ExternalLink'
1414
importtype{PatchIntroduction}from'~/types/api/patch'
1515

16+
//@ts-expect-error
1617
import'./_adjust.scss'
1718

1819
constKunPlyr=dynamic(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp