From 1305ab3cc698ba2958bae3f7c8864aa39eab16ad Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 16 Apr 2025 18:19:34 +0200 Subject: [PATCH] :bug: Fix issue with empty placeholder on team change --- frontend/src/app/main/ui/dashboard/grid.cljs | 2 ++ .../app/main/ui/dashboard/placeholder.cljs | 31 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/main/ui/dashboard/grid.cljs b/frontend/src/app/main/ui/dashboard/grid.cljs index fd5804760b..0cfa341b56 100644 --- a/frontend/src/app/main/ui/dashboard/grid.cljs +++ b/frontend/src/app/main/ui/dashboard/grid.cljs @@ -534,6 +534,7 @@ :create-fn create-fn :origin origin :project-id project-id + :team-id team-id :on-finish-import on-finish-import}])])) (mf/defc line-grid-row @@ -662,4 +663,5 @@ :can-edit can-edit :create-fn create-fn :project-id project-id + :team-id team-id :on-finish-import on-finish-import}])])) diff --git a/frontend/src/app/main/ui/dashboard/placeholder.cljs b/frontend/src/app/main/ui/dashboard/placeholder.cljs index ce6177dacc..adfc3b42e0 100644 --- a/frontend/src/app/main/ui/dashboard/placeholder.cljs +++ b/frontend/src/app/main/ui/dashboard/placeholder.cljs @@ -8,7 +8,6 @@ (:require-macros [app.main.style :as stl]) (:require [app.main.data.event :as ev] - [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.dashboard.import :as udi] [app.main.ui.ds.product.empty-placeholder :refer [empty-placeholder*]] @@ -16,12 +15,13 @@ [app.main.ui.icons :as i] [app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]] + [okulary.core :as l] [potok.v2.core :as ptk] [rumext.v2 :as mf])) (mf/defc empty-placeholder-projects* {::mf/wrap-props false} - [{:keys [on-create on-finish-import project-id] :as props}] + [{:keys [on-create on-finish-import project-id]}] (let [file-input (mf/use-ref nil) on-add-library (mf/use-fn (fn [_] @@ -48,17 +48,38 @@ :project-id project-id :on-finish-import on-finish-import}]])) +(defn- make-has-other-files-or-projects-ref + "Return a ref that resolves to true or false if there are at least some + file or some project (a part of the default) exists; this determines + if we need to show a complete placeholder or the small one." + [team-id] + (l/derived (fn [state] + (or (let [projects (get state :projects)] + (some (fn [[_ project]] + (and (= (:team-id project) team-id) + (not (:is-default project)))) + projects)) + (let [files (get state :files)] + (some (fn [[_ file]] + (= (:team-id file) team-id)) + files)))) + st/state)) + (mf/defc empty-placeholder - [{:keys [dragging? limit origin create-fn can-edit project-id on-finish-import]}] + [{:keys [dragging? limit origin create-fn can-edit team-id project-id on-finish-import]}] (let [on-click (mf/use-fn (mf/deps create-fn) (fn [_] (create-fn "dashboard:empty-folder-placeholder"))) + show-text (mf/use-state nil) on-mouse-enter (mf/use-fn #(reset! show-text true)) on-mouse-leave (mf/use-fn #(reset! show-text nil)) - files (mf/deref refs/files)] + + has-other* (mf/with-memo [team-id] + (make-has-other-files-or-projects-ref team-id)) + has-other? (mf/deref has-other*)] (cond (true? dragging?) [:ul @@ -80,7 +101,7 @@ :tag-name "span"}])] :else - (if (= (count files) 0) + (if-not has-other? [:> empty-placeholder-projects* {:on-create on-click :on-finish-import on-finish-import :project-id project-id}] [:div {:class (stl/css :grid-empty-placeholder)} [:button {:class (stl/css :create-new)