diff options
| author | bobzel <zzzman@gmail.com> | 2024-05-19 01:01:02 -0400 |
|---|---|---|
| committer | bobzel <zzzman@gmail.com> | 2024-05-19 01:01:02 -0400 |
| commit | 6e72f969029c22fe797397a6437836a0482260b6 (patch) | |
| tree | e8ccde75702e557b2226c9069263e1bc3bd21a4b /src/client/views/pdf/AnchorMenu.tsx | |
| parent | 5ff0bef5d3c4825aa7210a26c98aae3b24f4a835 (diff) | |
| parent | 13dc6de0e0099f699ad0d2bb54401e6a0aa25018 (diff) | |
Merge branch 'restoringEslint' into alyssa-starter
Diffstat (limited to 'src/client/views/pdf/AnchorMenu.tsx')
| -rw-r--r-- | src/client/views/pdf/AnchorMenu.tsx | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx index a0c3cf487..b7247a034 100644 --- a/src/client/views/pdf/AnchorMenu.tsx +++ b/src/client/views/pdf/AnchorMenu.tsx @@ -4,21 +4,22 @@ import { IReactionDisposer, ObservableMap, action, computed, makeObservable, obs import { observer } from 'mobx-react'; import * as React from 'react'; import { ColorResult } from 'react-color'; -import { Utils, returnFalse, setupMoveUpEvents, unimplementedFunction } from '../../../Utils'; +import { ClientUtils, returnFalse, setupMoveUpEvents } from '../../../ClientUtils'; +import { emptyFunction, unimplementedFunction } from '../../../Utils'; import { Doc, Opt } from '../../../fields/Doc'; -import { DocUtils, Docs } from '../../documents/Documents'; -import { GPTCallType, gptAPICall } from '../../apis/gpt/GPT'; -import { DocumentType } from '../../documents/DocumentTypes'; -import { SelectionManager } from '../../util/SelectionManager'; +import { gptAPICall } from '../../apis/gpt/GPT'; +import { GPTCallType } from '../../apis/gpt/setup'; import { SettingsManager } from '../../util/SettingsManager'; import { AntimodeMenu, AntimodeMenuProps } from '../AntimodeMenu'; import { LinkPopup } from '../linking/LinkPopup'; +import { DocumentView } from '../nodes/DocumentView'; import './AnchorMenu.scss'; import { GPTPopup, GPTPopupMode } from './GPTPopup/GPTPopup'; -import { PDFViewer } from 'pdfjs-dist/web/pdf_viewer.mjs'; +import { Docs } from '../../documents/Documents'; @observer export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { + // eslint-disable-next-line no-use-before-define static Instance: AnchorMenu; private _disposer: IReactionDisposer | undefined; @@ -37,9 +38,11 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { @observable public Status: 'marquee' | 'annotation' | '' = ''; // GPT additions - @observable private selectedText: string = ''; + @observable private _selectedText: string = ''; @action - public setSelectedText = (txt: string) => (this.selectedText = txt); + public setSelectedText = (txt: string) => { + this._selectedText = txt.trim(); + }; public onMakeAnchor: () => Opt<Doc> = () => undefined; // Method to get anchor from text search @@ -48,8 +51,8 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { public OnAudio: (e: PointerEvent) => void = unimplementedFunction; public StartDrag: (e: PointerEvent, ele: HTMLElement) => void = unimplementedFunction; public StartCropDrag: (e: PointerEvent, ele: HTMLElement) => void = unimplementedFunction; - public Highlight: (color: string, isTargetToggler: boolean, savedAnnotations?: ObservableMap<number, HTMLDivElement[]>, addAsAnnotation?: boolean) => Opt<Doc> = (color: string, isTargetToggler: boolean) => undefined; - public GetAnchor: (savedAnnotations: Opt<ObservableMap<number, HTMLDivElement[]>>, addAsAnnotation: boolean) => Opt<Doc> = (savedAnnotations: Opt<ObservableMap<number, HTMLDivElement[]>>, addAsAnnotation: boolean) => undefined; + public Highlight: (color: string) => Opt<Doc> = (/* color: string */) => undefined; + public GetAnchor: (savedAnnotations: Opt<ObservableMap<number, HTMLDivElement[]>>, addAsAnnotation: boolean) => Opt<Doc> = emptyFunction; public Delete: () => void = unimplementedFunction; public PinToPres: () => void = unimplementedFunction; public MakeTargetToggle: () => void = unimplementedFunction; @@ -66,8 +69,8 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { componentDidMount() { this._disposer = reaction( - () => SelectionManager.Views.slice(), - sel => AnchorMenu.Instance.fadeOut(true) + () => DocumentView.Selected().slice(), + () => AnchorMenu.Instance.fadeOut(true) ); } @@ -88,6 +91,10 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { } GPTPopup.Instance.setLoading(false); }; + // gptSummarize = async () => { + // GPTPopup.Instance?.setSelectedText(this._selectedText); + // GPTPopup.Instance.generateSummary(); + // }; /** * Invokes the API with the selected text and stores it in the selected text. @@ -134,35 +141,35 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { setupMoveUpEvents( this, e, - (e: PointerEvent) => { - this.StartDrag(e, this._commentRef.current!); + (moveEv: PointerEvent) => { + this.StartDrag(moveEv, this._commentRef.current!); return true; }, returnFalse, - e => this.OnClick?.(e) + clickEv => this.OnClick?.(clickEv) ); }; audioDown = (e: React.PointerEvent) => { - setupMoveUpEvents(this, e, returnFalse, returnFalse, e => this.OnAudio?.(e)); + setupMoveUpEvents(this, e, returnFalse, returnFalse, clickEv => this.OnAudio?.(clickEv)); }; cropDown = (e: React.PointerEvent) => { setupMoveUpEvents( this, e, - (e: PointerEvent) => { - this.StartCropDrag(e, this._cropRef.current!); + (moveEv: PointerEvent) => { + this.StartCropDrag(moveEv, this._cropRef.current!); return true; }, returnFalse, - e => this.OnCrop?.(e) + clickev => this.OnCrop?.(clickev) ); }; @action - highlightClicked = (e: React.MouseEvent) => { - this.Highlight(this.highlightColor, false, undefined, true); + highlightClicked = () => { + this.Highlight(this.highlightColor); AnchorMenu.Instance.fadeOut(true); }; @@ -171,7 +178,7 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { <Group> <IconButton icon={<FontAwesomeIcon icon="highlighter" style={{ transition: 'transform 0.1s', transform: 'rotate(-45deg)' }} />} - tooltip={'Click to Highlight'} + tooltip="Click to Highlight" onClick={this.highlightClicked} colorPicker={this.highlightColor} color={SettingsManager.userColor} @@ -187,16 +194,9 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { hsl: { a: 0, h: 0, s: 0, l: 0 }, rgb: { a: 0, r: 0, b: 0, g: 0 }, }; - this.highlightColor = Utils.colorString(col); + this.highlightColor = ClientUtils.colorString(col); }; - /** - * Returns whether the selected text can be summarized. The goal is to have - * all selected text available to summarize but its only supported for pdf and web ATM. - * @returns Whether the GPT icon for summarization should appear - */ - canSummarize = () => SelectionManager.Docs.some(doc => [DocumentType.PDF, DocumentType.WEB].includes(doc.type as any)); - render() { const buttons = this.Status === 'marquee' ? ( @@ -210,8 +210,8 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { color={SettingsManager.userColor} /> </div> - {/* GPT Summarize icon only shows up when text is highlighted, not on marquee selection*/} - {AnchorMenu.Instance.StartCropDrag === unimplementedFunction && this.canSummarize() && ( + {/* GPT Summarize icon only shows up when text is highlighted, not on marquee selection */} + {this._selectedText && ( <IconButton tooltip="Summarize with AI" // onPointerDown={this.gptSummarize} @@ -237,7 +237,7 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { <Popup tooltip="Find document to link to selected text" // type={Type.PRIM} - icon={<FontAwesomeIcon icon={'search'} />} + icon={<FontAwesomeIcon icon="search" />} popup={<LinkPopup key="popup" linkCreateAnchor={this.onMakeAnchor} />} color={SettingsManager.userColor} /> @@ -280,7 +280,7 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> { )} {this.IsTargetToggler !== returnFalse && ( <Toggle - tooltip={'Make target visibility toggle on click'} + tooltip="Make target visibility toggle on click" type={Type.PRIM} toggleType={ToggleType.BUTTON} toggleStatus={this.IsTargetToggler()} |
