Skip to content

Commit 9de422f

Browse files
committed
feat: galgame person list and detail page
1 parent ba0c666 commit 9de422f

File tree

18 files changed

+178
-191
lines changed

18 files changed

+178
-191
lines changed

app/api/person/all/route.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { NextRequest, NextResponse } from 'next/server'
33
import { prisma } from '~/prisma/index'
44
import { getPersonSchema } from '~/validations/person'
55
import { kunParseGetQuery } from '~/app/api/utils/parseQuery'
6+
import type { PatchPerson } from '~/types/api/person'
67

78
export const getPerson = async (input: z.infer<typeof getPersonSchema>) => {
89
const { page, limit } = input
910
const offset = (page - 1) * limit
1011

11-
const [persons, total] = await Promise.all([
12+
const [data, total] = await Promise.all([
1213
prisma.patch_person.findMany({
1314
take: limit,
1415
skip: offset,
@@ -25,6 +26,17 @@ export const getPerson = async (input: z.infer<typeof getPersonSchema>) => {
2526
prisma.patch_person.count()
2627
])
2728

29+
const persons: PatchPerson[] = data.map((p) => ({
30+
id: p.id,
31+
image: p.image,
32+
roles: p.roles,
33+
name: {
34+
'zh-cn': p.name_zh_cn,
35+
'ja-jp': p.name_ja_jp,
36+
'en-us': p.name_en_us
37+
}
38+
}))
39+
2840
return { persons, total }
2941
}
3042

app/api/person/route.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from 'next/server'
22
import { z } from 'zod'
33
import { prisma } from '~/prisma'
44
import { kunParseGetQuery } from '../utils/parseQuery'
5+
import type { PatchPersonDetail } from '~/types/api/person'
56

67
const personIdSchema = z.object({ personId: z.coerce.number().min(1) })
78

@@ -20,22 +21,26 @@ export const getPersonById = async (input: z.infer<typeof personIdSchema>) => {
2021
})
2122
const patches = patchRelations.map((pr) => ({
2223
id: pr.patch.id,
23-
name: pr.patch.name,
24+
name_zh_cn: pr.patch.name_zh_cn,
25+
name_ja_jp: pr.patch.name_ja_jp,
26+
name_en_us: pr.patch.name_en_us,
2427
banner: pr.patch.banner
2528
}))
2629

2730
return {
2831
id: person.id,
2932
image: person.image,
3033
roles: person.roles,
31-
language: person.language,
32-
links: person.links,
33-
name_zh_cn: person.name_zh_cn,
34-
name_ja_jp: person.name_ja_jp,
35-
name_en_us: person.name_en_us,
36-
description_zh_cn: person.description_zh_cn,
37-
description_ja_jp: person.description_ja_jp,
38-
description_en_us: person.description_en_us,
34+
name: {
35+
'zh-cn': person.name_zh_cn,
36+
'ja-jp': person.name_ja_jp,
37+
'en-us': person.name_en_us
38+
},
39+
description: {
40+
'zh-cn': person.description_zh_cn,
41+
'ja-jp': person.description_ja_jp,
42+
'en-us': person.description_en_us
43+
},
3944
birthday: person.birthday,
4045
blood_type: person.blood_type,
4146
birthplace: person.birthplace,
@@ -45,8 +50,16 @@ export const getPersonById = async (input: z.infer<typeof personIdSchema>) => {
4550
official_website: person.official_website,
4651
blog: person.blog,
4752
alias: aliases,
48-
patches
49-
}
53+
patches: patches.map((p) => ({
54+
id: p.id,
55+
name: {
56+
'zh-cn': p.name_zh_cn,
57+
'ja-jp': p.name_ja_jp,
58+
'en-us': p.name_en_us
59+
},
60+
banner: p.banner
61+
}))
62+
} satisfies PatchPersonDetail
5063
}
5164

5265
export const GET = async (req: NextRequest) => {

app/character/[id]/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { generateNullMetadata } from '~/utils/noIndex'
44
import { ErrorComponent } from '~/components/error/ErrorComponent'
55
import type { Metadata } from 'next'
66

7+
export const generateMetadata = async (): Promise<Metadata> => {
8+
return generateNullMetadata('角色详情')
9+
}
10+
711
export default async function Kun({
812
params
913
}: {
@@ -18,7 +22,3 @@ export default async function Kun({
1822

1923
return <CharDetailContainer char={response} />
2024
}
21-
22-
export const generateMetadata = async (): Promise<Metadata> => {
23-
return generateNullMetadata('角色详情')
24-
}

app/character/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const generateMetadata = async (): Promise<Metadata> => {
1010
return generateNullMetadata('角色列表')
1111
}
1212

13-
export default async function CharIndex() {
13+
export default async function Kun() {
1414
const response = await kunGetActions({ page: 1, limit: 72 })
1515
if (typeof response === 'string') {
1616
return <ErrorComponent error={response} />

app/person/[id]/metadata.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

app/person/[id]/page.tsx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
1-
import { notFound } from 'next/navigation'
2-
import { z } from 'zod'
3-
import type { Metadata } from 'next'
41
import { getPersonById } from '~/app/api/person/route'
52
import { PersonDetailContainer } from '~/components/person/detail/Container'
6-
import { generateKunMetadataTemplate } from './metadata'
3+
import { generateNullMetadata } from '~/utils/noIndex'
4+
import type { Metadata } from 'next'
5+
import { ErrorComponent } from '~/components/error/ErrorComponent'
76

8-
const paramsSchema = z.object({ id: z.coerce.number().min(1) })
7+
export const generateMetadata = async (): Promise<Metadata> => {
8+
return generateNullMetadata('制作人')
9+
}
910

10-
export default async function PersonDetailPage({
11+
export default async function Kun({
1112
params
1213
}: {
13-
params: { id: string }
14+
params: Promise<{ id: string }>
1415
}) {
15-
const parsed = paramsSchema.safeParse(params)
16-
if (!parsed.success) notFound()
17-
const data = await getPersonById({ personId: parsed.data.id })
18-
if (typeof data === 'string') notFound()
19-
return <PersonDetailContainer person={data} />
20-
}
16+
const { id } = await params
17+
const response = await getPersonById({ personId: Number(id) })
2118

22-
export const generateMetadata = async ({
23-
params
24-
}: {
25-
params: { id: string }
26-
}): Promise<Metadata> => {
27-
const parsed = paramsSchema.safeParse(params)
28-
if (!parsed.success) return {}
29-
const data = await getPersonById({ personId: parsed.data.id })
30-
if (typeof data === 'string') return {}
31-
return generateKunMetadataTemplate(data)
19+
if (typeof response === 'string') {
20+
return <ErrorComponent error={response} />
21+
}
22+
23+
return <PersonDetailContainer person={response} />
3224
}

app/person/metadata.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

app/person/page.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { kunGetActions } from './actions'
22
import { ErrorComponent } from '~/components/error/ErrorComponent'
3-
import type { Metadata } from 'next'
43
import { PersonContainer } from '~/components/person/Container'
5-
import { kunMetadata } from './metadata'
4+
import { generateNullMetadata } from '~/utils/noIndex'
5+
import type { Metadata } from 'next'
66

77
export const revalidate = 5
88

9-
export const metadata: Metadata = kunMetadata
9+
export const generateMetadata = async (): Promise<Metadata> => {
10+
return generateNullMetadata('制作人列表')
11+
}
1012

11-
export default async function PersonIndex() {
12-
const response = await kunGetActions({ page: 1, limit: 100 })
13+
export default async function Kun() {
14+
const response = await kunGetActions({ page: 1, limit: 72 })
1315
if (typeof response === 'string') {
1416
return <ErrorComponent error={response} />
1517
}
18+
1619
return (
1720
<PersonContainer
1821
initialPersons={response.persons}

components/character/Container.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const CharContainer = ({
7474
<div className="flex flex-col w-full my-4 space-y-8">
7575
<KunHeader
7676
name="Galgame 角色列表"
77-
description="这里是 Galgame 游戏中出现的所有 Galgame 角色的列表"
77+
description="这里是 Galgame 游戏中出现的所有 Galgame 角色的列表, 本页面只是随手写一下, 仍在开发中..."
7878
/>
7979

8080
<SearchChars query={query} setQuery={setQuery} searching={searching} />
@@ -83,10 +83,10 @@ export const CharContainer = ({
8383
<CharList chars={chars} loading={loading} searching={searching} />
8484
)}
8585

86-
{total > 100 && !query && (
86+
{total > 72 && !query && (
8787
<div className="flex justify-center">
8888
<Pagination
89-
total={Math.ceil(total / 100)}
89+
total={Math.ceil(total / 72)}
9090
page={page}
9191
onChange={setPage}
9292
showControls

components/character/detail/Container.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export const CharDetailContainer = ({
184184
))}
185185
</div>
186186
) : (
187-
<div className="text-sm text-default-400">暂无参与的 Patch</div>
187+
<div className="text-sm text-default-400">暂无参与的 Galgame</div>
188188
)}
189189
</section>
190190
</main>

0 commit comments

Comments
 (0)