From 77ab0706be6780e2fe3f1160d1a74aa6f931a043 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 20 May 2021 16:55:57 +0200 Subject: [PATCH] :bug: Fix some issues on recent files loading. --- frontend/src/app/main/data/workspace.cljs | 2 +- .../app/main/ui/dashboard/project_menu.cljs | 42 ++++++++----------- .../src/app/main/ui/dashboard/projects.cljs | 22 ++++++---- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 9e034d6be..1d42177dc 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1254,7 +1254,7 @@ (ptk/reify ::go-to-dashboard ptk/WatchEvent (watch [it state stream] - (let [team-id (or team-id (get-in state [:workspace-project :team-id]))] + (when-let [team-id (or team-id (:current-team-id state))] (rx/of ::dwp/force-persist (rt/nav :dashboard-projects {:team-id team-id}))))))) diff --git a/frontend/src/app/main/ui/dashboard/project_menu.cljs b/frontend/src/app/main/ui/dashboard/project_menu.cljs index 73cf15978..946478a09 100644 --- a/frontend/src/app/main/ui/dashboard/project_menu.cljs +++ b/frontend/src/app/main/ui/dashboard/project_menu.cljs @@ -9,6 +9,7 @@ [app.main.data.dashboard :as dd] [app.main.data.messages :as dm] [app.main.data.modal :as modal] + [app.main.refs :as refs] [app.main.repo :as rp] [app.main.store :as st] [app.main.ui.components.context-menu :refer [context-menu]] @@ -28,7 +29,8 @@ left (or left 0) current-team-id (mf/use-ctx ctx/current-team-id) - teams (mf/use-state nil) + teams (mf/deref refs/teams) + teams (-> teams (dissoc current-team-id) vals vec) on-duplicate-success (fn [new-project] @@ -71,27 +73,19 @@ :accept-label (tr "modals.delete-project-confirm.accept") :on-accept delete-fn}))] - (mf/use-effect - (fn [] - (->> (rp/query! :teams) - (rx/map (fn [teams] - (into [] (remove #(= (:id %) current-team-id)) teams))) - (rx/subs #(reset! teams %))))) - - (when @teams - [:& context-menu {:on-close on-menu-close - :show show? - :fixed? (or (not= top 0) (not= left 0)) - :min-width? true - :top top - :left left - :options [[(tr "labels.rename") on-edit] - [(tr "dashboard.duplicate") on-duplicate] - [(tr "dashboard.pin-unpin") toggle-pin] - (when (seq @teams) - [(tr "dashboard.move-to") nil - (for [team @teams] - [(:name team) (on-move (:id team))])]) - [:separator] - [(tr "labels.delete") on-delete]]}]))) + [:& context-menu {:on-close on-menu-close + :show show? + :fixed? (or (not= top 0) (not= left 0)) + :min-width? true + :top top + :left left + :options [[(tr "labels.rename") on-edit] + [(tr "dashboard.duplicate") on-duplicate] + [(tr "dashboard.pin-unpin") toggle-pin] + (when (seq teams) + [(tr "dashboard.move-to") nil + (for [team teams] + [(:name team) (on-move (:id team))])]) + [:separator] + [(tr "labels.delete") on-delete]]}])) diff --git a/frontend/src/app/main/ui/dashboard/projects.cljs b/frontend/src/app/main/ui/dashboard/projects.cljs index 41e5b895c..911f6afc4 100644 --- a/frontend/src/app/main/ui/dashboard/projects.cljs +++ b/frontend/src/app/main/ui/dashboard/projects.cljs @@ -115,12 +115,15 @@ (if (:is-default project) (tr "labels.drafts") (:name project))]) - [:& project-menu {:project project - :show? (:menu-open @local) - :left (:x (:menu-pos @local)) - :top (:y (:menu-pos @local)) - :on-edit on-edit-open - :on-menu-close on-menu-close}] + + (when (:menu-open @local) + [:& project-menu {:project project + :show? (:menu-open @local) + :left (:x (:menu-pos @local)) + :top (:y (:menu-pos @local)) + :on-edit on-edit-open + :on-menu-close on-menu-close}]) + [:span.info (str file-count " files")] (when (> file-count 0) (let [time (-> (:modified-at project) @@ -147,8 +150,7 @@ (let [projects (->> (vals projects) (sort-by :modified-at) (reverse)) - recent-map (mf/deref recent-files-ref) - files (vals recent-map)] + recent-map (mf/deref recent-files-ref)] (mf/use-effect (mf/deps team) @@ -167,7 +169,9 @@ [:& header] [:section.dashboard-container (for [{:keys [id] :as project} projects] - (let [files (some->> files (filterv #(= id (:project-id %))))] + (let [files (when recent-map + (->> (vals recent-map) + (filterv #(= id (:project-id %)))))] [:& project-item {:project project :files files :first? (= project (first projects))