From 04669ffeb163688c7aefd7b5face7998252abdca Mon Sep 17 00:00:00 2001 From: bobzel Date: Mon, 10 Mar 2025 18:02:07 -0400 Subject: removed label creation from text's anchor menu. removed label creation from pdfs. --- src/client/views/StyleProviderQuiz.tsx | 9 ++-- .../views/nodes/formattedText/FormattedTextBox.tsx | 5 +- src/client/views/pdf/AnchorMenu.tsx | 53 ++-------------------- src/client/views/pdf/PDFViewer.tsx | 8 ++-- src/client/views/smartdraw/StickerPalette.tsx | 4 +- 5 files changed, 16 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/client/views/StyleProviderQuiz.tsx b/src/client/views/StyleProviderQuiz.tsx index c2c352113..acda38dd7 100644 --- a/src/client/views/StyleProviderQuiz.tsx +++ b/src/client/views/StyleProviderQuiz.tsx @@ -3,7 +3,7 @@ import { Tooltip } from '@mui/material'; import { runInAction } from 'mobx'; import * as React from 'react'; import { returnFalse, setupMoveUpEvents } from '../../ClientUtils'; -import { emptyFunction } from '../../Utils'; +import { emptyFunction, unimplementedFunction } from '../../Utils'; import { Doc, DocListCast, Opt } from '../../fields/Doc'; import { DocData } from '../../fields/DocSymbols'; import { List } from '../../fields/List'; @@ -113,7 +113,7 @@ export namespace styleProviderQuiz { /** * Create flashcards from an image. */ - async function getImageDesc(img: ImageBox) { + async function makeFlashcardsForImage(img: ImageBox) { img.Loading = true; try { const hrefBase64 = await createCanvas(img); @@ -383,10 +383,7 @@ export namespace styleProviderQuiz { } break; case StyleProp.AnchorMenuItems: - if (imgBox) { - AnchorMenu.Instance.gptFlashcards = () => getImageDesc(imgBox); - AnchorMenu.Instance.makeLabels = () => makeLabels(props?.DocumentView?.().ComponentView as ImageBox); - } + AnchorMenu.Instance.makeLabels = imgBox ? () => makeLabels(props?.DocumentView?.().ComponentView as ImageBox) : unimplementedFunction; } return undefined; } diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index 7feaac6ae..38817ac6d 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -226,7 +226,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent { + selectionToFlashcards = async () => { const queryText = window.getSelection()?.toString() ?? ''; try { if (queryText) { @@ -241,7 +241,8 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent { AnchorMenu.Instance.Status = 'marquee'; - AnchorMenu.Instance.gptFlashcards = this.gptPDFFlashcards; + // AnchorMenu.Instance.gptFlashcards = this.selectionToFlashcards; + AnchorMenu.Instance.makeLabels = unimplementedFunction; AnchorMenu.Instance.addToCollection = this._props.DocumentView?.()._props.addDocument; AnchorMenu.Instance.OnClick = () => { !this.layoutDoc.layout_showSidebar && this.toggleSidebar(); diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx index 9aa8fe649..eaaeb8d97 100644 --- a/src/client/views/pdf/AnchorMenu.tsx +++ b/src/client/views/pdf/AnchorMenu.tsx @@ -1,24 +1,19 @@ import { ColorPicker, Group, IconButton, Popup, Size, Toggle, ToggleType, Type } from '@dash/components'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { IReactionDisposer, ObservableMap, action, computed, makeObservable, observable, reaction, runInAction } from 'mobx'; +import { IReactionDisposer, ObservableMap, action, computed, makeObservable, observable, reaction } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; import { ColorResult } from 'react-color'; -import ReactLoading from 'react-loading'; import { ClientUtils, returnFalse, setupMoveUpEvents } from '../../../ClientUtils'; import { emptyFunction, unimplementedFunction } from '../../../Utils'; import { Doc, Opt } from '../../../fields/Doc'; -import { DocData } from '../../../fields/DocSymbols'; import { SettingsManager } from '../../util/SettingsManager'; -import { undoBatch } from '../../util/UndoManager'; import { AntimodeMenu, AntimodeMenuProps } from '../AntimodeMenu'; import { LinkPopup } from '../linking/LinkPopup'; import { ComparisonBox } from '../nodes/ComparisonBox'; import { DocumentView } from '../nodes/DocumentView'; -import { DrawingOptions, SmartDrawHandler } from '../smartdraw/SmartDrawHandler'; import './AnchorMenu.scss'; import { GPTPopup } from './GPTPopup/GPTPopup'; -import { RichTextMenu } from '../nodes/formattedText/RichTextMenu'; @observer export class AnchorMenu extends AntimodeMenu { @@ -116,39 +111,6 @@ export class AnchorMenu extends AntimodeMenu { ); }; - /** - * Creates a GPT drawing based on selected text. - */ - gptDraw = (e: React.PointerEvent) => { - try { - SmartDrawHandler.Instance.AddDrawing = this.createDrawingAnnotation; - runInAction(() => (this._isLoading = true)); - SmartDrawHandler.Instance.drawWithGPT({ X: e.clientX, Y: e.clientY }, this._selectedText, 5, 100, true)?.then( - action(() => { - this._isLoading = false; - }) - ); - } catch (err) { - console.error(err); - } - }; - - /** - * Defines how a GPT drawing should be added to the current document. - */ - @undoBatch - createDrawingAnnotation = action((drawing: Doc, opts: DrawingOptions, gptRes: string) => { - this.AddDrawingAnnotation(drawing); - const docData = drawing[DocData]; - docData.title = opts.text?.match(/^(.*?)~~~.*$/)?.[1] || opts.text; - docData.ai_drawing_input = opts.text; - docData.ai_drawing_complexity = opts.complexity; - docData.ai_drawing_colored = opts.autoColor; - docData.ai_drawing_size = opts.size; - docData.ai_drawing_data = gptRes; - docData.ai = 'gpt'; - }); - pointerDown = (e: React.PointerEvent) => { setupMoveUpEvents( this, @@ -232,17 +194,8 @@ export class AnchorMenu extends AntimodeMenu { /> )} {/* Adds a create flashcards option to the anchor menu, which calls the gptFlashcard method. */} - } color={SettingsManager.userColor} /> - } color={SettingsManager.userColor} /> - {this._selectedText && ( - this.gptDraw(e)} - icon={this._isLoading ? : } - color={SettingsManager.userColor} - /> - )} - {this._selectedText && RichTextMenu.Instance?.createLinkButton()} + {this.gptFlashcards === unimplementedFunction ? null : } color={SettingsManager.userColor} />} + {this.makeLabels === unimplementedFunction ? null : } color={SettingsManager.userColor} />} {AnchorMenu.Instance.OnAudio === unimplementedFunction ? null : ( { */ gptPDFFlashcards = async () => { const queryText = this._selectionText; - this._loading = true; + runInAction(() => (this._loading = true)); try { const res = await gptAPICall(queryText, GPTCallType.FLASHCARD); @@ -406,11 +406,12 @@ export class PDFViewer extends ObservableReactComponent { } catch (err) { console.error(err); } - this._loading = false; + runInAction(() => (this._loading = false)); }; @action finishMarquee = (/* x?: number, y?: number */) => { + AnchorMenu.Instance.makeLabels = unimplementedFunction; this._getAnchor = AnchorMenu.Instance?.GetAnchor; this.isAnnotating = false; this._marqueeref.current?.onTerminateSelection(); @@ -442,6 +443,7 @@ export class PDFViewer extends ObservableReactComponent { // allows for creating collection AnchorMenu.Instance.addToCollection = this._props.DocumentView?.()._props.addDocument; AnchorMenu.Instance.gptFlashcards = this.gptPDFFlashcards; + AnchorMenu.Instance.makeLabels = unimplementedFunction; AnchorMenu.Instance.AddDrawingAnnotation = this.addDrawingAnnotation; }; diff --git a/src/client/views/smartdraw/StickerPalette.tsx b/src/client/views/smartdraw/StickerPalette.tsx index d5307974f..e3305851a 100644 --- a/src/client/views/smartdraw/StickerPalette.tsx +++ b/src/client/views/smartdraw/StickerPalette.tsx @@ -151,7 +151,7 @@ export class StickerPalette extends ObservableReactComponent { return this._showRegenerate ? SmartDrawHandler.Instance.regenerate(prevDrawings, this._opts, this._gptRes[i], this._userInput) - : SmartDrawHandler.Instance.drawWithGPT({ X: 0, Y: 0 }, this._userInput, this._opts.complexity, this._opts.size, this._opts.autoColor); + : SmartDrawHandler.Instance.drawWithGPT({ X: 0, Y: 0 }, this._userInput, this._opts.complexity || 0, this._opts.size || 0, !!this._opts.autoColor); }) ).then(() => { this._opts.text !== '' ? (this._opts.text = `${this._opts.text} ~~~ ${this._userInput}`) : (this._opts.text = this._userInput); @@ -177,7 +177,7 @@ export class StickerPalette extends ObservableReactComponent