Skip to content

Commit 7c42cfe

Browse files
committed
feat: skip NSFW confirm for login users
1 parent 2edb78c commit 7c42cfe

File tree

3 files changed

+56
-60
lines changed

3 files changed

+56
-60
lines changed

.env-cmdrc

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

app/patch/[id]/layout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ErrorComponent } from '~/components/error/ErrorComponent'
22
import { kunGetPatchActions, kunGetPatchIntroductionActions } from './actions'
33
import { generateKunMetadataTemplate } from './metadata'
44
import { PatchContainer } from '~/components/patch/Container'
5+
import { verifyHeaderCookie } from '~/utils/actions/verifyHeaderCookie'
56
import type { Metadata } from 'next'
67

78
interface Props {
@@ -41,8 +42,10 @@ export default async function Kun({ params, children }: Props) {
4142
return <ErrorComponent error={intro} />
4243
}
4344

45+
const payload = await verifyHeaderCookie()
46+
4447
return (
45-
<PatchContainer patch={patch} intro={intro}>
48+
<PatchContainer patch={patch} intro={intro} uid={payload?.uid}>
4649
{children}
4750
</PatchContainer>
4851
)

components/patch/Container.tsx

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
1-
'use client'
2-
3-
import { Alert, Button } from '@heroui/react'
4-
import { useState } from 'react'
5-
import { PatchHeaderContainer } from '~/components/patch/header/Container'
6-
import { Patch, PatchIntroduction } from '~/types/api/patch'
7-
8-
interface Props {
9-
children: React.ReactNode
10-
patch: Patch
11-
intro: PatchIntroduction
12-
}
13-
14-
export const PatchContainer = ({ children, patch, intro }: Props) => {
15-
const [show, setShow] = useState(false)
16-
17-
if (patch.content_limit === 'nsfw') {
18-
return (
19-
<div className="container py-6 mx-auto space-y-6">
20-
{!show && (
21-
<div className="flex flex-col items-center">
22-
<Alert
23-
color="primary"
24-
title="确认显示"
25-
description="网站目前正在索引中, NSFW 的内容请您点击确定后即可显示"
26-
endContent={
27-
<Button color="primary" onPress={() => setShow(!show)}>
28-
确定
29-
</Button>
30-
}
31-
/>
32-
</div>
33-
)}
34-
35-
{show && (
36-
<>
37-
<PatchHeaderContainer patch={patch} intro={intro} />
38-
{children}
39-
</>
40-
)}
41-
</div>
42-
)
43-
}
44-
45-
return (
46-
<div className="container py-6 mx-auto space-y-6">
47-
<PatchHeaderContainer patch={patch} intro={intro} />
48-
{children}
49-
</div>
50-
)
51-
}
1+
'use client'
2+
3+
import { Alert, Button } from '@heroui/react'
4+
import { useState } from 'react'
5+
import { PatchHeaderContainer } from '~/components/patch/header/Container'
6+
import { Patch, PatchIntroduction } from '~/types/api/patch'
7+
8+
interface Props {
9+
children: React.ReactNode
10+
patch: Patch
11+
intro: PatchIntroduction
12+
uid?: number
13+
}
14+
15+
export const PatchContainer = ({ children, patch, intro, uid }: Props) => {
16+
const [show, setShow] = useState(false)
17+
18+
if (!uid && patch.content_limit === 'nsfw') {
19+
return (
20+
<div className="container py-6 mx-auto space-y-6">
21+
{!show && (
22+
<div className="flex flex-col items-center">
23+
<Alert
24+
color="primary"
25+
title="确认显示"
26+
description="网站目前正在索引中, NSFW 的内容请您点击确定后即可显示"
27+
endContent={
28+
<Button color="primary" onPress={() => setShow(!show)}>
29+
确定
30+
</Button>
31+
}
32+
/>
33+
</div>
34+
)}
35+
36+
{show && (
37+
<>
38+
<PatchHeaderContainer patch={patch} intro={intro} />
39+
{children}
40+
</>
41+
)}
42+
</div>
43+
)
44+
}
45+
46+
return (
47+
<div className="container py-6 mx-auto space-y-6">
48+
<PatchHeaderContainer patch={patch} intro={intro} />
49+
{children}
50+
</div>
51+
)
52+
}

0 commit comments

Comments
 (0)