From 4fcad4eb428746ca597598732b3f2946e0eea14a Mon Sep 17 00:00:00 2001 From: ljungster Date: Tue, 22 Mar 2022 16:18:32 -0400 Subject: stashing --- .../views/collections/CollectionNoteTakingView.tsx | 138 +++++++++------------ .../CollectionNoteTakingViewFieldColumn.tsx | 6 - src/client/views/collections/CollectionView.tsx | 1 + 3 files changed, 60 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionNoteTakingView.tsx b/src/client/views/collections/CollectionNoteTakingView.tsx index fbb789894..3fd63d245 100644 --- a/src/client/views/collections/CollectionNoteTakingView.tsx +++ b/src/client/views/collections/CollectionNoteTakingView.tsx @@ -4,10 +4,9 @@ import { CursorProperty } from "csstype"; import { action, computed, IReactionDisposer, observable, reaction, runInAction } from "mobx"; import { observer } from "mobx-react"; import { DataSym, Doc, HeightSym, Opt, WidthSym } from "../../../fields/Doc"; -import { collectionSchema, documentSchema } from "../../../fields/documentSchemas"; import { Id } from "../../../fields/FieldSymbols"; import { List } from "../../../fields/List"; -import { listSpec, makeInterface } from "../../../fields/Schema"; +import { listSpec } from "../../../fields/Schema"; import { SchemaHeaderField } from "../../../fields/SchemaHeaderField"; import { BoolCast, Cast, NumCast, ScriptCast, StrCast } from "../../../fields/Types"; import { TraceMobx } from "../../../fields/util"; @@ -19,39 +18,32 @@ import { Transform } from "../../util/Transform"; import { undoBatch } from "../../util/UndoManager"; import { ContextMenu } from "../ContextMenu"; import { ContextMenuProps } from "../ContextMenuItem"; -import { EditableView } from "../EditableView"; import { LightboxView } from "../LightboxView"; import { CollectionFreeFormDocumentView } from "../nodes/CollectionFreeFormDocumentView"; import { DocFocusOptions, DocumentView, DocumentViewProps, ViewAdjustment } from "../nodes/DocumentView"; import { StyleProp } from "../StyleProvider"; +import { CollectionNoteTakingViewFieldColumn } from "./CollectionNoteTakingViewFieldColumn"; import "./CollectionStackingView.scss"; -import { CollectionStackingViewFieldColumn } from "./CollectionStackingViewFieldColumn"; import { CollectionSubView } from "./CollectionSubView"; import { CollectionViewType } from "./CollectionView"; import internal = require("events"); -import { CollectionNoteTakingViewFieldColumn } from "./CollectionNoteTakingViewFieldColumn"; const _global = (window /* browser */ || global /* node */) as any; -type StackingDocument = makeInterface<[typeof collectionSchema, typeof documentSchema]>; -const StackingDocument = makeInterface(collectionSchema, documentSchema); - export type collectionNoteTakingViewProps = { chromeHidden?: boolean; viewType?: CollectionViewType; NativeWidth?: () => number; NativeHeight?: () => number; - numColumns?: number; }; //TODO: where am I going to add columns? @observer -export class CollectionNoteTakingView extends CollectionSubView>(StackingDocument) { +export class CollectionNoteTakingView extends CollectionSubView>() { // used in a column dragger, likely due for the masonry grid view. We want to use this _draggerRef = React.createRef(); // Seems like we cause reaction in MobX get rid of our height once we exit this view _autoHeightDisposer?: IReactionDisposer; - _pivotFieldDisposer?: IReactionDisposer; // keeping track of documents. Updated on internal and external drops. What's the difference? _docXfs: { height: () => number, width: () => number, stackedDocTransform: () => Transform }[] = []; @@ -59,9 +51,11 @@ export class CollectionNoteTakingView extends CollectionSubView(); + this.layoutDoc._columnHeaders = new List([new SchemaHeaderField("0")]); } - + console.log(this.layoutDoc._columnHeaders) } children = (docs: Doc[]) => { @@ -98,6 +91,11 @@ export class CollectionNoteTakingView extends CollectionSubView { + if (d._columnIndex && parseInt(d._columnIndex.toString()) + 1 > this.numColumns) { + this._numColumns = parseInt(d._columnIndex.toString()) + 1; + } else if (d._columnIndex === undefined) { + d._columnIndex = 0; + } const height = () => this.getDocHeight(d); const width = () => this.getDocWidth(d); // just getting the style @@ -109,27 +107,19 @@ export class CollectionNoteTakingView extends CollectionSubView(); if (this.columnHeaders === undefined) { setTimeout(() => this.layoutDoc._columnHeaders = new List(), 0); return new Map(); } - const columnHeaders = Array.from(this.columnHeaders); const fields = new Map(columnHeaders.map(sh => [sh, []] as [SchemaHeaderField, []])); let changed = false; this.filteredChildren.map(d => { - // need to set the section value - console.log(d._columnIndex) - if (!d.hasOwnProperty("_columnIndex")) { - d._columnIndex = 0; - - } - const sectionValue = (d[this.columnIndex] ? d[this.columnIndex] : `NO ${this.columnIndex.toUpperCase()} VALUE`) as object; // the next five lines ensures that floating point rounding errors don't create more than one section -syip const parsed = parseInt(sectionValue.toString()); @@ -137,13 +127,11 @@ export class CollectionNoteTakingView extends CollectionSubView sh.heading === (castedSectionValue ? castedSectionValue.toString() : `NO ${this.columnIndex.toUpperCase()} VALUE`)); - // const existingHeader = columnHeaders.find(sh => sh.heading === castedSectionValue.toString()); if (existingHeader) { fields.get(existingHeader)!.push(d); } else { const newSchemaHeader = new SchemaHeaderField(castedSectionValue ? castedSectionValue.toString() : `NO ${this.columnIndex.toUpperCase()} VALUE`); - // const newSchemaHeader = new SchemaHeaderField(castedSectionValue.toString()); fields.set(newSchemaHeader, [d]); columnHeaders.push(newSchemaHeader); changed = true; @@ -161,16 +149,44 @@ export class CollectionNoteTakingView extends CollectionSubView this.columnHeaders?.splice(0, this.columnHeaders.length, ...columnHeaders)), 0); return fields; } + //TODO: this seems important + // get Sections() { + // // at the start, we likely will not have column headers + // if (this.columnHeaders === undefined) { + // console.log("columns weren't yet defined") + // setTimeout(() => this.layoutDoc._columnHeaders = new List([new SchemaHeaderField("0")])); + // return new Map(); + // } + + // // on later renders, we should have the column headers + // const columnHeaders = Array.from(this.columnHeaders); + // console.log(columnHeaders) + // const fields = new Map(); + // let changed = false; + // this.filteredChildren.map(d => { + // const sectionValue = (d._columnIndex ? d._columnIndex : `NO COLUMN VALUE`) as object; + // // the next five lines ensures that floating point rounding errors don't create more than one section -syip + // const parsed = parseInt(sectionValue.toString()); + // const castedSectionValue = !isNaN(parsed) ? parsed : sectionValue; + // const newSchemaHeader = new SchemaHeaderField(castedSectionValue.toString()); + // const currentDocs = fields.get(newSchemaHeader) + // if (currentDocs) { + // currentDocs.push(d) + // fields.set(newSchemaHeader, currentDocs); + // } + // const existingHeader = columnHeaders.find(sh => sh.heading === (castedSectionValue ? castedSectionValue.toString() : `NO COLUMN VALUE`)); + // if (existingHeader) { + // columnHeaders.push(newSchemaHeader); + // changed = true; + // } + // }); + // changed && setTimeout(action(() => this.columnHeaders?.splice(0, this.columnHeaders.length, ...columnHeaders)), 0); + // return fields; + // } componentDidMount() { super.componentDidMount?.(); - // reset section headers when a new filter is inputted - this._pivotFieldDisposer = reaction( - () => this.columnIndex, - () => this.layoutDoc._columnHeaders = new List() - ); - this._autoHeightDisposer = reaction(() => this.layoutDoc._autoHeight, autoHeight => autoHeight && this.props.setHeight(Math.min(NumCast(this.layoutDoc._maxHeight, Number.MAX_SAFE_INTEGER), this.headerMargin + @@ -179,7 +195,6 @@ export class CollectionNoteTakingView extends CollectionSubView; } - // TODO: plj - @action - onPointerOver = (e: React.PointerEvent) => { - // console.log("hovering over something") - if (DragManager.docsBeingDragged.length) { - // essentially copying code from onInternalDrop for this: - const doc = DragManager.docsBeingDragged[0] - // console.log(doc[LayoutSym]()) - - console.log(doc[DataSym]) - console.log(Doc.IndexOf(doc, this.childDocs)) - - } - - - } - - //used in onPointerOver to swap two nodes in the rendered filtered children list - swapNodes = (i: number, j: number) => { - - } - - //plj added this - @action - onPointerDown = (e: React.PointerEvent) => { - - } - - // TODO: plj - look at this. Start with making changes to db, and then transition to client side @undoBatch @action onInternalDrop = (e: Event, de: DragManager.DropEvent) => { @@ -473,13 +459,11 @@ export class CollectionNoteTakingView extends CollectionSubView { - const key = this.columnIndex; + const key = "columnIndex"; let type: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | undefined = undefined; - if (this.columnIndex) { - const types = docList.length ? docList.map(d => typeof d[key]) : this.filteredChildren.map(d => typeof d[key]); - if (types.map((i, idx) => types.indexOf(i) === idx).length === 1) { - type = types[0]; - } + const types = docList.length ? docList.map(d => typeof d[key]) : this.filteredChildren.map(d => typeof d[key]); + if (types.map((i, idx) => types.indexOf(i) === idx).length === 1) { + type = types[0]; } //TODO: I think that we only have one of these atm return this.sectionStacking(section[0], section[1])); } @@ -643,8 +625,6 @@ export class CollectionNoteTakingView extends CollectionSubView this._scroll = e.currentTarget.scrollTop)} - onPointerOver={this.onPointerOver} - onPointerDown={this.onPointerDown} onDrop={this.onExternalDrop.bind(this)} onContextMenu={this.onContextMenu} onWheel={e => this.props.isContentActive(true) && e.stopPropagation()} > diff --git a/src/client/views/collections/CollectionNoteTakingViewFieldColumn.tsx b/src/client/views/collections/CollectionNoteTakingViewFieldColumn.tsx index 535411118..0c3eef36d 100644 --- a/src/client/views/collections/CollectionNoteTakingViewFieldColumn.tsx +++ b/src/client/views/collections/CollectionNoteTakingViewFieldColumn.tsx @@ -284,12 +284,6 @@ export class CollectionNoteTakingViewFieldColumn extends React.Component {!this.props.chromeHidden && type !== DocumentType.PRES ? - // TODO: this is the "new" button: see what you can work with here - // change cursor to pointer for this, and update dragging cursor - //TODO: there is a bug that occurs when adding a freeform document and trying to move it around - //TODO: would be great if there was additional space beyond the frame, so that you can actually see your - // bottom note - //TODO: ok, so we are using a single column, and this is it!