From c2ed39a36d2462a26031e983b123e4c9a437da57 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 14 Apr 2020 17:00:52 +0200 Subject: [PATCH] :bug: More bugfixes. --- frontend/deps.edn | 4 +- frontend/src/uxbox/main/data/library.cljs | 88 +++++++++---------- frontend/src/uxbox/main/store.cljs | 4 +- frontend/src/uxbox/main/ui.cljs | 2 +- frontend/src/uxbox/main/ui/dashboard.cljs | 16 ++-- .../src/uxbox/main/ui/dashboard/library.cljs | 35 +++++--- 6 files changed, 81 insertions(+), 68 deletions(-) diff --git a/frontend/deps.edn b/frontend/deps.edn index 357cef1ff..62b8a3471 100644 --- a/frontend/deps.edn +++ b/frontend/deps.edn @@ -14,10 +14,10 @@ funcool/cuerdas {:mvn/version "2020.03.26-3"} funcool/lentes {:mvn/version "1.4.0-SNAPSHOT"} - funcool/okulary {:mvn/version "2020.04.13-2"} + funcool/okulary {:mvn/version "2020.04.14-0"} funcool/potok {:mvn/version "2.8.0-SNAPSHOT"} funcool/promesa {:mvn/version "5.1.0"} - funcool/rumext {:mvn/version "2020.04.11-0"} + funcool/rumext {:mvn/version "2020.04.14-1"} } :aliases {:dev diff --git a/frontend/src/uxbox/main/data/library.cljs b/frontend/src/uxbox/main/data/library.cljs index 8f7fb3e61..f781c0f5c 100644 --- a/frontend/src/uxbox/main/data/library.cljs +++ b/frontend/src/uxbox/main/data/library.cljs @@ -14,18 +14,16 @@ [uxbox.util.router :as r] [uxbox.common.uuid :as uuid])) -(defn initialize-workspace-libraries [] - ()) - ;; Retrieve libraries (declare retrieve-libraries-result) (defn retrieve-libraries - ([type] (retrieve-libraries type uuid/zero)) - ([type team-id] + ([section] + (retrieve-libraries section uuid/zero)) + ([section team-id] (s/assert ::us/uuid team-id) - (let [method (case type + (let [method (case section :icons :icon-libraries :images :image-libraries :palettes :color-libraries)] @@ -33,38 +31,38 @@ ptk/WatchEvent (watch [_ state stream] (->> (rp/query! method {:team-id team-id}) - (rx/map (partial retrieve-libraries-result type team-id)))))))) + (rx/map (partial retrieve-libraries-result section team-id)))))))) -(defn retrieve-libraries-result [type team-id result] +(defn- retrieve-libraries-result + [section team-id result] (ptk/reify ::retrieve-libraries-result ptk/UpdateEvent (update [_ state] - (-> state - (assoc-in [:library type team-id] result))))) + (assoc-in state [:library section team-id] result)))) ;; Retrieve library data (declare retrieve-library-data-result) (defn retrieve-library-data - [type library-id] + [section library-id] (ptk/reify ::retrieve-library-data ptk/WatchEvent (watch [_ state stream] - (let [method (case type + (let [method (case section :icons :icons :images :images :palettes :colors)] (->> (rp/query! method {:library-id library-id}) - (rx/map (partial retrieve-library-data-result type library-id))))))) + (rx/map (partial retrieve-library-data-result section library-id))))))) (defn retrieve-library-data-result - [type library-id data] + [section library-id data] (ptk/reify ::retrieve-library-data-result ptk/UpdateEvent (update [_ state] (-> state - (assoc-in [:library-items type library-id] data))))) + (assoc-in [:library-items section library-id] data))))) ;; Create library @@ -72,45 +70,45 @@ (declare create-library-result) (defn create-library - [type team-id name] + [section team-id name] (ptk/reify ::create-library ptk/WatchEvent (watch [_ state stream] - (let [method (case type + (let [method (case section :icons :create-icon-library :images :create-image-library :palettes :create-color-library)] (->> (rp/mutation! method {:team-id team-id :name name}) - (rx/map (partial create-library-result type team-id))))))) + (rx/map (partial create-library-result section team-id))))))) (defn create-library-result - [type team-id result] + [section team-id result] (ptk/reify ::create-library-result ptk/UpdateEvent (update [_ state] (-> state - (update-in [:library type team-id] #(into [result] %)))))) + (update-in [:library section team-id] #(into [result] %)))))) ;; Rename library (declare rename-library-result) (defn rename-library - [type team-id library-id name] + [section team-id library-id name] (ptk/reify ::rename-library ptk/WatchEvent (watch [_ state stream] - (let [method (case type + (let [method (case section :icons :rename-icon-library :images :rename-image-library :palettes :rename-color-library)] (->> (rp/mutation! method {:id library-id :name name}) - (rx/map #(rename-library-result type team-id library-id name))))))) + (rx/map #(rename-library-result section team-id library-id name))))))) (defn rename-library-result - [type team-id library-id name] + [section team-id library-id name] (ptk/reify ::rename-library-result ptk/UpdateEvent (update [_ state] @@ -121,85 +119,85 @@ (update-fn [libraries] (map change-name libraries))] (-> state - (update-in [:library type team-id] update-fn)))))) + (update-in [:library section team-id] update-fn)))))) ;; Delete library (declare delete-library-result) (defn delete-library - [type team-id library-id] + [section team-id library-id] (ptk/reify ::delete-library ptk/UpdateEvent (update [_ state] (-> state (assoc-in [:library :last-deleted-library] library-id))) - + ptk/WatchEvent (watch [_ state stream] - (let [method (case type + (let [method (case section :icons :delete-icon-library :images :delete-image-library :palettes :delete-color-library)] (->> (rp/mutation! method {:id library-id}) - (rx/map #(delete-library-result type team-id library-id))))))) + (rx/map #(delete-library-result section team-id library-id))))))) (defn delete-library-result - [type team-id library-id] + [section team-id library-id] (ptk/reify ::create-library-result ptk/UpdateEvent (update [_ state] (let [update-fn (fn [libraries] (filterv #(not= library-id (:id %)) libraries))] (-> state - (update-in [:library type team-id] update-fn)))))) + (update-in [:library section team-id] update-fn)))))) ;; Delete library item (declare delete-item-result) (defn delete-item - [type library-id item-id] + [section library-id item-id] (ptk/reify ::delete-item ptk/WatchEvent (watch [_ state stream] - (let [method (case type + (let [method (case section :icons :delete-icon :images :delete-image :palettes :delete-color)] (->> (rp/mutation! method {:id item-id}) - (rx/map #(delete-item-result type library-id item-id))))))) + (rx/map #(delete-item-result section library-id item-id))))))) (defn delete-item-result - [type library-id item-id] + [section library-id item-id] (ptk/reify ::delete-item-result ptk/UpdateEvent (update [_ state] (let [update-fn (fn [items] (filterv #(not= item-id (:id %)) items))] (-> state - (update-in [:library-items type library-id] update-fn)))))) + (update-in [:library-items section library-id] update-fn)))))) ;; Batch delete (declare batch-delete-item-result) (defn batch-delete-item - [type library-id item-ids] + [section library-id item-ids] (ptk/reify ::batch-delete-item ptk/WatchEvent (watch [_ state stream] - (let [method (case type + (let [method (case section :icons :delete-icon :images :delete-image :palettes :delete-color)] (->> (rx/from item-ids) (rx/flat-map #(rp/mutation! method {:id %})) (rx/last) - (rx/map #(batch-delete-item-result type library-id item-ids))))))) + (rx/map #(batch-delete-item-result section library-id item-ids))))))) (defn batch-delete-item-result - [type library-id item-ids] + [section library-id item-ids] (ptk/reify ::batch-delete-item-result ptk/UpdateEvent (update [_ state] @@ -207,25 +205,25 @@ update-fn (fn [items] (filterv #(not (item-ids-set (:id %))) items))] (-> state - (update-in [:library-items type library-id] update-fn)))))) + (update-in [:library-items section library-id] update-fn)))))) ;; Workspace - select library (defn select-library - [type library-id] + [section library-id] (ptk/reify ::select-library ptk/UpdateEvent (update [_ state] (-> state - (assoc-in [:library-selected type] library-id))))) + (assoc-in [:library-selected section] library-id))))) ;; Workspace - change library filter (defn change-library-filter - [type filter] + [section filter] (ptk/reify ::change-library-filter ptk/UpdateEvent (update [_ state] (-> state - (assoc-in [:library-filter type] filter))))) + (assoc-in [:library-filter section] filter))))) diff --git a/frontend/src/uxbox/main/store.cljs b/frontend/src/uxbox/main/store.cljs index 44e0842d8..557792890 100644 --- a/frontend/src/uxbox/main/store.cljs +++ b/frontend/src/uxbox/main/store.cljs @@ -18,8 +18,8 @@ (def ^:dynamic *on-error* identity) -(defonce state (atom {})) -(defonce loader (atom false)) +(defonce state (l/atom {})) +(defonce loader (l/atom false)) (defonce store (ptk/store {:on-error #(*on-error* %)})) (defonce stream (ptk/input-stream store)) diff --git a/frontend/src/uxbox/main/ui.cljs b/frontend/src/uxbox/main/ui.cljs index bc2562d8b..fc0790045 100644 --- a/frontend/src/uxbox/main/ui.cljs +++ b/frontend/src/uxbox/main/ui.cljs @@ -139,7 +139,7 @@ [] (let [route (mf/deref refs/route)] (when route - [:& app-container {:route route :key (get-in route [:data :name])}]))) + [:& app-container {:route route}]))) ;; --- Error Handling diff --git a/frontend/src/uxbox/main/ui/dashboard.cljs b/frontend/src/uxbox/main/ui/dashboard.cljs index 6c610d266..8632d8d03 100644 --- a/frontend/src/uxbox/main/ui/dashboard.cljs +++ b/frontend/src/uxbox/main/ui/dashboard.cljs @@ -75,10 +75,10 @@ [:div.dashboard-content (case page :dashboard-search - (mf/element search-page #js {:team-id team-id :search-term search-term}) + [:& search-page {:team-id team-id :search-term search-term}] :dashboard-team - (mf/element recent-files-page #js {:team-id team-id}) + [:& recent-files-page {:team-id team-id}] (:dashboard-library-icons :dashboard-library-icons-index @@ -86,11 +86,11 @@ :dashboard-library-images-index :dashboard-library-palettes :dashboard-library-palettes-index) - (mf/element library-page #js {:key library-id - :team-id team-id - :library-id library-id - :section library-section}) + [:& library-page {:key (str library-id) + :team-id team-id + :library-id library-id + :section library-section}] :dashboard-project - (mf/element project-page #js {:team-id team-id - :project-id project-id}))]]])) + [:& project-page {:team-id team-id + :project-id project-id}])]]])) diff --git a/frontend/src/uxbox/main/ui/dashboard/library.cljs b/frontend/src/uxbox/main/ui/dashboard/library.cljs index 4f8afe504..5f7c37841 100644 --- a/frontend/src/uxbox/main/ui/dashboard/library.cljs +++ b/frontend/src/uxbox/main/ui/dashboard/library.cljs @@ -301,25 +301,40 @@ :message "Are you sure you want to delete this color?" :accept-text "Delete"}))]]}]]]))) -(defn libraries-ref [section team-id] - (-> (l/in [:library section team-id]) - (l/derived st/state))) +(defn- make-libraries-ref + [section team-id] + #(-> (l/in [:library section team-id]) + (l/derived st/state =))) -(defn selected-items-ref [section library-id] - (-> (l/in [:library-items section library-id]) - (l/derived st/state))) +(defn- make-library-items-ref + [section library-id] + #(-> (l/in [:library-items section library-id]) + (l/derived st/state =))) (def last-deleted-library-ref (-> (l/in [:library :last-deleted-library]) - (l/derived st/state))) + (l/derived st/state =))) + +(defonce counter (atom 0)) (mf/defc library-page [{:keys [team-id library-id section]}] (let [state (mf/use-state {:selected #{}}) - libraries (mf/deref (libraries-ref section team-id)) - items (mf/deref (selected-items-ref section library-id)) + libs-ref (mf/use-memo + (mf/deps section team-id) + (make-libraries-ref section team-id)) + + libraries (mf/deref libs-ref) + items-ref (mf/use-memo + (mf/deps section library-id) + (make-library-items-ref section library-id)) + + items (mf/deref items-ref) + last-deleted-library (mf/deref last-deleted-library-ref) - selected-library (first (filter #(= (:id %) library-id) libraries))] + selected-library (first (filter #(= (:id %) library-id) libraries)) + + ] (mf/use-effect (mf/deps libraries)