diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/formattedText/DailyJournal.tsx | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/client/views/nodes/formattedText/DailyJournal.tsx b/src/client/views/nodes/formattedText/DailyJournal.tsx index 39306632e..e4127fba3 100644 --- a/src/client/views/nodes/formattedText/DailyJournal.tsx +++ b/src/client/views/nodes/formattedText/DailyJournal.tsx @@ -85,11 +85,24 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() console.log('Current text field:', this.dataDoc[this.fieldKey]); } + /** + * Method to set initial date of document in the calendar view + */ + @action setInitialDateRange() { - if (!this.dataDoc.date_range) { - const isoDate = new Date().toISOString().split('T')[0]; // YYYY-MM-DD - this.dataDoc.date_range = `${isoDate}|${isoDate}`; - this.dataDoc.allDay = true; + if (!this.dataDoc.date_range && 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; + + console.log('Set date_range and allDay on journal (from local date):', this.dataDoc.date_range); + } else { + console.log('Could not parse journalDate:', this.journalDate); + } } } @@ -104,6 +117,22 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() if (this.typingTimeout) clearTimeout(this.typingTimeout); + const { state } = editorView; + const cursorPos = state.selection.from; + + // characters before cursor + const triggerText = state.doc.textBetween(Math.max(0, cursorPos - 4), cursorPos); + + if (triggerText === '/ask') { + // remove /ask text + const tr = state.tr.delete(cursorPos - 4, cursorPos); + editorView.dispatch(tr); + + // insert predicted question + this.insertPredictiveQuestion(); + return; + } + this.typingTimeout = setTimeout(() => { this.insertPredictiveQuestion(); }, 3500); @@ -149,7 +178,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() const fontSizeMark = this.prePredictiveMarks.find(m => m.type.name === 'pFontSize'); const fontFamilyMark = this.prePredictiveMarks.find(m => m.type.name === 'pFontFamily'); // if applicable - this.predictiveText = ' ...'; // placeholder for now + this.predictiveText = ' ...'; // placeholder const fullTextUpToCursor = state.doc.textBetween(0, state.selection.to, '\n', '\n'); const gptPrompt = `Given the following incomplete journal entry, generate a single 2-5 word question that continues the user's thought:\n\n"${fullTextUpToCursor}"`; @@ -162,7 +191,6 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() // Insert styled text at cursor position const transaction = state.tr.insert(insertPos, predictedText).setStoredMarks(this.prePredictiveMarks); - // should probably instead inquire marks before predictive prompt dispatch(transaction); this.predictiveText = text; |