|
|
@@ -1,49 +1,16 @@
|
|
|
-import { memo, useCallback, useState } from 'react'
|
|
|
+import { memo } from 'react'
|
|
|
import { Change, CommentOperation } from '../../../../../types/change'
|
|
|
-import { ReviewPanelMessage } from './review-panel-message'
|
|
|
-import { useTranslation } from 'react-i18next'
|
|
|
-import {
|
|
|
- useThreadsActionsContext,
|
|
|
- useThreadsContext,
|
|
|
-} from '../context/threads-context'
|
|
|
+import { useThreadsContext } from '../context/threads-context'
|
|
|
import classnames from 'classnames'
|
|
|
-import AutoExpandingTextArea from '@/shared/components/auto-expanding-text-area'
|
|
|
-import MaterialIcon from '@/shared/components/material-icon'
|
|
|
import { ReviewPanelEntry } from './review-panel-entry'
|
|
|
+import MaterialIcon from '@/shared/components/material-icon'
|
|
|
+import { ReviewPanelCommentContent } from './review-panel-comment-content'
|
|
|
|
|
|
export const ReviewPanelComment = memo<{
|
|
|
comment: Change<CommentOperation>
|
|
|
top?: number
|
|
|
}>(({ comment, top }) => {
|
|
|
- const { t } = useTranslation()
|
|
|
- const [submitting, setSubmitting] = useState(false)
|
|
|
- const [error, setError] = useState<Error>()
|
|
|
- const [content, setContent] = useState('')
|
|
|
const threads = useThreadsContext()
|
|
|
- const { resolveThread, addMessage } = useThreadsActionsContext()
|
|
|
-
|
|
|
- const handleSubmitReply = useCallback(() => {
|
|
|
- setSubmitting(true)
|
|
|
- addMessage(comment.op.t, content)
|
|
|
- .then(() => {
|
|
|
- setContent('')
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- setError(error)
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
- setSubmitting(false)
|
|
|
- })
|
|
|
- }, [addMessage, comment.op.t, content])
|
|
|
-
|
|
|
- const handleCommentReplyKeyPress = (
|
|
|
- e: React.KeyboardEvent<HTMLTextAreaElement>
|
|
|
- ) => {
|
|
|
- if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
|
|
|
- e.preventDefault()
|
|
|
- handleSubmitReply()
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
const thread = threads?.[comment.op.t]
|
|
|
if (!thread || thread.resolved) {
|
|
|
@@ -62,40 +29,7 @@ export const ReviewPanelComment = memo<{
|
|
|
<div className="review-panel-entry-indicator">
|
|
|
<MaterialIcon type="edit" className="review-panel-entry-icon" />
|
|
|
</div>
|
|
|
-
|
|
|
- <div className="review-panel-entry-content">
|
|
|
- {thread.messages.map((message, i) => {
|
|
|
- const isReply = i !== 0
|
|
|
-
|
|
|
- return (
|
|
|
- <div key={message.id} className="review-panel-comment-wrapper">
|
|
|
- {isReply && (
|
|
|
- <div className="review-panel-comment-reply-divider" />
|
|
|
- )}
|
|
|
-
|
|
|
- <ReviewPanelMessage
|
|
|
- message={message}
|
|
|
- threadId={comment.op.t}
|
|
|
- isReply={isReply}
|
|
|
- hasReplies={!isReply && thread.messages.length > 1}
|
|
|
- onResolve={() => resolveThread(comment.op.t)}
|
|
|
- />
|
|
|
- </div>
|
|
|
- )
|
|
|
- })}
|
|
|
-
|
|
|
- <AutoExpandingTextArea
|
|
|
- name="content"
|
|
|
- className="review-panel-comment-input"
|
|
|
- onChange={e => setContent(e.target.value)}
|
|
|
- onKeyDown={handleCommentReplyKeyPress}
|
|
|
- placeholder={t('reply')}
|
|
|
- value={content}
|
|
|
- disabled={submitting}
|
|
|
- />
|
|
|
-
|
|
|
- {error && <div>{error.message}</div>}
|
|
|
- </div>
|
|
|
+ <ReviewPanelCommentContent comment={comment} isResolved={false} />
|
|
|
</ReviewPanelEntry>
|
|
|
)
|
|
|
})
|