@@ -22,12 +22,14 @@ import {
22
22
CommentInlineHighlightSpan ,
23
23
type CommentMessage ,
24
24
type CommentsTextSelectionItem ,
25
+ type CommentsUIMode ,
25
26
type CommentUpdatePayload ,
26
27
isTextSelectionComment ,
27
28
useComments ,
28
29
useCommentsEnabled ,
29
30
useCommentsScroll ,
30
31
useCommentsSelectedPath ,
32
+ useCommentsUpsell ,
31
33
} from '../../../src'
32
34
import { getSelectionBoundingRect , useAuthoringReferenceElement } from '../helpers'
33
35
import { FloatingButtonPopover } from './FloatingButtonPopover'
@@ -47,22 +49,25 @@ export function CommentsPortableTextInput(props: PortableTextInputProps) {
47
49
// Therefore we disable the comments for the AI assist type.
48
50
const isAiAssist = props . schemaType . name === AI_ASSIST_TYPE
49
51
50
- if ( ! enabled || mode === 'upsell' || isAiAssist ) {
52
+ if ( ! enabled || isAiAssist ) {
51
53
return props . renderDefault ( props )
52
54
}
53
55
54
- return < CommentsPortableTextInputInner { ...props } />
56
+ return < CommentsPortableTextInputInner { ...props } mode = { mode } />
55
57
}
56
58
57
59
export const CommentsPortableTextInputInner = React . memo ( function CommentsPortableTextInputInner (
58
- props : PortableTextInputProps ,
60
+ props : PortableTextInputProps & { mode : CommentsUIMode } ,
59
61
) {
62
+ const { mode} = props
60
63
const currentUser = useCurrentUser ( )
61
64
const portal = usePortal ( )
62
65
63
- const { mentionOptions, comments, operation, onCommentsOpen, getComment} = useComments ( )
66
+ const { mentionOptions, comments, operation, onCommentsOpen, getComment, setStatus, status} =
67
+ useComments ( )
64
68
const { setSelectedPath, selectedPath} = useCommentsSelectedPath ( )
65
69
const { scrollToComment, scrollToGroup} = useCommentsScroll ( )
70
+ const { handleOpenDialog} = useCommentsUpsell ( )
66
71
67
72
const editorRef = useRef < PortableTextEditor | null > ( null )
68
73
const mouseDownRef = useRef < boolean > ( false )
@@ -100,8 +105,15 @@ export const CommentsPortableTextInputInner = React.memo(function CommentsPortab
100
105
// Set the next comment selection to the current selection so that we can
101
106
// render the comment input popover on the current selection using a range decoration.
102
107
const handleSelectCurrentSelection = useCallback ( ( ) => {
108
+ // When trying to add a comment in "upsell" mode, we want to
109
+ // display the upsell dialog instead of the comment input popover.
110
+ if ( mode === 'upsell' ) {
111
+ handleOpenDialog ( 'pte' )
112
+ return
113
+ }
114
+
103
115
setNextCommentSelection ( currentSelection )
104
- } , [ currentSelection ] )
116
+ } , [ currentSelection , handleOpenDialog , mode ] )
105
117
106
118
// Clear the selection and close the popover when discarding the comment
107
119
const handleCommentDiscardConfirm = useCallback ( ( ) => {
@@ -125,12 +137,15 @@ export const CommentsPortableTextInputInner = React.memo(function CommentsPortab
125
137
126
138
const fragment = getFragment ( ) || EMPTY_ARRAY
127
139
const editorValue = PortableTextEditor . getValue ( editorRef . current )
140
+
128
141
if ( ! editorValue ) return
142
+
129
143
const textSelection = buildTextSelectionFromFragment ( {
130
144
fragment,
131
145
selection : nextCommentSelection ,
132
146
value : editorValue ,
133
147
} )
148
+
134
149
const threadId = uuid ( )
135
150
136
151
operation . create ( {
@@ -145,27 +160,37 @@ export const CommentsPortableTextInputInner = React.memo(function CommentsPortab
145
160
threadId,
146
161
} )
147
162
163
+ // Open the inspector when a new comment is added
148
164
onCommentsOpen ?.( )
149
165
166
+ // Set the status to 'open' so that the comment is visible
167
+ if ( status === 'resolved' ) {
168
+ setStatus ( 'open' )
169
+ }
170
+
171
+ // Set the selected path to the new comment
150
172
setSelectedPath ( {
151
173
fieldPath : stringFieldPath ,
152
174
threadId,
153
175
origin : 'form' ,
154
176
} )
155
177
178
+ // Scroll to the comment
156
179
scrollToGroup ( threadId )
157
180
158
181
resetStates ( )
159
182
} , [
160
- resetStates ,
161
- getFragment ,
162
183
nextCommentSelection ,
184
+ getFragment ,
185
+ operation ,
186
+ stringFieldPath ,
163
187
nextCommentValue ,
164
188
onCommentsOpen ,
165
- operation ,
166
- scrollToGroup ,
189
+ status ,
167
190
setSelectedPath ,
168
- stringFieldPath ,
191
+ scrollToGroup ,
192
+ resetStates ,
193
+ setStatus ,
169
194
] )
170
195
171
196
const handleDecoratorClick = useCallback (
0 commit comments