aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/DocUtils.ts13
-rw-r--r--src/client/documents/DocumentTypes.ts2
-rw-r--r--src/client/documents/Documents.ts52
-rw-r--r--src/client/views/Main.tsx4
-rw-r--r--src/client/views/nodes/formattedText/DailyJournal.tsx108
-rw-r--r--src/server/ApiManagers/AssistantManager.ts3
6 files changed, 180 insertions, 2 deletions
diff --git a/src/client/documents/DocUtils.ts b/src/client/documents/DocUtils.ts
index 23032b62e..5a39a9720 100644
--- a/src/client/documents/DocUtils.ts
+++ b/src/client/documents/DocUtils.ts
@@ -396,6 +396,19 @@ export namespace DocUtils {
event: e => (DocumentView.Selected().lastElement().ComponentView as CollectionFreeFormView)?.showSmartDraw(e?.x || 0, e?.y || 0),
icon: 'file',
});
+
+ // AARAV ADD //
+ documentList.push({
+ description: ':Daily Journal',
+ event: undoable(() => {
+ const newDoc = Docs.Create.DailyJournalDocument('', { x, y });
+ docAdder?.(newDoc);
+ }, 'Create Daily Journal'),
+ icon: 'book',
+ });
+
+ // AARAV ADD //
+
ContextMenu.Instance.addItem({
description: 'Create document',
subitems: documentList,
diff --git a/src/client/documents/DocumentTypes.ts b/src/client/documents/DocumentTypes.ts
index 8aa844c0b..65cd499c9 100644
--- a/src/client/documents/DocumentTypes.ts
+++ b/src/client/documents/DocumentTypes.ts
@@ -44,6 +44,8 @@ export enum DocumentType {
SCRIPTDB = 'scriptdb', // database of scripts
GROUPDB = 'groupdb', // database of groups
+
+ JOURNAL = 'journal', // AARAV ADD
}
export enum CollectionViewType {
Invalid = 'invalid',
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 891223952..ce8c8a6b7 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -19,6 +19,7 @@ import { DocServer } from '../DocServer';
import { dropActionType } from '../util/DropActionTypes';
import { CollectionViewType, DocumentType } from './DocumentTypes';
import { Id } from '../../fields/FieldSymbols';
+import { DailyJournal } from '../views/nodes/formattedText/DailyJournal';
class EmptyBox {
public static LayoutString() {
@@ -569,6 +570,19 @@ export namespace Docs {
options: { acl: '' },
},
],
+
+ // AARAV ADD //
+ [
+ DocumentType.JOURNAL,
+ {
+ layout: { view: EmptyBox, dataField: 'text' },
+ options: {
+ title: 'Daily Journal',
+ acl_Guest: SharingPermissions.View,
+ },
+ },
+ ],
+ // AARAV ADD //
]);
const suffix = 'Proto';
@@ -651,6 +665,7 @@ export namespace Docs {
return undefined;
}
const { layout } = template;
+
// create title
const upper = suffix.toUpperCase();
const title = prototypeId.toUpperCase().replace(upper, `_${upper}`);
@@ -899,6 +914,43 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.RTF), field, options, undefined, fieldKey);
}
+ // AARAV ADD //
+
+ export function DailyJournalDocument(text: string | RichTextField, options: DocumentOptions = {}, fieldKey: string = 'text') {
+ const rtf = {
+ doc: {
+ type: 'doc',
+ content: [
+ {
+ type: 'paragraph',
+ content: [
+ {
+ type: 'text',
+ text,
+ },
+ ],
+ },
+ ],
+ },
+ selection: { type: 'text', anchor: 1, head: 1 },
+ storedMarks: [],
+ Text: text,
+ };
+ const field = text instanceof RichTextField ? text : text ? new RichTextField(JSON.stringify(rtf), text) : options.text instanceof RichTextField ? options.text : undefined;
+
+ return InstanceFromProto(Prototypes.get(DocumentType.JOURNAL), field, {
+ title: new Date().toLocaleDateString(undefined, {
+ weekday: 'long',
+ year: 'numeric',
+ month: 'long',
+ day: 'numeric',
+ }),
+ ...options,
+ });
+ }
+
+ // AARAV ADD //
+
export function LinkDocument(source: Doc, target: Doc, options: DocumentOptions = {}, id?: string) {
const linkDoc = InstanceFromProto(
Prototypes.get(DocumentType.LINK),
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index dda543470..8087a0e6d 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -29,7 +29,6 @@ import { CollectionSchemaView } from './collections/collectionSchema/CollectionS
import { SchemaRowBox } from './collections/collectionSchema/SchemaRowBox';
import './global/globalScripts';
import { AudioBox } from './nodes/AudioBox';
-import { ChatBox } from './nodes/chatbot/chatboxcomponents/ChatBox';
import { ComparisonBox } from './nodes/ComparisonBox';
import { DataVizBox } from './nodes/DataVizBox/DataVizBox';
import { DiagramBox } from './nodes/DiagramBox';
@@ -53,6 +52,8 @@ import { ScriptingBox } from './nodes/ScriptingBox';
import { VideoBox } from './nodes/VideoBox';
import { WebBox } from './nodes/WebBox';
import { CalendarBox } from './nodes/calendarBox/CalendarBox';
+import { ChatBox } from './nodes/chatbot/chatboxcomponents/ChatBox';
+import { DailyJournal } from './nodes/formattedText/DailyJournal';
import { DashDocCommentView } from './nodes/formattedText/DashDocCommentView';
import { DashDocView } from './nodes/formattedText/DashDocView';
import { DashFieldView } from './nodes/formattedText/DashFieldView';
@@ -119,6 +120,7 @@ FieldLoader.ServerLoadStatus = { requested: 0, retrieved: 0, message: 'cache' };
DocumentContentsView.Init(KeyValueBox.LayoutString(), {
StickerPalette: StickerPalette,
FormattedTextBox,
+ DailyJournal, // AARAV
ImageBox,
FontIconBox,
LabelBox,
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',
+ },
+});
diff --git a/src/server/ApiManagers/AssistantManager.ts b/src/server/ApiManagers/AssistantManager.ts
index c41f697db..e859e5c5f 100644
--- a/src/server/ApiManagers/AssistantManager.ts
+++ b/src/server/ApiManagers/AssistantManager.ts
@@ -25,6 +25,7 @@ import { DashUploadUtils } from '../DashUploadUtils';
import { Method } from '../RouteManager';
import { filesDirectory, publicDirectory } from '../SocketData';
import ApiManager, { Registration } from './ApiManager';
+import { env } from 'process';
// Enumeration of directories where different file types are stored
export enum Directory {
@@ -89,7 +90,7 @@ export default class AssistantManager extends ApiManager {
protected initialize(register: Registration): void {
// Initialize Google Custom Search API
const customsearch = google.customsearch('v1');
- const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
+ const openai = new OpenAI({ apiKey: env.OPENAI_API_KEY });
// Register Wikipedia summary API route
register({