2024-10-10 09:01:30 -04:00
|
|
|
import { memo, useCallback } from 'react'
|
2024-08-19 09:16:56 -04:00
|
|
|
import { Change, CommentOperation } from '../../../../../types/change'
|
|
|
|
import { ReviewPanelMessage } from './review-panel-message'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-10-10 09:01:30 -04:00
|
|
|
import { useThreadsContext } from '../context/threads-context'
|
2024-08-19 09:16:56 -04:00
|
|
|
import AutoExpandingTextArea from '@/shared/components/auto-expanding-text-area'
|
|
|
|
import ReviewPanelResolvedMessage from './review-panel-resolved-message'
|
|
|
|
import { ReviewPanelResolvedCommentThread } from '../../../../../types/review-panel/comment-thread'
|
2024-09-16 04:40:59 -04:00
|
|
|
import useSubmittableTextInput from '../hooks/use-submittable-text-input'
|
2024-10-21 04:58:39 -04:00
|
|
|
import {
|
|
|
|
CommentId,
|
|
|
|
ThreadId,
|
|
|
|
} from '../../../../../types/review-panel/review-panel'
|
2024-08-19 09:16:56 -04:00
|
|
|
|
|
|
|
export const ReviewPanelCommentContent = memo<{
|
|
|
|
comment: Change<CommentOperation>
|
|
|
|
isResolved: boolean
|
2024-10-10 09:01:30 -04:00
|
|
|
onEdit?: (commentId: CommentId, content: string) => Promise<void>
|
|
|
|
onReply?: (content: string) => Promise<void>
|
2024-10-21 04:58:39 -04:00
|
|
|
onDeleteMessage?: (commentId: CommentId) => Promise<void>
|
|
|
|
onDeleteThread?: (threadId: ThreadId) => Promise<void>
|
2024-10-10 09:01:30 -04:00
|
|
|
onResolve?: () => Promise<void>
|
2024-10-02 07:58:46 -04:00
|
|
|
onLeave?: () => void
|
|
|
|
onEnter?: () => void
|
2024-10-10 09:01:30 -04:00
|
|
|
}>(
|
|
|
|
({
|
|
|
|
comment,
|
|
|
|
isResolved,
|
|
|
|
onResolve,
|
2024-10-21 04:58:39 -04:00
|
|
|
onDeleteMessage,
|
|
|
|
onDeleteThread,
|
2024-10-10 09:01:30 -04:00
|
|
|
onEdit,
|
|
|
|
onReply,
|
|
|
|
onLeave,
|
|
|
|
onEnter,
|
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const threads = useThreadsContext()
|
2024-08-19 09:16:56 -04:00
|
|
|
|
2024-10-10 09:01:30 -04:00
|
|
|
const handleSubmit = useCallback(
|
|
|
|
(content, setContent) => onReply?.(content).then(() => setContent('')),
|
|
|
|
[onReply]
|
|
|
|
)
|
2024-08-19 09:16:56 -04:00
|
|
|
|
2024-10-10 09:01:30 -04:00
|
|
|
const { handleChange, handleKeyPress, content } =
|
|
|
|
useSubmittableTextInput(handleSubmit)
|
2024-08-19 09:16:56 -04:00
|
|
|
|
2024-10-10 09:01:30 -04:00
|
|
|
const thread = threads?.[comment.op.t]
|
|
|
|
if (!thread) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="review-panel-entry-content"
|
|
|
|
onMouseEnter={onEnter}
|
|
|
|
onMouseLeave={onLeave}
|
|
|
|
>
|
|
|
|
{thread.messages.map((message, i) => {
|
|
|
|
const isReply = i !== 0
|
2024-08-19 09:16:56 -04:00
|
|
|
|
2024-10-10 09:01:30 -04:00
|
|
|
return (
|
|
|
|
<div key={message.id} className="review-panel-comment-wrapper">
|
|
|
|
{isReply && (
|
|
|
|
<div className="review-panel-comment-reply-divider" />
|
|
|
|
)}
|
|
|
|
<ReviewPanelMessage
|
|
|
|
message={message}
|
|
|
|
isReply={isReply}
|
|
|
|
hasReplies={!isReply && thread.messages.length > 1}
|
|
|
|
onResolve={onResolve}
|
|
|
|
onEdit={onEdit}
|
2024-10-21 04:58:39 -04:00
|
|
|
onDelete={() =>
|
|
|
|
isReply
|
|
|
|
? onDeleteMessage?.(message.id)
|
|
|
|
: onDeleteThread?.(comment.op.t)
|
|
|
|
}
|
2024-10-10 09:01:30 -04:00
|
|
|
isThreadResolved={isResolved}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})}
|
2024-08-19 09:16:56 -04:00
|
|
|
|
2024-10-10 09:01:30 -04:00
|
|
|
{isResolved && (
|
|
|
|
<div className="review-panel-comment-wrapper">
|
|
|
|
<div className="review-panel-comment-reply-divider" />
|
|
|
|
<ReviewPanelResolvedMessage
|
|
|
|
thread={thread as ReviewPanelResolvedCommentThread}
|
2024-08-19 09:16:56 -04:00
|
|
|
/>
|
|
|
|
</div>
|
2024-10-10 09:01:30 -04:00
|
|
|
)}
|
2024-08-19 09:16:56 -04:00
|
|
|
|
2024-10-10 09:01:30 -04:00
|
|
|
{!isResolved && (
|
|
|
|
<AutoExpandingTextArea
|
|
|
|
name="content"
|
|
|
|
className="review-panel-comment-input"
|
|
|
|
onChange={handleChange}
|
|
|
|
onKeyDown={handleKeyPress}
|
|
|
|
placeholder={t('reply')}
|
|
|
|
value={content}
|
2024-08-19 09:16:56 -04:00
|
|
|
/>
|
2024-10-10 09:01:30 -04:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2024-08-19 09:16:56 -04:00
|
|
|
ReviewPanelCommentContent.displayName = 'ReviewPanelCommentContent'
|