From f77249408f89187a179f656e9027446b46a858c0 Mon Sep 17 00:00:00 2001 From: srichman333 Date: Tue, 27 Feb 2024 17:37:36 -0500 Subject: pdf summary - generate again bug fix --- src/client/views/pdf/AnchorMenu.tsx | 14 +--- src/client/views/pdf/GPTPopup/GPTPopup.tsx | 101 ++++++++++++++++++++--------- 2 files changed, 72 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx index d0688c338..222cf2f7e 100644 --- a/src/client/views/pdf/AnchorMenu.tsx +++ b/src/client/views/pdf/AnchorMenu.tsx @@ -73,18 +73,8 @@ export class AnchorMenu extends AntimodeMenu { * @param e pointer down event */ gptSummarize = async (e: React.PointerEvent) => { - // move this logic to gptpopup, need to implement generate again - GPTPopup.Instance.setVisible(true); - GPTPopup.Instance.setMode(GPTPopupMode.SUMMARY); - GPTPopup.Instance.setLoading(true); - - try { - const res = await gptAPICall(this.selectedText, GPTCallType.SUMMARY); - GPTPopup.Instance.setText(res || 'Something went wrong.'); - } catch (err) { - console.error(err); - } - GPTPopup.Instance.setLoading(false); + GPTPopup.Instance?.setSelectedText(this.selectedText); + GPTPopup.Instance.generateSummary(); }; pointerDown = (e: React.PointerEvent) => { diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx index a14c659db..8c575748f 100644 --- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx +++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx @@ -10,7 +10,7 @@ import { Utils } from '../../../../Utils'; import { Doc } from '../../../../fields/Doc'; import { NumCast, StrCast } from '../../../../fields/Types'; import { Networking } from '../../../Network'; -import { gptImageCall } from '../../../apis/gpt/GPT'; +import { GPTCallType, gptAPICall, gptImageCall } from '../../../apis/gpt/GPT'; import { DocUtils, Docs } from '../../../documents/Documents'; import { ObservableReactComponent } from '../../ObservableReactComponent'; import { AnchorMenu } from '../AnchorMenu'; @@ -47,6 +47,12 @@ export class GPTPopup extends ObservableReactComponent { public setText = (text: string) => { this.text = text; }; + @observable + public selectedText: string = ''; + @action + public setSelectedText = (text: string) => { + this.selectedText = text; + }; @observable public imgDesc: string = ''; @@ -133,6 +139,20 @@ export class GPTPopup extends ObservableReactComponent { this.setLoading(false); }; + generateSummary = async () => { + GPTPopup.Instance.setVisible(true); + GPTPopup.Instance.setMode(GPTPopupMode.SUMMARY); + GPTPopup.Instance.setLoading(true); + + try { + const res = await gptAPICall(this.selectedText, GPTCallType.SUMMARY); + GPTPopup.Instance.setText(res || 'Something went wrong.'); + } catch (err) { + console.error(err); + } + GPTPopup.Instance.setLoading(false); + } + /** * Transfers the summarization text to a sidebar annotation text document. */ @@ -216,35 +236,59 @@ export class GPTPopup extends ObservableReactComponent { ); }; - data = () => { - return ( -
- {this.heading('GENERATED IMAGE')} -
- {this.imgUrls.map(rawSrc => ( -
-
- dalle generation -
-
-
-
- ))} + summaryBox = () => ( + <> +
+ {this.heading('SUMMARY')} +
+ {!this.loading && + (!this.done ? ( + { + setTimeout(() => { + this.setDone(true); + }, 500); + }, + ]} + /> + ) : ( + this.text + ))}
- {!this.loading && ( - <> - } color={StrCast(Doc.UserDoc().userVariantColor)} /> - - )}
- ); - }; + {!this.loading && ( +
+ {this.done ? ( + <> + } color={StrCast(Doc.UserDoc().userVariantColor)} /> +
+ )} +
+ )} + + ); - summaryBox = () => ( + dataAnalysisBox = () => ( <>
- {this.mode==GPTPopupMode.SUMMARY? this.heading('SUMMARY'): this.heading("ANALYSIS")} + {this.heading("ANALYSIS")}
{!this.loading && (!this.done ? ( @@ -258,7 +302,6 @@ export class GPTPopup extends ObservableReactComponent { }, 500); }, ]} - //cursor={{ hideWhenDone: true }} /> ) : ( this.text @@ -269,10 +312,6 @@ export class GPTPopup extends ObservableReactComponent {
{this.done ? ( <> - {this.mode==GPTPopupMode.SUMMARY? - } color={StrCast(Doc.UserDoc().userVariantColor)} /> - : null } - {/* } color={StrCast(Doc.UserDoc().userVariantColor)} /> */}