From e2b5bc51c1fa4b4ed026e6582b80086808bdcb70 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Sun, 25 Oct 2020 11:50:03 -0400
Subject: added reaction to switch current presentation when selected

---
 src/client/views/nodes/PresBox.tsx | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'src/client/views/nodes/PresBox.tsx')

diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx
index 0f686c7bc..54830d731 100644
--- a/src/client/views/nodes/PresBox.tsx
+++ b/src/client/views/nodes/PresBox.tsx
@@ -1,7 +1,7 @@
 import React = require("react");
 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
 import { Tooltip } from "@material-ui/core";
-import { action, computed, observable, runInAction, ObservableMap } from "mobx";
+import { action, computed, observable, runInAction, ObservableMap, IReactionDisposer, reaction } from "mobx";
 import { observer } from "mobx-react";
 import { ColorState, SketchPicker } from "react-color";
 import { Doc, DocCastAsync, DocListCast, DocListCastAsync } from "../../../fields/Doc";
@@ -76,6 +76,7 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>
     @observable _pathBoolean: boolean = false;
     @observable _expandBoolean: boolean = false;
 
+    private _disposers: { [name: string]: IReactionDisposer } = {};
     @observable private transitionTools: boolean = false;
     @observable private newDocumentTools: boolean = false;
     @observable private progressivizeTools: boolean = false;
@@ -132,6 +133,7 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>
         this._presKeyEventsActive = false;
         // Turn of progressivize editors
         this.turnOffEdit(true);
+        Object.values(this._disposers).forEach(disposer => disposer?.());
     }
 
     @action
@@ -147,6 +149,8 @@ export class PresBox extends ViewBoxBaseComponent<FieldViewProps, PresBoxSchema>
         this.turnOffEdit(true);
         DocListCastAsync((Doc.UserDoc().myPresentations as Doc).data).then(pres =>
             !pres?.includes(this.rootDoc) && Doc.AddDocToList(Doc.UserDoc().myPresentations as Doc, "data", this.rootDoc));
+        this._disposers.selection = reaction(() => SelectionManager.SelectedDocuments(),
+            views => views.some(view => view.props.Document === this.rootDoc) && this.updateCurrentPresentation())
     }
 
     @action
-- 
cgit v1.2.3-70-g09d2

