diff options
| author | sharkiecodes <lanyi_stroud@brown.edu> | 2025-04-21 19:41:51 -0400 |
|---|---|---|
| committer | sharkiecodes <lanyi_stroud@brown.edu> | 2025-04-21 19:41:51 -0400 |
| commit | 5290e6a69fdadb6037f3d8a03f5ed82e00927520 (patch) | |
| tree | 2ab7cb47f242905b14f78653ba74024b9b4b0b5a /src/client/views/nodes/scrapbook/ScrapbookBox.tsx | |
| parent | 17e24e780b54f2f7015c0ca955c3aa5091bba19c (diff) | |
attempting to integrate scrapbooks
Diffstat (limited to 'src/client/views/nodes/scrapbook/ScrapbookBox.tsx')
| -rw-r--r-- | src/client/views/nodes/scrapbook/ScrapbookBox.tsx | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/client/views/nodes/scrapbook/ScrapbookBox.tsx b/src/client/views/nodes/scrapbook/ScrapbookBox.tsx new file mode 100644 index 000000000..56cfcda70 --- /dev/null +++ b/src/client/views/nodes/scrapbook/ScrapbookBox.tsx @@ -0,0 +1,106 @@ +import { makeObservable } from 'mobx'; +import * as React from 'react'; +import { ViewBoxAnnotatableComponent } from '../../DocComponent'; +import { FieldView, FieldViewProps } from '../FieldView'; +import { Docs } from '../../../documents/Documents'; +import { DocumentType } from '../../../documents/DocumentTypes'; +import { action, observable } from 'mobx'; +import { DocListCast } from '../../../../fields/Doc'; +import { Doc } from '../../../../fields/Doc'; +import { DocumentView } from '../DocumentView'; +import { FormattedTextBox } from '../formattedText/FormattedTextBox'; +import { List } from '../../../../fields/List'; +// Scrapbook view: a container that lays out its child items in a grid/template +export class ScrapbookBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { + @observable createdDate: string; + + constructor(props: FieldViewProps) { + super(props); + makeObservable(this); + this.createdDate = this.getFormattedDate(); + + // ensure we always have a List<Doc> in dataDoc['items'] + if (!this.dataDoc[this.fieldKey]) { + this.dataDoc[this.fieldKey] = new List<Doc>(); + } + this.createdDate = this.getFormattedDate(); + this.setTitle(); + } + + public static LayoutString(fieldStr: string) { + return FieldView.LayoutString(ScrapbookBox, fieldStr); + } + + + + + + + + getFormattedDate(): string { + return new Date().toLocaleDateString(undefined, { + year: 'numeric', + month: 'short', + day: 'numeric', + }); + } + + @action + setTitle() { + const title = `Scrapbook - ${this.createdDate}`; + if (this.dataDoc.title !== title) { + this.dataDoc.title = title; + } + } + + componentDidMount() { + this.setTitle(); + if (!this.dataDoc[this.fieldKey]) { + this.dataDoc[this.fieldKey] = new List<Doc>(); + } + } + + render() { + // cast into an array even if empty + const items: Doc[] = DocListCast(this.dataDoc[this.fieldKey]); + + return ( + <div style={{ background: 'beige', width: '100%', height: '100%' }}> + + </div> + + // <div + // style={{ + // }} + // > + // {items.length === 0 + // ? <div style={{color:'#888',fontStyle:'italic'}}>Drop docs here</div> + // : items.map((childDoc, idx) => ( + // <DocumentView + // key={String(childDoc.id ?? idx)} + // {...this._props} + // Document={childDoc} + // /> + // )) + // } + // </div> + ); + } +} + + +// Register scrapbook +Docs.Prototypes.TemplateMap.set(DocumentType.SCRAPBOOK, { + layout: { view: ScrapbookBox, dataField: 'items' }, + options: { + acl: '', + _height: 200, + _xMargin: 10, + _yMargin: 10, + _layout_autoHeight: true, + _layout_reflowVertical: true, + _layout_reflowHorizontal: true, + defaultDoubleClick: 'ignore', + systemIcon: 'BsImages', + }, +}); |
