mirror of
https://github.com/penpot/penpot.git
synced 2026-02-12 14:42:56 +00:00
Move image collections state transformations functions into data ns.
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
[uuid.core :as uuid]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.state :as st]
|
||||
[uxbox.state.images :as sti]
|
||||
[uxbox.repo :as rp]))
|
||||
|
||||
;; --- Initialize
|
||||
@@ -46,7 +45,10 @@
|
||||
(defrecord CollectionsFetched [items]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(reduce sti/assoc-collection state items)))
|
||||
(reduce (fn [acc {:keys [id] :as item}]
|
||||
(assoc-in acc [:images-by-id id] item))
|
||||
state
|
||||
items)))
|
||||
|
||||
(defn collections-fetched
|
||||
[items]
|
||||
@@ -71,7 +73,7 @@
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(-> state
|
||||
(sti/assoc-collection item)
|
||||
(assoc-in [:images-by-id (:id item)] item)
|
||||
(assoc-in [:dashboard :collection-id] (:id item))
|
||||
(assoc-in [:dashboard :collection-type] :own))))
|
||||
|
||||
@@ -143,7 +145,7 @@
|
||||
(defrecord DeleteCollection [id]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(sti/dissoc-collection state id))
|
||||
(update state :images-by-id dissoc id))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
@@ -218,7 +220,7 @@
|
||||
(defrecord DeleteImage [coll-id image]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(sti/dissoc-image state coll-id image))
|
||||
(update-in state [:images-by-id coll-id :images] disj image))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
(ns uxbox.state.images)
|
||||
|
||||
(defn assoc-collection
|
||||
"A reduce function for assoc the image collection
|
||||
to the state map."
|
||||
[state coll]
|
||||
(let [id (:id coll)]
|
||||
(assoc-in state [:images-by-id id] coll)))
|
||||
|
||||
(defn dissoc-collection
|
||||
"A reduce function for dissoc the image collection
|
||||
to the state map."
|
||||
[state id]
|
||||
(update state :images-by-id dissoc id))
|
||||
|
||||
(defn select-first-collection
|
||||
"A reduce function for select the first image collection
|
||||
to the state map."
|
||||
[state]
|
||||
(let [colls (sort-by :id (vals (:images-by-id state)))]
|
||||
(assoc-in state [:dashboard :collection-id] (:id (first colls)))))
|
||||
|
||||
(defn dissoc-image
|
||||
"A reduce function for dissoc the image collection
|
||||
to the state map."
|
||||
[state coll-id image]
|
||||
(update-in state [:images-by-id coll-id :images] disj image))
|
||||
Reference in New Issue
Block a user