send comment over sharejs after thread is created (#14807)

* send comment over sharejs after thread is created

* only react version

* loading gif

GitOrigin-RevId: a6b16a8cae66faa3219f1c9141ee04e303d9f11b
This commit is contained in:
Domagoj Kriskovic 2023-09-20 17:18:06 +02:00 committed by Copybot
parent dbe5c9732b
commit 20f49ae325
3 changed files with 56 additions and 28 deletions

View file

@ -24,16 +24,23 @@ function AddCommentEntry({ entryId }: AddCommentEntryProps) {
useReviewPanelUpdaterFnsContext()
const [content, setContent] = useState('')
const [isSubmitting, setIsSubmiting] = useState(false)
const handleStartNewComment = () => {
setIsAddingComment(true)
handleLayoutChange({ async: true })
}
const handleSubmitNewComment = () => {
submitNewComment(content)
setIsAddingComment(false)
setContent('')
const handleSubmitNewComment = async () => {
setIsSubmiting(true)
try {
await submitNewComment(content)
setIsSubmiting(false)
setIsAddingComment(false)
setContent('')
} catch (err) {
setIsSubmiting(false)
}
handleLayoutChange({ async: true })
}
@ -79,15 +86,21 @@ function AddCommentEntry({ entryId }: AddCommentEntryProps) {
{isAddingComment ? (
<>
<div className="rp-new-comment">
<AutoExpandingTextArea
className="rp-comment-input"
onChange={e => setContent(e.target.value)}
onKeyPress={handleCommentKeyPress}
onResize={handleLayoutChange}
placeholder={t('add_your_comment_here')}
value={content}
autoFocus // eslint-disable-line jsx-a11y/no-autofocus
/>
{isSubmitting ? (
<div className="rp-loading">
<Icon type="spinner" spin />
</div>
) : (
<AutoExpandingTextArea
className="rp-comment-input"
onChange={e => setContent(e.target.value)}
onKeyPress={handleCommentKeyPress}
onResize={handleLayoutChange}
placeholder={t('add_your_comment_here')}
value={content}
autoFocus // eslint-disable-line jsx-a11y/no-autofocus
/>
)}
</div>
<EntryActions>
<EntryActions.Button
@ -98,7 +111,7 @@ function AddCommentEntry({ entryId }: AddCommentEntryProps) {
</EntryActions.Button>
<EntryActions.Button
onClick={handleSubmitNewComment}
disabled={!content.length}
disabled={isSubmitting || !content.length}
>
<Icon type="comment" /> {t('comment')}
</EntryActions.Button>

View file

@ -73,7 +73,7 @@ export interface ReviewPanelState {
unresolveComment: (threadId: ThreadId) => void
deleteThread: (_entryId: unknown, docId: DocId, threadId: ThreadId) => void
refreshResolvedCommentsDropdown: () => Promise<void>
submitNewComment: (content: string) => void
submitNewComment: (content: string) => Promise<void>
setEntryHover: React.Dispatch<React.SetStateAction<Value<'entryHover'>>>
setIsAddingComment: React.Dispatch<
React.SetStateAction<Value<'isAddingComment'>>

View file

@ -818,27 +818,42 @@ export default App.controller(
const thread_id = RangesTracker.generateId()
const thread = getThread(thread_id)
thread.submitting = true
$scope.$broadcast('comment:add', thread_id, offset, length)
dispatchReviewPanelEvent('comment:add', {
threadId: thread_id,
offset,
length,
})
$http
const emitCommentAdd = () => {
$scope.$broadcast('comment:add', thread_id, offset, length)
dispatchReviewPanelEvent('comment:add', {
threadId: thread_id,
offset,
length,
})
// TODO: unused?
$scope.$broadcast('editor:clearSelection')
$timeout(() => ide.$scope.$broadcast('review-panel:layout'))
eventTracking.sendMB('rp-new-comment', { size: content.length })
}
if (ide.$scope.reviewPanel.isReact === false) {
emitCommentAdd()
}
return $http
.post(`/project/${$scope.project_id}/thread/${thread_id}/messages`, {
content,
_csrf: window.csrfToken,
})
.catch(() =>
.then(() => {
if (ide.$scope.reviewPanel.isReact) {
emitCommentAdd()
}
})
.catch(() => {
ide.showGenericMessageModal(
'Error submitting comment',
'Sorry, there was a problem submitting your comment'
)
)
// TODO: unused?
$scope.$broadcast('editor:clearSelection')
$timeout(() => ide.$scope.$broadcast('review-panel:layout'))
eventTracking.sendMB('rp-new-comment', { size: content.length })
throw Error('Error submitting comment')
})
}
$scope.cancelNewComment = entry =>