From 403dcfb5e8b659f62ed51212ede3f5807caa58c6 Mon Sep 17 00:00:00 2001 From: bobzel Date: Tue, 10 Jun 2025 19:06:31 -0400 Subject: cleanup and streamlining of scrapbook code. --- .../views/nodes/formattedText/FormattedTextBox.tsx | 44 ++++++---------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'src/client/views/nodes/formattedText') diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index 0c3179173..1768eb08d 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -8,7 +8,6 @@ import { baseKeymap, selectAll, splitBlock } from 'prosemirror-commands'; import { history } from 'prosemirror-history'; import { inputRules } from 'prosemirror-inputrules'; import { keymap } from 'prosemirror-keymap'; -import { runInAction } from 'mobx'; import { Fragment, Mark, Node, Slice } from 'prosemirror-model'; import { EditorState, NodeSelection, Plugin, Selection, TextSelection, Transaction } from 'prosemirror-state'; import { EditorView, NodeViewConstructor } from 'prosemirror-view'; @@ -65,7 +64,6 @@ import { removeMarkWithAttrs } from './prosemirrorPatches'; import { RichTextMenu, RichTextMenuPlugin } from './RichTextMenu'; import { RichTextRules } from './RichTextRules'; import { schema } from './schema_rts'; -import { tickStep } from 'd3'; // import * as applyDevTools from 'prosemirror-dev-tools'; export interface FormattedTextBoxProps extends FieldViewProps { @@ -310,30 +308,18 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent { + autoTag = () => { + const rawText = RTFCast(this.Document[this.fieldKey])?.Text ?? StrCast(this.Document[this.fieldKey]); + const callType = rawText.includes('[placeholder]') ? GPTCallType.CLASSIFYTEXTMINIMAL : GPTCallType.CLASSIFYTEXTFULL; - const layoutKey = Doc.LayoutDataKey(this.Document); - const rawText = RTFCast(this.Document[layoutKey])?.Text ?? StrCast(this.Document[layoutKey]); - - const callType = rawText.includes("[placeholder]") - ? GPTCallType.CLASSIFYTEXTMINIMAL - : GPTCallType.CLASSIFYTEXTFULL; - - gptAPICall(rawText, callType).then(desc => { - runInAction(() => { - // Clear existing tags - this.Document.$tags_chat = new List(); - - // Split GPT response into tokens and push individually - const tokens = desc.trim().split(/\s+/); - tokens.forEach(tok => { - (this.Document.$tags_chat as List).push(tok); - }); - - this.Document._layout_showTags = true; - }); - }); -}; + gptAPICall(rawText, callType).then( + action(desc => { + // Split GPT response into tokens and push individually & clear existing tags + this.Document.$tags_chat = new List(desc.trim().split(/\s+/)); + this.Document._layout_showTags = true; + }) + ); + }; leafText = (node: Node) => { if (node.type === this.EditorView?.state.schema.nodes.dashField) { @@ -1298,13 +1284,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent ({ title: this.Document.title, sel: this._props.isSelected() }), - action(() => { - this.autoTag(); - }), - { fireImmediately: true } - ); + this._disposers.tagger = reaction(() => ({ title: this.Document.title, sel: this._props.isSelected() }), this.autoTag, { fireImmediately: true }); if (!this._props.dontRegisterView) { this._disposers.record = reaction( -- cgit v1.2.3-70-g09d2