Skip to content

Commit b918393

Browse files
committed
feat: comment allowcomment
Signed-off-by: Innei <[email protected]>
1 parent 36c3460 commit b918393

File tree

6 files changed

+40
-8
lines changed

6 files changed

+40
-8
lines changed

src/app/(page-detail)/[slug]/layout.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ export default async (props: NextPageParams<PageParams>) => {
8585

8686
<LayoutRightSideProvider className="absolute bottom-0 right-0 top-0 hidden translate-x-full lg:block" />
8787
</div>
88-
{isCN ? <NotSupport /> : <CommentAreaRoot refId={data.id} />}
88+
{isCN ? (
89+
<NotSupport />
90+
) : (
91+
<CommentAreaRoot refId={data.id} allowComment={data.allowComment} />
92+
)}
8993
</>
9094
)
9195
}

src/app/notes/[id]/layout.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export default async (
7878

7979
const isCN = geo === 'CN'
8080

81+
const { id: noteObjectId, allowComment } = data.data
82+
8183
return (
8284
<>
8385
<CurrentNoteIdProvider noteId={id} />
@@ -86,7 +88,11 @@ export default async (
8688

8789
<BottomToUpTransitionView className="min-w-0">
8890
<Paper as={NoteMainContainer}>{props.children}</Paper>
89-
{isCN ? <NotSupport /> : <CommentAreaRoot refId={data.data.id} />}
91+
{isCN ? (
92+
<NotSupport />
93+
) : (
94+
<CommentAreaRoot refId={noteObjectId} allowComment={allowComment} />
95+
)}
9096
</BottomToUpTransitionView>
9197
</>
9298
)

src/app/posts/(post-detail)/[category]/[slug]/layout.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React from 'react'
2+
import { headers } from 'next/dist/client/components/headers'
23
import { notFound } from 'next/navigation'
34
import type { Metadata } from 'next'
45

56
import { RequestError } from '@mx-space/api-client'
67

8+
import { NotSupport } from '~/components/common/NotSupport'
79
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
10+
import { CommentAreaRoot } from '~/components/widgets/comment'
11+
import { REQUEST_GEO } from '~/constants/system'
812
import { attachUA } from '~/lib/attach-ua'
913
import { getSummaryFromMd } from '~/lib/markdown'
1014
import { CurrentPostDataProvider } from '~/providers/post/CurrentPostDataProvider'
@@ -73,13 +77,23 @@ export default async (props: NextPageParams<PageParams>) => {
7377
}
7478
throw error
7579
})
80+
const header = headers()
81+
const geo = header.get(REQUEST_GEO)
82+
83+
const isCN = geo === 'CN'
7684

7785
return (
7886
<>
7987
<CurrentPostDataProvider data={data} />
8088
<div className="relative flex min-h-[120px] grid-cols-[auto,200px] lg:grid">
8189
<BottomToUpTransitionView className="min-w-0">
8290
{props.children}
91+
92+
{isCN ? (
93+
<NotSupport />
94+
) : (
95+
<CommentAreaRoot refId={data.id} allowComment={data.allowComment} />
96+
)}
8397
</BottomToUpTransitionView>
8498

8599
<LayoutRightSideProvider className="relative hidden lg:block" />

src/app/posts/(post-detail)/[category]/[slug]/page.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { PropsWithChildren } from 'react'
88
import { ClientOnly } from '~/components/common/ClientOnly'
99
import { useSetHeaderMetaInfo } from '~/components/layout/header/hooks'
1010
import { Markdown } from '~/components/ui/markdown'
11-
import { CommentAreaRoot } from '~/components/widgets/comment'
1211
import { PostActionAside } from '~/components/widgets/post/PostActionAside'
1312
import { PostCopyright } from '~/components/widgets/post/PostCopyright'
1413
import { PostMetaBar } from '~/components/widgets/post/PostMetaBar'
@@ -29,6 +28,7 @@ import Loading from './loading'
2928
const PostPage = () => {
3029
const id = useCurrentPostDataSelector((p) => p?.id)
3130
const title = useCurrentPostDataSelector((p) => p?.title)
31+
const allowComment = useCurrentPostDataSelector((p) => p?.allowComment)
3232
if (!id) {
3333
return <Loading />
3434
}
@@ -71,8 +71,6 @@ const PostPage = () => {
7171
<SubscribeBell defaultType="post_c" />
7272
<XLogInfoForPost />
7373
</ClientOnly>
74-
75-
<CommentAreaRoot refId={id} />
7674
</div>
7775
)
7876
}

src/components/widgets/comment/CommentRoot.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ import { CommentBoxRoot } from './CommentBox/Root'
88
import { Comments } from './Comments'
99

1010
const LoadingElement = <Loading loadingText="评论区加载中..." />
11-
export const CommentAreaRoot: FC<CommentBaseProps> = (props) => {
11+
export const CommentAreaRoot: FC<
12+
CommentBaseProps & {
13+
allowComment: boolean
14+
}
15+
> = (props) => {
16+
if (!props.allowComment) {
17+
return (
18+
<p className="mt-[100px] text-center text-xl font-medium">评论已关闭</p>
19+
)
20+
}
21+
1222
return (
1323
<LazyLoad placeholder={LoadingElement}>
1424
<div className="relative mt-12">

tailwind.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ const twConfig: Config = {
244244
{
245245
dark: {
246246
'color-scheme': 'dark',
247-
primary: '#1f8f93',
248-
secondary: '#92bbff',
247+
primary: '#91bef0',
248+
secondary: '#39C5BB',
249249
accent: '#91bef0',
250250

251251
neutral: UIKitColors.grey3.dark,

0 commit comments

Comments
 (0)