🐛 More bugfixes.

This commit is contained in:
Andrey Antukh 2020-04-14 17:00:52 +02:00
parent b24307cf35
commit c2ed39a36d
6 changed files with 81 additions and 68 deletions

View file

@ -14,10 +14,10 @@
funcool/cuerdas {:mvn/version "2020.03.26-3"} funcool/cuerdas {:mvn/version "2020.03.26-3"}
funcool/lentes {:mvn/version "1.4.0-SNAPSHOT"} 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/potok {:mvn/version "2.8.0-SNAPSHOT"}
funcool/promesa {:mvn/version "5.1.0"} funcool/promesa {:mvn/version "5.1.0"}
funcool/rumext {:mvn/version "2020.04.11-0"} funcool/rumext {:mvn/version "2020.04.14-1"}
} }
:aliases :aliases
{:dev {:dev

View file

@ -14,18 +14,16 @@
[uxbox.util.router :as r] [uxbox.util.router :as r]
[uxbox.common.uuid :as uuid])) [uxbox.common.uuid :as uuid]))
(defn initialize-workspace-libraries []
())
;; Retrieve libraries ;; Retrieve libraries
(declare retrieve-libraries-result) (declare retrieve-libraries-result)
(defn retrieve-libraries (defn retrieve-libraries
([type] (retrieve-libraries type uuid/zero)) ([section]
([type team-id] (retrieve-libraries section uuid/zero))
([section team-id]
(s/assert ::us/uuid team-id) (s/assert ::us/uuid team-id)
(let [method (case type (let [method (case section
:icons :icon-libraries :icons :icon-libraries
:images :image-libraries :images :image-libraries
:palettes :color-libraries)] :palettes :color-libraries)]
@ -33,38 +31,38 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(->> (rp/query! method {:team-id team-id}) (->> (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/reify ::retrieve-libraries-result
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (assoc-in state [:library section team-id] result))))
(assoc-in [:library type team-id] result)))))
;; Retrieve library data ;; Retrieve library data
(declare retrieve-library-data-result) (declare retrieve-library-data-result)
(defn retrieve-library-data (defn retrieve-library-data
[type library-id] [section library-id]
(ptk/reify ::retrieve-library-data (ptk/reify ::retrieve-library-data
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [method (case type (let [method (case section
:icons :icons :icons :icons
:images :images :images :images
:palettes :colors)] :palettes :colors)]
(->> (rp/query! method {:library-id library-id}) (->> (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 (defn retrieve-library-data-result
[type library-id data] [section library-id data]
(ptk/reify ::retrieve-library-data-result (ptk/reify ::retrieve-library-data-result
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (-> state
(assoc-in [:library-items type library-id] data))))) (assoc-in [:library-items section library-id] data)))))
;; Create library ;; Create library
@ -72,45 +70,45 @@
(declare create-library-result) (declare create-library-result)
(defn create-library (defn create-library
[type team-id name] [section team-id name]
(ptk/reify ::create-library (ptk/reify ::create-library
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [method (case type (let [method (case section
:icons :create-icon-library :icons :create-icon-library
:images :create-image-library :images :create-image-library
:palettes :create-color-library)] :palettes :create-color-library)]
(->> (rp/mutation! method {:team-id team-id (->> (rp/mutation! method {:team-id team-id
:name name}) :name name})
(rx/map (partial create-library-result type team-id))))))) (rx/map (partial create-library-result section team-id)))))))
(defn create-library-result (defn create-library-result
[type team-id result] [section team-id result]
(ptk/reify ::create-library-result (ptk/reify ::create-library-result
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (-> state
(update-in [:library type team-id] #(into [result] %)))))) (update-in [:library section team-id] #(into [result] %))))))
;; Rename library ;; Rename library
(declare rename-library-result) (declare rename-library-result)
(defn rename-library (defn rename-library
[type team-id library-id name] [section team-id library-id name]
(ptk/reify ::rename-library (ptk/reify ::rename-library
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [method (case type (let [method (case section
:icons :rename-icon-library :icons :rename-icon-library
:images :rename-image-library :images :rename-image-library
:palettes :rename-color-library)] :palettes :rename-color-library)]
(->> (rp/mutation! method {:id library-id (->> (rp/mutation! method {:id library-id
:name name}) :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 (defn rename-library-result
[type team-id library-id name] [section team-id library-id name]
(ptk/reify ::rename-library-result (ptk/reify ::rename-library-result
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -121,85 +119,85 @@
(update-fn [libraries] (map change-name libraries))] (update-fn [libraries] (map change-name libraries))]
(-> state (-> state
(update-in [:library type team-id] update-fn)))))) (update-in [:library section team-id] update-fn))))))
;; Delete library ;; Delete library
(declare delete-library-result) (declare delete-library-result)
(defn delete-library (defn delete-library
[type team-id library-id] [section team-id library-id]
(ptk/reify ::delete-library (ptk/reify ::delete-library
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (-> state
(assoc-in [:library :last-deleted-library] library-id))) (assoc-in [:library :last-deleted-library] library-id)))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [method (case type (let [method (case section
:icons :delete-icon-library :icons :delete-icon-library
:images :delete-image-library :images :delete-image-library
:palettes :delete-color-library)] :palettes :delete-color-library)]
(->> (rp/mutation! method {:id library-id}) (->> (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 (defn delete-library-result
[type team-id library-id] [section team-id library-id]
(ptk/reify ::create-library-result (ptk/reify ::create-library-result
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [update-fn (fn [libraries] (let [update-fn (fn [libraries]
(filterv #(not= library-id (:id %)) libraries))] (filterv #(not= library-id (:id %)) libraries))]
(-> state (-> state
(update-in [:library type team-id] update-fn)))))) (update-in [:library section team-id] update-fn))))))
;; Delete library item ;; Delete library item
(declare delete-item-result) (declare delete-item-result)
(defn delete-item (defn delete-item
[type library-id item-id] [section library-id item-id]
(ptk/reify ::delete-item (ptk/reify ::delete-item
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [method (case type (let [method (case section
:icons :delete-icon :icons :delete-icon
:images :delete-image :images :delete-image
:palettes :delete-color)] :palettes :delete-color)]
(->> (rp/mutation! method {:id item-id}) (->> (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 (defn delete-item-result
[type library-id item-id] [section library-id item-id]
(ptk/reify ::delete-item-result (ptk/reify ::delete-item-result
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [update-fn (fn [items] (let [update-fn (fn [items]
(filterv #(not= item-id (:id %)) items))] (filterv #(not= item-id (:id %)) items))]
(-> state (-> state
(update-in [:library-items type library-id] update-fn)))))) (update-in [:library-items section library-id] update-fn))))))
;; Batch delete ;; Batch delete
(declare batch-delete-item-result) (declare batch-delete-item-result)
(defn batch-delete-item (defn batch-delete-item
[type library-id item-ids] [section library-id item-ids]
(ptk/reify ::batch-delete-item (ptk/reify ::batch-delete-item
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [method (case type (let [method (case section
:icons :delete-icon :icons :delete-icon
:images :delete-image :images :delete-image
:palettes :delete-color)] :palettes :delete-color)]
(->> (rx/from item-ids) (->> (rx/from item-ids)
(rx/flat-map #(rp/mutation! method {:id %})) (rx/flat-map #(rp/mutation! method {:id %}))
(rx/last) (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 (defn batch-delete-item-result
[type library-id item-ids] [section library-id item-ids]
(ptk/reify ::batch-delete-item-result (ptk/reify ::batch-delete-item-result
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -207,25 +205,25 @@
update-fn (fn [items] update-fn (fn [items]
(filterv #(not (item-ids-set (:id %))) items))] (filterv #(not (item-ids-set (:id %))) items))]
(-> state (-> state
(update-in [:library-items type library-id] update-fn)))))) (update-in [:library-items section library-id] update-fn))))))
;; Workspace - select library ;; Workspace - select library
(defn select-library (defn select-library
[type library-id] [section library-id]
(ptk/reify ::select-library (ptk/reify ::select-library
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (-> state
(assoc-in [:library-selected type] library-id))))) (assoc-in [:library-selected section] library-id)))))
;; Workspace - change library filter ;; Workspace - change library filter
(defn change-library-filter (defn change-library-filter
[type filter] [section filter]
(ptk/reify ::change-library-filter (ptk/reify ::change-library-filter
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(-> state (-> state
(assoc-in [:library-filter type] filter))))) (assoc-in [:library-filter section] filter)))))

View file

@ -18,8 +18,8 @@
(def ^:dynamic *on-error* identity) (def ^:dynamic *on-error* identity)
(defonce state (atom {})) (defonce state (l/atom {}))
(defonce loader (atom false)) (defonce loader (l/atom false))
(defonce store (ptk/store {:on-error #(*on-error* %)})) (defonce store (ptk/store {:on-error #(*on-error* %)}))
(defonce stream (ptk/input-stream store)) (defonce stream (ptk/input-stream store))

View file

@ -139,7 +139,7 @@
[] []
(let [route (mf/deref refs/route)] (let [route (mf/deref refs/route)]
(when route (when route
[:& app-container {:route route :key (get-in route [:data :name])}]))) [:& app-container {:route route}])))
;; --- Error Handling ;; --- Error Handling

View file

@ -75,10 +75,10 @@
[:div.dashboard-content [:div.dashboard-content
(case page (case page
:dashboard-search :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 :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
:dashboard-library-icons-index :dashboard-library-icons-index
@ -86,11 +86,11 @@
:dashboard-library-images-index :dashboard-library-images-index
:dashboard-library-palettes :dashboard-library-palettes
:dashboard-library-palettes-index) :dashboard-library-palettes-index)
(mf/element library-page #js {:key library-id [:& library-page {:key (str library-id)
:team-id team-id :team-id team-id
:library-id library-id :library-id library-id
:section library-section}) :section library-section}]
:dashboard-project :dashboard-project
(mf/element project-page #js {:team-id team-id [:& project-page {:team-id team-id
:project-id project-id}))]]])) :project-id project-id}])]]]))

View file

@ -301,25 +301,40 @@
:message "Are you sure you want to delete this color?" :message "Are you sure you want to delete this color?"
:accept-text "Delete"}))]]}]]]))) :accept-text "Delete"}))]]}]]])))
(defn libraries-ref [section team-id] (defn- make-libraries-ref
(-> (l/in [:library section team-id]) [section team-id]
(l/derived st/state))) #(-> (l/in [:library section team-id])
(l/derived st/state =)))
(defn selected-items-ref [section library-id] (defn- make-library-items-ref
(-> (l/in [:library-items section library-id]) [section library-id]
(l/derived st/state))) #(-> (l/in [:library-items section library-id])
(l/derived st/state =)))
(def last-deleted-library-ref (def last-deleted-library-ref
(-> (l/in [:library :last-deleted-library]) (-> (l/in [:library :last-deleted-library])
(l/derived st/state))) (l/derived st/state =)))
(defonce counter (atom 0))
(mf/defc library-page (mf/defc library-page
[{:keys [team-id library-id section]}] [{:keys [team-id library-id section]}]
(let [state (mf/use-state {:selected #{}}) (let [state (mf/use-state {:selected #{}})
libraries (mf/deref (libraries-ref section team-id)) libs-ref (mf/use-memo
items (mf/deref (selected-items-ref section library-id)) (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) 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/use-effect
(mf/deps libraries) (mf/deps libraries)