aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/formattedText/DailyJournal.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/formattedText/DailyJournal.tsx')
-rw-r--r--src/client/views/nodes/formattedText/DailyJournal.tsx108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/client/views/nodes/formattedText/DailyJournal.tsx b/src/client/views/nodes/formattedText/DailyJournal.tsx
new file mode 100644
index 000000000..9decbfaf0
--- /dev/null
+++ b/src/client/views/nodes/formattedText/DailyJournal.tsx
@@ -0,0 +1,108 @@
+import { action, makeObservable, observable } from 'mobx';
+import * as React from 'react';
+import { RichTextField } from '../../../../fields/RichTextField';
+import { Docs } from '../../../documents/Documents';
+import { DocumentType } from '../../../documents/DocumentTypes';
+import { ViewBoxAnnotatableComponent } from '../../DocComponent';
+import { FieldView, FieldViewProps } from '../FieldView';
+import { FormattedTextBox, FormattedTextBoxProps } from './FormattedTextBox';
+
+export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() {
+ @observable journalDate: string;
+
+ public static LayoutString(fieldStr: string) {
+ return FieldView.LayoutString(DailyJournal, fieldStr);
+ }
+
+ constructor(props: FormattedTextBoxProps) {
+ super(props);
+ makeObservable(this);
+ this.journalDate = this.getFormattedDate();
+
+ console.log('Constructor: Setting initial title and text...');
+ this.setDailyTitle();
+ this.setDailyText();
+ }
+
+ getFormattedDate(): string {
+ const date = new Date().toLocaleDateString(undefined, {
+ weekday: 'long',
+ year: 'numeric',
+ month: 'long',
+ day: 'numeric',
+ });
+ console.log('📆 getFormattedDate():', date);
+ return date;
+ }
+
+ @action
+ setDailyTitle() {
+ console.log('setDailyTitle() called...');
+ console.log('Current title before update:', this.dataDoc.title);
+
+ if (!this.dataDoc.title || this.dataDoc.title !== this.journalDate) {
+ console.log('Updating title to:', this.journalDate);
+ this.dataDoc.title = this.journalDate;
+ }
+
+ console.log('New title after update:', this.dataDoc.title);
+ }
+
+ @action
+ setDailyText() {
+ console.log('setDailyText() called...');
+ const initialText = `Journal Entry - ${this.journalDate}\n\nStart writing here...`;
+
+ console.log('Checking if dataDoc has text field...');
+
+ console.log('Setting new text field with:', initialText);
+ this.dataDoc[this.fieldKey] = new RichTextField(
+ JSON.stringify({
+ doc: {
+ type: 'doc',
+ content: [{ type: 'paragraph', content: [{ type: 'text', text: initialText }] }],
+ },
+ selection: { type: 'text', anchor: 1, head: 1 },
+ storedMarks: [],
+ }),
+ initialText
+ );
+
+ console.log('Current text field:', this.dataDoc[this.fieldKey]);
+ }
+
+ componentDidMount(): void {
+ console.log('componentDidMount() triggered...');
+ this.setDailyTitle();
+ this.setDailyText();
+ }
+
+ componentDidUpdate(prevProps: Readonly<FormattedTextBoxProps>): void {
+ console.log('componentDidUpdate() triggered...');
+ super.componentDidUpdate(prevProps);
+ this.setDailyTitle();
+ this.setDailyText();
+ }
+
+ render() {
+ return <div style={{ background: 'beige', width: '100%', height: '100%' }}>
+ <FormattedTextBox {...this._props} fieldKey={'text'} Document={this.Document} TemplateDataDocument={undefined} />
+
+ </div>;
+ }
+}
+
+Docs.Prototypes.TemplateMap.set(DocumentType.JOURNAL, {
+ layout: { view: DailyJournal, dataField: 'text' },
+ options: {
+ acl: '',
+ _height: 35,
+ _xMargin: 10,
+ _yMargin: 10,
+ _layout_nativeDimEditable: true,
+ _layout_reflowVertical: true,
+ _layout_reflowHorizontal: true,
+ defaultDoubleClick: 'ignore',
+ systemIcon: 'BsFileEarmarkTextFill',
+ },
+});