// Copyright (C) 2020 Intel Corporation // // SPDX-License-Identifier: MIT import React, { useState, useEffect, useRef } from 'react'; import ReactDOM from 'react-dom'; import { Row, Col } from 'antd/lib/grid'; import Comment from 'antd/lib/comment'; import Text from 'antd/lib/typography/Text'; import Title from 'antd/lib/typography/Title'; import Tooltip from 'antd/lib/tooltip'; import Button from 'antd/lib/button'; import Input from 'antd/lib/input'; import Icon from 'antd/lib/icon'; import moment from 'moment'; interface Props { id: number; comments: any[]; left: number; top: number; resolved: boolean; isFetching: boolean; collapse: () => void; resolve: () => void; reopen: () => void; comment: (message: string) => void; highlight: () => void; blur: () => void; } export default function IssueDialog(props: Props): JSX.Element { const ref = useRef(null); const [currentText, setCurrentText] = useState(''); const { comments, id, left, top, resolved, isFetching, collapse, resolve, reopen, comment, highlight, blur, } = props; useEffect(() => { if (!resolved) { setTimeout(highlight); } else { setTimeout(blur); } }, [resolved]); const lines = comments.map( (_comment: any): JSX.Element => { const created = _comment.createdDate ? moment(_comment.createdDate) : moment(moment.now()); const diff = created.fromNow(); return ( {_comment.author ? _comment.author.username : 'Unknown'}} content={

{_comment.message}

} datetime={( {diff} )} /> ); }, ); const resolveButton = resolved ? ( ) : ( ); return ReactDOM.createPortal(
{id >= 0 ? `Issue #${id}` : 'Issue'} {lines} ) => { setCurrentText(event.target.value); }} onPressEnter={() => { if (currentText) { comment(currentText); setCurrentText(''); } }} /> {currentText.length ? ( ) : ( resolveButton )}
, window.document.getElementById('cvat_canvas_attachment_board') as HTMLElement, ); }