import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { action, observable } from 'mobx'; import { observer } from 'mobx-react'; import React = require('react'); import ReactLoading from 'react-loading'; import Typist from 'react-typist'; import { Doc } from '../../../fields/Doc'; import { Docs } from '../../documents/Documents'; import './GPTPopup.scss'; interface GPTPopupProps { visible: boolean; text: string; loadingSummary: boolean; callApi: (e: React.PointerEvent) => Promise; } @observer export class GPTPopup extends React.Component { static Instance: GPTPopup; @observable private summaryDone: boolean = false; @observable private sidebarId: string = ''; @action public setSummaryDone = (done: boolean) => { this.summaryDone = done; }; @action public setSidebarId = (id: string) => { this.sidebarId = id; }; public addDoc: (doc: Doc | Doc[], sidebarKey?: string | undefined) => boolean = () => false; /** * Transfers the summarization text to a sidebar annotation text document. */ private transferToText = () => { const newDoc = Docs.Create.TextDocument(this.props.text.trim(), { _width: 200, _height: 50, _fitWidth: true, _autoHeight: true, }); this.addDoc(newDoc, this.sidebarId); }; constructor(props: GPTPopupProps) { super(props); GPTPopup.Instance = this; } componentDidUpdate = () => { if (this.props.loadingSummary) { this.setSummaryDone(false); } }; render() { return (
{this.props.loadingSummary && }
{!this.props.loadingSummary && (!this.summaryDone ? ( { setTimeout( action(() => { this.summaryDone = true; }), 500 ); })}> {this.props.text} ) : ( this.props.text ))}
{!this.props.loadingSummary && (
{this.summaryDone ? ( <> ) : (
)}
)} {this.summaryDone && (
AI generated responses can contain inaccurate or misleading content.{' '} Learn More
)}
); } }