File tree 13 files changed +93
-44
lines changed
posts/(post-detail)/[category]/[slug]
13 files changed +93
-44
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { RequestError } from '@mx-space/api-client'
7
7
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
8
8
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
9
9
import { OnlyMobile } from '~/components/ui/viewport/OnlyMobile'
10
- import { CommentAreaRoot } from '~/components/widgets/comment/CommentRoot '
10
+ import { CommentAreaRootLazy } from '~/components/widgets/comment'
11
11
import { TocFAB } from '~/components/widgets/toc/TocFAB'
12
12
import { attachUA } from '~/lib/attach-ua'
13
13
import { getSummaryFromMd } from '~/lib/markdown'
@@ -115,7 +115,7 @@ export default async (props: NextPageParams<PageParams>) => {
115
115
< LayoutRightSideProvider className = "absolute bottom-0 right-0 top-0 hidden translate-x-full lg:block" />
116
116
</ div >
117
117
< BottomToUpSoftScaleTransitionView delay = { 1000 } >
118
- < CommentAreaRoot refId = { data . id } allowComment = { data . allowComment } />
118
+ < CommentAreaRootLazy refId = { data . id } allowComment = { data . allowComment } />
119
119
</ BottomToUpSoftScaleTransitionView >
120
120
121
121
< OnlyMobile >
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import type { Metadata } from 'next'
3
3
4
4
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
5
5
import { OnlyMobile } from '~/components/ui/viewport/OnlyMobile'
6
- import { CommentAreaRoot } from '~/components/widgets/comment'
6
+ import { CommentAreaRootLazy } from '~/components/widgets/comment'
7
7
import { NoteMainContainer } from '~/components/widgets/note/NoteMainContainer'
8
8
import { TocFAB } from '~/components/widgets/toc/TocFAB'
9
9
import { REQUEST_QUERY } from '~/constants/system'
@@ -88,7 +88,10 @@ export default async (
88
88
< Transition className = "min-w-0" >
89
89
< Paper as = { NoteMainContainer } > { props . children } </ Paper >
90
90
< BottomToUpSoftScaleTransitionView delay = { 500 } >
91
- < CommentAreaRoot refId = { noteObjectId } allowComment = { allowComment } />
91
+ < CommentAreaRootLazy
92
+ refId = { noteObjectId }
93
+ allowComment = { allowComment }
94
+ />
92
95
</ BottomToUpSoftScaleTransitionView >
93
96
</ Transition >
94
97
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { RequestError } from '@mx-space/api-client'
7
7
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
8
8
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView'
9
9
import { OnlyMobile } from '~/components/ui/viewport/OnlyMobile'
10
- import { CommentAreaRoot } from '~/components/widgets/comment'
10
+ import { CommentAreaRootLazy } from '~/components/widgets/comment'
11
11
import { TocFAB } from '~/components/widgets/toc/TocFAB'
12
12
import { attachUA } from '~/lib/attach-ua'
13
13
import { getSummaryFromMd } from '~/lib/markdown'
@@ -86,7 +86,10 @@ export default async (props: NextPageParams<PageParams>) => {
86
86
{ props . children }
87
87
88
88
< BottomToUpSoftScaleTransitionView delay = { 500 } >
89
- < CommentAreaRoot refId = { data . id } allowComment = { data . allowComment } />
89
+ < CommentAreaRootLazy
90
+ refId = { data . id }
91
+ allowComment = { data . allowComment }
92
+ />
90
93
</ BottomToUpSoftScaleTransitionView >
91
94
</ BottomToUpTransitionView >
92
95
Original file line number Diff line number Diff line change @@ -22,8 +22,7 @@ import { TextArea } from '~/components/ui/input'
22
22
import { Loading } from '~/components/ui/loading'
23
23
import { Markdown } from '~/components/ui/markdown'
24
24
import { RelativeTime } from '~/components/ui/relative-time'
25
- import { CommentBoxRoot } from '~/components/widgets/comment/CommentBox'
26
- import { Comments } from '~/components/widgets/comment/Comments'
25
+ import { CommentBoxRootLazy , CommentsLazy } from '~/components/widgets/comment'
27
26
import { PeekLink } from '~/components/widgets/peek/PeekLink'
28
27
import { LoadMoreIndicator } from '~/components/widgets/shared/LoadMoreIndicator'
29
28
import { usePrevious } from '~/hooks/common/use-previous'
@@ -348,16 +347,16 @@ const CommentModal = (props: RecentlyModel) => {
348
347
const { id, allowComment, content } = props
349
348
350
349
return (
351
- < div className = "max-w-95vw w-[700px] overflow-y-auto overflow-x-hidden" >
350
+ < div className = "max-w-95vw overflow-y-auto overflow-x-hidden md:w-[500px] lg:w-[600px] xl:w-[700px] " >
352
351
< span > { allowComment && '回复:' } </ span >
353
352
354
353
< Markdown className = "mt-4" allowsScript >
355
354
{ content }
356
355
</ Markdown >
357
356
358
- { allowComment && < CommentBoxRoot className = "my-12" refId = { id } /> }
357
+ { allowComment && < CommentBoxRootLazy className = "my-12" refId = { id } /> }
359
358
360
- < Comments refId = { id } />
359
+ < CommentsLazy refId = { id } />
361
360
</ div >
362
361
)
363
362
}
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export const Comment: Component<{
39
39
< li
40
40
data-comment-id = { cid }
41
41
data-parent-id = { parentId }
42
- className = { clsx ( 'relative' , className ) }
42
+ className = { clsx ( 'relative my-2 ' , className ) }
43
43
>
44
44
< div className = "group flex w-full items-stretch gap-2" >
45
45
< div className = "flex w-9 shrink-0 items-end" >
Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ import type { FC } from 'react'
4
4
5
5
import { AutoResizeHeight } from '~/components/widgets/shared/AutoResizeHeight'
6
6
7
+ import { CommentBoxRootLazy } from '.'
7
8
import { CommentBoxHolderPortal } from './Comment'
8
9
import { useCommentBoxRefIdValue } from './CommentBox/hooks'
9
10
import { CommentIsReplyProvider } from './CommentBox/providers'
10
- import { CommentBoxRoot } from './CommentBox/Root'
11
11
12
12
export const CommentReplyButton : FC < {
13
13
commentId : string
@@ -45,7 +45,7 @@ export const CommentReplyButton: FC<{
45
45
{ replyFormOpen && (
46
46
< >
47
47
< div className = "h-6" />
48
- < CommentBoxRoot refId = { commentId } />
48
+ < CommentBoxRootLazy refId = { commentId } />
49
49
< div className = "h-6" />
50
50
</ >
51
51
) }
Original file line number Diff line number Diff line change 1
1
import type { FC } from 'react'
2
2
import type { CommentBaseProps } from './types'
3
3
4
- import { LazyLoad } from '~/components/common/Lazyload'
5
- import { Loading } from '~/components/ui/loading'
6
-
7
4
import { CommentBoxRoot } from './CommentBox/Root'
8
5
import { Comments } from './Comments'
9
6
10
- const LoadingElement = < Loading loadingText = "评论区加载中..." />
11
7
export const CommentAreaRoot : FC <
12
8
CommentBaseProps & {
13
9
allowComment : boolean
@@ -29,13 +25,11 @@ export const CommentAreaRoot: FC<
29
25
}
30
26
31
27
return (
32
- < LazyLoad placeholder = { LoadingElement } >
33
- < div className = "relative mt-12" >
34
- < CommentBoxRoot refId = { refId } />
28
+ < div className = "relative mt-12" >
29
+ < CommentBoxRoot refId = { refId } />
35
30
36
- < div className = "h-12" />
37
- < Comments refId = { refId } />
38
- </ div >
39
- </ LazyLoad >
31
+ < div className = "h-12" />
32
+ < Comments refId = { refId } />
33
+ </ div >
40
34
)
41
35
}
Original file line number Diff line number Diff line change
1
+ 'use client'
2
+
3
+ import dynamic from 'next/dynamic'
4
+
5
+ import { LazyLoad } from '~/components/common/Lazyload'
6
+ import { Loading } from '~/components/ui/loading'
7
+
8
+ const LoadingElement = < Loading loadingText = "评论区加载中..." />
9
+
10
+ const CommentAreaRoot = dynamic (
11
+ ( ) => import ( './CommentRoot' ) . then ( ( mod ) => mod . CommentAreaRoot ) ,
12
+ {
13
+ ssr : false ,
14
+ loading : ( ) => LoadingElement ,
15
+ } ,
16
+ )
17
+
18
+ export const CommentAreaRootLazy : typeof CommentAreaRoot = ( props ) => {
19
+ return (
20
+ < LazyLoad placeholder = { LoadingElement } >
21
+ < CommentAreaRoot { ...props } />
22
+ </ LazyLoad >
23
+ )
24
+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import type { FC } from 'react'
6
6
import type { CommentBaseProps } from './types'
7
7
8
8
import { NotSupport } from '~/components/common/NotSupport'
9
+ import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView'
9
10
import { apiClient } from '~/lib/request'
10
11
11
12
import { LoadMoreIndicator } from '../shared/LoadMoreIndicator'
@@ -52,18 +53,22 @@ export const Comments: FC<CommentBaseProps> = ({ refId }) => {
52
53
return (
53
54
< >
54
55
< ul className = "min-h-[400px] list-none space-y-4" >
55
- { data ?. pages . map ( ( data ) =>
56
- data . data . map ( ( comment , index ) => {
57
- return (
58
- < CommentListItem
59
- comment = { comment }
60
- key = { comment . id }
61
- refId = { refId }
62
- index = { index }
63
- />
64
- )
65
- } ) ,
66
- ) }
56
+ { data ?. pages . map ( ( data , index ) => {
57
+ return (
58
+ < BottomToUpSoftScaleTransitionView key = { index } >
59
+ { data . data . map ( ( comment , index ) => {
60
+ return (
61
+ < CommentListItem
62
+ comment = { comment }
63
+ key = { comment . id }
64
+ refId = { refId }
65
+ index = { index }
66
+ />
67
+ )
68
+ } ) }
69
+ </ BottomToUpSoftScaleTransitionView >
70
+ )
71
+ } ) }
67
72
</ ul >
68
73
{ hasNextPage && (
69
74
< LoadMoreIndicator onLoading = { fetchNextPage } >
Original file line number Diff line number Diff line change 1
- export { CommentAreaRoot } from './CommentRoot'
1
+ import { createElement } from 'react'
2
+ import dynamic from 'next/dynamic'
3
+
4
+ import { Loading } from '~/components/ui/loading'
5
+
6
+ export const CommentsLazy = dynamic (
7
+ ( ) => import ( './Comments' ) . then ( ( mod ) => mod . Comments ) ,
8
+ { ssr : false } ,
9
+ )
10
+ export const CommentBoxRootLazy = dynamic (
11
+ ( ) => import ( './CommentBox' ) . then ( ( mod ) => mod . CommentBoxRoot ) ,
12
+ {
13
+ ssr : false ,
14
+ loading : ( ) => createElement ( Loading , { useDefaultLoadingText : true } ) ,
15
+ } ,
16
+ )
17
+
18
+ // export { CommentAreaRoot } from './CommentRoot'
19
+ export { CommentAreaRootLazy } from './CommentRootLazy'
20
+
21
+ // export { Comments } from './Comments'
22
+ // export { CommentBoxRoot } from './CommentBox'
Original file line number Diff line number Diff line change 1
1
import type { ModalContentComponent } from '~/providers/root/modal-stack-provider'
2
2
3
- import { CommentBoxRoot } from '../comment/CommentBox'
4
- import { Comments } from '../comment/Comments'
3
+ import { CommentBoxRootLazy , CommentsLazy } from '../comment'
5
4
6
5
export interface CommentModalProps {
7
6
title : string
@@ -16,19 +15,19 @@ export const CommentModal: ModalContentComponent<CommentModalProps> = (
16
15
const { refId, title, dismiss, initialValue } = props
17
16
18
17
return (
19
- < div className = "max-w-95vw w-[700px] overflow-y-auto overflow-x-hidden" >
18
+ < div className = "max-w-95vw overflow-y-auto overflow-x-hidden md:w-[500px] lg:w-[600px] xl:w-[700px] " >
20
19
< span >
21
20
回复: < h1 className = "mt-4 text-lg font-medium" > { title } </ h1 >
22
21
</ span >
23
22
24
- < CommentBoxRoot
23
+ < CommentBoxRootLazy
25
24
initialValue = { initialValue }
26
25
className = "my-12"
27
26
refId = { refId }
28
27
afterSubmit = { dismiss }
29
28
/>
30
29
31
- < Comments refId = { refId } />
30
+ < CommentsLazy refId = { refId } />
32
31
</ div >
33
32
)
34
33
}
Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ export const WithArticleSelectionAction: Component<{
104
104
onClick = { ( ) => {
105
105
present ( {
106
106
title : '评论' ,
107
+
107
108
content : ( rest ) => (
108
109
< CommentModal
109
110
refId = { refId }
Original file line number Diff line number Diff line change @@ -219,7 +219,7 @@ const Modal: Component<{
219
219
'relative flex flex-col overflow-hidden rounded-lg' ,
220
220
'bg-slate-50/80 dark:bg-neutral-900/80' ,
221
221
'p-2 shadow-2xl shadow-stone-300 backdrop-blur-sm dark:shadow-stone-800' ,
222
- 'max-h-[70vh] min-w-[300px] max-w-[90vw] lg:max-h-[calc(100vh-20rem)] lg:max-w-[50vw ]' ,
222
+ 'max-h-[70vh] min-w-[300px] max-w-[90vw] lg:max-h-[calc(100vh-20rem)] lg:max-w-[70vw ]' ,
223
223
'border border-slate-200 dark:border-neutral-800' ,
224
224
modalClassName ,
225
225
) }
You can’t perform that action at this time.
0 commit comments