From 14b23094ea3050b96dc6aed28b5f35612c821140 Mon Sep 17 00:00:00 2001
From: Naafiyan Ahmed <naafiyan@gmail.com>
Date: Mon, 2 May 2022 23:16:33 -0400
Subject: got subgrouping to work naively

---
 src/client/views/InkTranscription.tsx | 36 +++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)

(limited to 'src/client/views/InkTranscription.tsx')

diff --git a/src/client/views/InkTranscription.tsx b/src/client/views/InkTranscription.tsx
index 3d505878c..7e26b51a0 100644
--- a/src/client/views/InkTranscription.tsx
+++ b/src/client/views/InkTranscription.tsx
@@ -1,7 +1,7 @@
 import * as iink from 'iink-js';
 import { action, observable } from 'mobx';
 import * as React from 'react';
-import { DataSym, Doc, DocListCast, HeightSym, WidthSym } from '../../fields/Doc';
+import { DataSym, Doc, DocListCast, HeightSym, WidthSym, LayoutSym } from '../../fields/Doc';
 import { InkData, InkField } from "../../fields/InkField";
 import { Cast, DateCast, NumCast } from '../../fields/Types';
 import { DocumentType } from "../documents/DocumentTypes";
@@ -9,6 +9,8 @@ import './InkTranscription.scss';
 import { aggregateBounds, Utils } from '../../Utils';
 import { timesSeries } from 'async';
 import { CollectionFreeFormView } from './collections/collectionFreeForm';
+import { DocumentManager } from "../util/DocumentManager";
+
 
 export class InkTranscription extends React.Component {
     static Instance: InkTranscription;
@@ -169,18 +171,29 @@ export class InkTranscription extends React.Component {
         return max - min;
     }
 
-    subgroupsTranscriptions = (wordInkDocMap: Map<string, Doc[]>) => {
+    subgroupsTranscriptions = async (wordInkDocMap: Map<string, Doc[]>) => {
          // TODO: nda - will probably want to go through ffView unprocessed docs and then see if any of the inksToGroup docs are in it and only use those
         // loop through the words in wordInkDocMap
         // for each word, get the inkDocs
 
         // iterate through the keys of wordInkDocMap
-        wordInkDocMap.forEach((inkDocs: Doc[], word: string) => {
+        wordInkDocMap.forEach(async (inkDocs: Doc[], word: string) => {
             const selected = inkDocs.slice();
             if (!selected) {
                 return;
             }
-            const marqViewRef = this.ffView._marqueeViewRef.current;
+            console.log("selected[0].context", DocListCast(selected[0].context));
+            console.log("selected[0]", DocListCast(selected[0]));
+            // TODO: nda - probably have to cast this to an actual Doc
+            const ctx = await Cast(selected[0].context, Doc);
+            if (!ctx) {
+                return;
+            }
+            const docView: CollectionFreeFormView = DocumentManager.Instance.getDocumentView(ctx)?.ComponentView as CollectionFreeFormView;
+
+            if (!docView) return;
+            const marqViewRef = docView._marqueeViewRef.current;
+            if (!marqViewRef) return;
             //  loop through selected an get the bound
             const bounds: { x: number, y: number, width?: number, height?: number }[] = []
 
@@ -193,8 +206,9 @@ export class InkTranscription extends React.Component {
             }))
 
             const aggregBounds = aggregateBounds(bounds, 0, 0);
+            const boundsWidth = Math.abs(aggregBounds.x - aggregBounds.r);
+            const boundsHeight = Math.abs(aggregBounds.y - aggregBounds.b);
 
-            // set the vals for bounds in marqueeView
             if (marqViewRef) {
                 marqViewRef._downX = aggregBounds.x;
                 marqViewRef._downY = aggregBounds.y;
@@ -202,6 +216,8 @@ export class InkTranscription extends React.Component {
                 marqViewRef._lastY = aggregBounds.b;
             }
 
+            // set the vals for bounds in marqueeView
+           
             selected.map(action(d => {
                 const dx = NumCast(d.x);
                 const dy = NumCast(d.y);
@@ -211,14 +227,17 @@ export class InkTranscription extends React.Component {
                 delete d._timecodeToShow;  // bcz: this should be automatic somehow.. along with any other properties that were logically associated with the original collection
                 delete d._timecodeToHide;  // bcz: this should be automatic somehow.. along with any other properties that were logically associated with the original collection
                 // calculate pos based on bounds
+                // d.x = dx - aggregBounds.x - boundsWidth / 2;
+                // d.y = dy - aggregBounds.y - boundsHeight / 2;
                 if (marqViewRef?.Bounds) {
                     d.x = dx - marqViewRef.Bounds.left - marqViewRef.Bounds.width / 2;
                     d.y = dy - marqViewRef.Bounds.top - marqViewRef.Bounds.height / 2;
                 }
                 return d;
             }));
-            this.ffView.props.removeDocument?.(selected);
-            // TODO: nda - this is the code to actually get a new grouped collection
+            
+            docView.props.removeDocument?.(selected);
+            // // TODO: nda - this is the code to actually get a new grouped collection
             const newCollection = marqViewRef?.getCollection(selected, undefined, [], true);
             if (newCollection) {
                 newCollection.height = newCollection[HeightSym]();
@@ -226,7 +245,8 @@ export class InkTranscription extends React.Component {
                 newCollection.title = word;
             }
             // nda - bug: when deleting a stroke before leaving writing mode, delete the stroke from unprocessed ink docs
-            newCollection && this.ffView.props.addDocument?.(newCollection);
+            console.log(newCollection);
+            newCollection && docView.props.addDocument?.(newCollection);
         });
     }
 
-- 
cgit v1.2.3-70-g09d2

