diff options
Diffstat (limited to 'src/client/views/nodes/formattedText')
-rw-r--r-- | src/client/views/nodes/formattedText/DailyJournal.tsx | 70 |
1 files changed, 19 insertions, 51 deletions
diff --git a/src/client/views/nodes/formattedText/DailyJournal.tsx b/src/client/views/nodes/formattedText/DailyJournal.tsx index ae5582ef7..564609494 100644 --- a/src/client/views/nodes/formattedText/DailyJournal.tsx +++ b/src/client/views/nodes/formattedText/DailyJournal.tsx @@ -12,7 +12,6 @@ import { RTFCast } from '../../../../fields/Types'; import { Mark } from 'prosemirror-model'; import { observer } from 'mobx-react'; - export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() { @observable journalDate: string; @observable typingTimeout: NodeJS.Timeout | null = null; // track typing delay @@ -22,8 +21,6 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() @observable inlinePromptsEnabled = true; @observable askPromptsEnabled = true; - - _ref = React.createRef<FormattedTextBox>(); // reference to the formatted textbox predictiveTextRange: { from: number; to: number } | null = null; // where predictive text starts and ends private predictiveText: string | null = ' ... why?'; @@ -114,7 +111,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() @action.bound toggleAskPrompts() { this.askPromptsEnabled = !this.askPromptsEnabled; } - + /** * Method to handle click on document (to close prompt menu) * @param e - a click on the document @@ -123,33 +120,27 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() handleDocumentClick(e: MouseEvent) { const menu = document.getElementById('prompts-menu'); const button = document.getElementById('prompts-button'); - if ( - this.showPromptMenu && - menu && - !menu.contains(e.target as Node) && - button && - !button.contains(e.target as Node) - ) { + if (this.showPromptMenu && menu && !menu.contains(e.target as Node) && button && !button.contains(e.target as Node)) { this.showPromptMenu = false; } } - /** * Method to set initial date of document in the calendar view */ @action setInitialDateRange() { - if (!this.dataDoc.date_range && this.journalDate) { + if (!this.dataDoc.$task_dateRange && this.journalDate) { const parsedDate = new Date(this.journalDate); if (!isNaN(parsedDate.getTime())) { const localStart = new Date(parsedDate.getFullYear(), parsedDate.getMonth(), parsedDate.getDate()); const localEnd = new Date(localStart); // same day - this.dataDoc.date_range = `${localStart.toISOString()}|${localEnd.toISOString()}`; - this.dataDoc.allDay = true; + this.dataDoc.$task_dateRange = `${localStart.toISOString()}|${localEnd.toISOString()}`; + this.dataDoc.$task_allDay = true; + this.dataDoc.$task = ''; // needed only to make the keyvalue view look good. - // console.log('Set date_range and allDay on journal (from local date):', this.dataDoc.date_range); + // console.log('Set task_dateRange and task_allDay on journal (from local date):', this.dataDoc.$task_dateRange); } else { // console.log('Could not parse journalDate:', this.journalDate); } @@ -187,7 +178,6 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() if (this.inlinePromptsEnabled) { this.insertPredictiveQuestion(); } - }, 3500); }; @@ -196,7 +186,6 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() */ @action insertPredictiveQuestion = async () => { - const editorView = this._ref.current?.EditorView; if (!editorView) return; @@ -347,7 +336,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() */ @action handleGeneratePrompts = async () => { if (this.isLoadingPrompts) { - return + return; } this.isLoadingPrompts = true; @@ -391,8 +380,6 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() // Insert formatted text const transaction = state.tr.insert(state.selection.from, headerText).insert(state.selection.from + headerText.nodeSize, responseText); dispatch(transaction); - (this._props as any)?.updateLayout?.(); - } } catch (err) { console.error('Error calling GPT:', err); @@ -402,7 +389,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() }; /** - * Method to render the styled DailyJournal + * Method to render the styled DailyJournal * @returns - the HTML component for the journal */ render() { @@ -438,8 +425,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() cursor: 'pointer', zIndex: 10, }} - onClick={this.togglePromptMenu} - > + onClick={this.togglePromptMenu}> Prompts </button> {this.showPromptMenu && ( @@ -458,16 +444,14 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() minWidth: '170px', maxWidth: 'fit-content', overflow: 'auto', - }} - > + }}> <div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center', marginBottom: '10px', - }} - > + }}> <label style={{ display: 'flex', @@ -476,26 +460,19 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() fontSize: '14px', justifyContent: 'flex-end', width: '100%', - }} - > + }}> /ask - <input - type="checkbox" - checked={this.askPromptsEnabled} - onChange={this.toggleAskPrompts} - style={{ margin: 0 }} - /> + <input type="checkbox" checked={this.askPromptsEnabled} onChange={this.toggleAskPrompts} style={{ margin: 0 }} /> </label> </div> - + <div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center', marginBottom: '10px', - }} - > + }}> <label style={{ display: 'flex', @@ -504,15 +481,9 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() fontSize: '14px', justifyContent: 'flex-end', width: '100%', - }} - > + }}> Inline Prompting - <input - type="checkbox" - checked={this.inlinePromptsEnabled} - onChange={this.toggleInlinePrompts} - style={{ margin: 0 }} - /> + <input type="checkbox" checked={this.inlinePromptsEnabled} onChange={this.toggleInlinePrompts} style={{ margin: 0 }} /> </label> </div> @@ -531,15 +502,12 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() opacity: this.isLoadingPrompts ? 0.6 : 1, padding: '5px 10px', float: 'right', - }} - > + }}> Generate Prompts </button> </div> )} - - <FormattedTextBox ref={this._ref} {...this._props} fieldKey={'text'} Document={this.Document} TemplateDataDocument={undefined} /> </div> ); |