import { css } from '@emotion/css'; import React, { FormEvent, useLayoutEffect, useRef, useState } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { CustomScrollbar, TextArea, useStyles2 } from '@grafana/ui'; import { Comment } from './Comment'; import { Message } from './types'; type Props = { comments: Message[]; packetCounter: number; addComment: (comment: string) => Promise; }; export const CommentView = ({ comments, packetCounter, addComment }: Props) => { const styles = useStyles2(getStyles); const [comment, setComment] = useState(''); const [scrollTop, setScrollTop] = useState(0); const commentViewContainer = useRef(null); useLayoutEffect(() => { if (commentViewContainer.current) { setScrollTop(commentViewContainer.current.offsetHeight); } else { setScrollTop(0); } }, [packetCounter]); const onUpdateComment = (event: FormEvent) => { const element = event.target as HTMLInputElement; setComment(element.value); }; const onKeyPress = async (event: React.KeyboardEvent) => { if (event?.key === 'Enter' && !event?.shiftKey) { event.preventDefault(); if (comment.length > 0) { const result = await addComment(comment); if (result) { setComment(''); } } } }; return (
{comments.map((msg) => ( ))}