From c4cae1a65acd5acaf05c7d64120e422e6adde180 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 5 Aug 2022 11:32:39 -0400
Subject: fixed crash with dropping from filesystem onto notetaking view.

---
 .../views/collections/CollectionNoteTakingView.tsx | 40 ++++++++++++----------
 1 file changed, 22 insertions(+), 18 deletions(-)

(limited to 'src/client/views/collections/CollectionNoteTakingView.tsx')

diff --git a/src/client/views/collections/CollectionNoteTakingView.tsx b/src/client/views/collections/CollectionNoteTakingView.tsx
index e80266b22..95aafce94 100644
--- a/src/client/views/collections/CollectionNoteTakingView.tsx
+++ b/src/client/views/collections/CollectionNoteTakingView.tsx
@@ -53,11 +53,8 @@ export class CollectionNoteTakingView extends CollectionSubView<Partial<collecti
         return this.props.chromeHidden || BoolCast(this.layoutDoc.chromeHidden);
     }
     @computed get columnHeaders() {
-        const columnHeaders = Cast(this.dataDoc.columnHeaders, listSpec(SchemaHeaderField), null);
-        let docs = this.childDocs;
-        const needsUnsetCategory = docs.some(d => {
-            return !d[this.notetakingCategoryField] && !columnHeaders.find(sh => sh.heading === 'unset');
-        });
+        const columnHeaders = Array.from(Cast(this.dataDoc.columnHeaders, listSpec(SchemaHeaderField), null));
+        const needsUnsetCategory = this.childDocs.some(d => !d[this.notetakingCategoryField] && !columnHeaders.find(sh => sh.heading === 'unset'));
 
         //  @#Oberable draggedColIndex = ...
         //@observable cloneDivXYcoords
@@ -510,21 +507,28 @@ export class CollectionNoteTakingView extends CollectionSubView<Partial<collecti
     }
 
     // when dropping outside of the current noteTaking context (like a new tab, freeform view, etc...)
-    @undoBatch
-    @action
     onExternalDrop = async (e: React.DragEvent): Promise<void> => {
         const targInd = this.docsDraggedRowCol?.[0] || 0;
-        super.onExternalDrop(e, {}, docus => {
-            this.onPointerMove(true, e.clientX, e.clientY);
-            docus?.map(doc => this.addDocument(doc));
-            const newDoc = this.childDocs.lastElement();
-            const docs = this.childDocList;
-            if (docs && targInd !== -1) {
-                docs.splice(docs.length - 1, 1);
-                docs.splice(targInd, 0, newDoc);
-            }
-            this.removeDocDragHighlight();
-        });
+        const colInd = this.docsDraggedRowCol?.[1] || 0;
+        super.onExternalDrop(
+            e,
+            {},
+            undoBatch(
+                action(docus => {
+                    this.onPointerMove(true, e.clientX, e.clientY);
+                    docus?.map((doc: Doc) => this.addDocument(doc));
+                    const newDoc = this.childDocs.lastElement();
+                    const colHeader = StrCast(this.columnHeaders[colInd].heading);
+                    newDoc[this.notetakingCategoryField] = colHeader;
+                    const docs = this.childDocList;
+                    if (docs && targInd !== -1) {
+                        docs.splice(docs.length - 1, 1);
+                        docs.splice(targInd, 0, newDoc);
+                    }
+                    this.removeDocDragHighlight();
+                })
+            )
+        );
     };
 
     headings = () => Array.from(this.Sections);
-- 
cgit v1.2.3-70-g09d2

