From 1773de88f5b5995804c344eb22fbea315e4220bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20Moya?= <andres.moya@kaleidos.net>
Date: Wed, 24 Mar 2021 13:57:47 +0100
Subject: [PATCH] :bug: Fix closing of thumbnails panel in view mode

---
 frontend/resources/styles/main/layouts/handoff.scss | 2 +-
 frontend/resources/styles/main/layouts/viewer.scss  | 2 +-
 frontend/src/app/main/ui/components/dropdown.cljs   | 5 ++---
 frontend/src/app/main/ui/dashboard/grid.cljs        | 6 ++++++
 frontend/src/app/main/ui/handoff.cljs               | 3 ++-
 frontend/src/app/main/ui/viewer.cljs                | 3 ++-
 frontend/src/app/main/ui/viewer/header.cljs         | 1 -
 7 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/frontend/resources/styles/main/layouts/handoff.scss b/frontend/resources/styles/main/layouts/handoff.scss
index 9f6a2ff8b..c41ad640d 100644
--- a/frontend/resources/styles/main/layouts/handoff.scss
+++ b/frontend/resources/styles/main/layouts/handoff.scss
@@ -17,7 +17,7 @@ $width-settings-bar: 16rem;
   }
 }
 
-.fullscreen .handoff-layout {
+.fullscreen .handoff-layout:not(.force-visible) {
   .viewer-header {
     width: 100%;
     position: fixed;
diff --git a/frontend/resources/styles/main/layouts/viewer.scss b/frontend/resources/styles/main/layouts/viewer.scss
index ed62d776c..ea6bf998a 100644
--- a/frontend/resources/styles/main/layouts/viewer.scss
+++ b/frontend/resources/styles/main/layouts/viewer.scss
@@ -15,7 +15,7 @@
   }
 }
 
-.fullscreen .viewer-layout {
+.fullscreen .viewer-layout:not(.force-visible) {
   & .viewer-header {
     width: 100%;
     position: fixed;
diff --git a/frontend/src/app/main/ui/components/dropdown.cljs b/frontend/src/app/main/ui/components/dropdown.cljs
index b7bb1f2f2..b1efae131 100644
--- a/frontend/src/app/main/ui/components/dropdown.cljs
+++ b/frontend/src/app/main/ui/components/dropdown.cljs
@@ -35,9 +35,8 @@
           (let [keys [(events/listen js/document EventType.CLICK on-click)
                       (events/listen js/document EventType.CONTEXTMENU on-click)
                       (events/listen js/document EventType.KEYUP on-keyup)]]
-            #(do (on-close)
-                 (doseq [key keys]
-                   (events/unlistenByKey key)))))]
+            #(doseq [key keys]
+               (events/unlistenByKey key))))]
 
     (mf/use-effect on-mount)
     children))
diff --git a/frontend/src/app/main/ui/dashboard/grid.cljs b/frontend/src/app/main/ui/dashboard/grid.cljs
index 56c73d75c..a7653c3f5 100644
--- a/frontend/src/app/main/ui/dashboard/grid.cljs
+++ b/frontend/src/app/main/ui/dashboard/grid.cljs
@@ -171,6 +171,12 @@
                   :edition true
                   :menu-open false)))]
 
+    (mf/use-effect
+      (mf/deps selected? local)
+      (fn []
+        (when (and (not selected?) (:menu-open @local))
+          (swap! local assoc :menu-open false))))
+
     [:div.grid-item.project-th {:class (dom/classnames
                                          :selected selected?)
                                 :ref item-ref
diff --git a/frontend/src/app/main/ui/handoff.cljs b/frontend/src/app/main/ui/handoff.cljs
index adf4a467f..9b6d9873f 100644
--- a/frontend/src/app/main/ui/handoff.cljs
+++ b/frontend/src/app/main/ui/handoff.cljs
@@ -96,7 +96,8 @@
     (mf/use-effect on-mount)
     (hooks/use-shortcuts sc/shortcuts)
 
-    [:div.handoff-layout
+    [:div.handoff-layout {:class (dom/classnames :force-visible
+                                                 (:show-thumbnails state))}
      [:& header
       {:data data
        :state state
diff --git a/frontend/src/app/main/ui/viewer.cljs b/frontend/src/app/main/ui/viewer.cljs
index 3467986d8..89fdbc91c 100644
--- a/frontend/src/app/main/ui/viewer.cljs
+++ b/frontend/src/app/main/ui/viewer.cljs
@@ -242,7 +242,8 @@
     (mf/use-effect on-mount)
     (hooks/use-shortcuts sc/shortcuts)
 
-    [:div.viewer-layout
+    [:div.viewer-layout {:class (dom/classnames :force-visible
+                                                (:show-thumbnails state))}
      [:& header
       {:data data
        :state state
diff --git a/frontend/src/app/main/ui/viewer/header.cljs b/frontend/src/app/main/ui/viewer/header.cljs
index 02e89ecdd..e2eeff8a5 100644
--- a/frontend/src/app/main/ui/viewer/header.cljs
+++ b/frontend/src/app/main/ui/viewer/header.cljs
@@ -21,7 +21,6 @@
    [app.main.ui.components.dropdown :refer [dropdown]]
    [app.main.ui.components.fullscreen :as fs]
    [app.main.ui.icons :as i]
-   [app.util.data :refer [classnames]]
    [app.util.dom :as dom]
    [app.util.i18n :as i18n :refer [t]]
    [app.util.router :as rt]