0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 15:39:50 -05:00

Refactor image storage layout.

This commit is contained in:
Andrey Antukh 2016-10-08 22:54:59 +02:00
parent 5762ee0bf3
commit 841e178c15
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -57,19 +57,22 @@
(-> (l/in [:dashboard :images]) (-> (l/in [:dashboard :images])
(l/derive st/state))) (l/derive st/state)))
(def ^:private collections-map-ref (def ^:private collections-ref
(-> (comp (l/key :image-colls-by-id) (-> (l/key :image-colls-by-id)
(ul/merge library/+image-collections-by-id+))
(l/derive st/state))) (l/derive st/state)))
(def ^:private collections-ref (def ^:private images-ref
(-> (l/lens vals) (-> (l/key :images-by-id)
(l/derive collections-map-ref))) (l/derive st/state)))
(defn- focus-collection ;; (def ^:private collections-ref
[id] ;; (-> (l/lens vals)
(-> (l/key id) ;; (l/derive collections-map-ref)))
(l/derive collections-map-ref)))
;; (defn- focus-collection
;; [id]
;; (-> (l/key id)
;; (l/derive collections-map-ref)))
;; --- Page Title ;; --- Page Title
@ -131,7 +134,7 @@
(let [type (:type collection) (let [type (:type collection)
id (:id collection)] id (:id collection)]
(rs/emit! (di/select-collection type id))))] (rs/emit! (di/select-collection type id))))]
(let [images (count (:images collection))] (let [images (count (:images collection []))]
[:li {:on-click on-click [:li {:on-click on-click
:class-name (when selected? "current")} :class-name (when selected? "current")}
[:span.element-title (:name collection)] [:span.element-title (:name collection)]
@ -140,10 +143,10 @@
(mx/defc nav-section (mx/defc nav-section
{:mixins [mx/static mx/reactive]} {:mixins [mx/static mx/reactive]}
[type selected] [type selected colls]
(let [own? (= type :own) (let [own? (= type :own)
builtin? (= type :builtin) builtin? (= type :builtin)
collections (cond->> (mx/react collections-ref) collections (cond->> (vals colls)
own? (filter #(= :own (:type %))) own? (filter #(= :own (:type %)))
builtin? (filter #(= :builtin (:type %))) builtin? (filter #(= :builtin (:type %)))
own? (sort-by :id))] own? (sort-by :id))]
@ -160,17 +163,16 @@
(mx/with-key key)))])) (mx/with-key key)))]))
(mx/defc nav (mx/defc nav
{:mixins [mx/static mx/reactive]} {:mixins [mx/static]}
[] [{:keys [type id] :as state} colls]
(let [dashboard (mx/react dashboard-ref) (let [own? (= type :own)
collections (mx/react collections-ref)
selected (:id dashboard)
type (:type dashboard)
own? (= type :own)
builtin? (= type :builtin)] builtin? (= type :builtin)]
(letfn [(select-tab [type] (letfn [(select-tab [type]
(let [xf (filter #(= type (:type %))) (let [xf (comp
colls (sequence xf collections)] (map second)
(filter #(= type (:type %))))
colls (into [] xf colls)
colls (sort-by :id colls)]
(if-let [item (first colls)] (if-let [item (first colls)]
(rs/emit! (di/select-collection type (:id item))) (rs/emit! (di/select-collection type (:id item)))
(rs/emit! (di/select-collection type)))))] (rs/emit! (di/select-collection type)))))]
@ -183,7 +185,7 @@
[:li {:class-name (when own? "current") [:li {:class-name (when own? "current")
:on-click (partial select-tab :own)} :on-click (partial select-tab :own)}
"YOUR LIBRARIES"]] "YOUR LIBRARIES"]]
(nav-section type selected)]]))) (nav-section type id colls)]])))
;; --- Grid ;; --- Grid
@ -248,13 +250,14 @@
[:span (:name image)]])) [:span (:name image)]]))
(mx/defc grid (mx/defc grid
{:mixins [mx/static]} {:mixins [mx/static mx/reactive]}
[state selected {:keys [id type images] :as coll}] [{:keys [id type selected] :as state}]
(let [own? (= type :own) (let [filtering (:filter state)
ordering (:order state) ordering (:order state)
filtering (:filter state) own? (= type :own)
images (->> images images (rum/react images-ref)
(remove nil?) images (->> (vals images)
(filter #(= id (:collection %)))
(filter-images-by filtering) (filter-images-by filtering)
(sort-images-by ordering))] (sort-images-by ordering))]
[:div.dashboard-grid-content [:div.dashboard-grid-content
@ -269,23 +272,22 @@
(mx/defc content (mx/defc content
{:mixins [mx/static]} {:mixins [mx/static]}
[state coll] [{:keys [type id selected] :as state} coll]
(let [selected (:selected state) (let [own? (= type :own)]
coll-type (:type coll)
own? (= coll-type :own)]
(when coll (when coll
[:section.dashboard-grid.library [:section.dashboard-grid.library
(page-title coll) (page-title coll)
(grid state selected coll) (grid state)
(when (and (seq selected)) (when (seq selected)
(grid-options coll))]))) (grid-options coll))])))
;; --- Menu ;; --- Menu
(mx/defc menu (mx/defc menu
{:mixins [mx/static]} {:mixins [mx/static mx/reactive]}
[state coll] [coll]
(let [ordering (:order state :name) (let [state (mx/react dashboard-ref)
ordering (:order state :name)
filtering (:filter state "") filtering (:filter state "")
icount (count (:images coll))] icount (count (:images coll))]
(letfn [(on-term-change [event] (letfn [(on-term-change [event]
@ -346,13 +348,13 @@
{:will-mount images-page-will-mount {:will-mount images-page-will-mount
:did-remount images-page-did-remount :did-remount images-page-did-remount
:mixins [mx/static mx/reactive]} :mixins [mx/static mx/reactive]}
[type id] [_ _]
(let [state (mx/react dashboard-ref) (let [state (mx/react dashboard-ref)
coll-id (:id state) colls (mx/react collections-ref)
coll (mx/react (focus-collection coll-id))] coll (get colls (:id state))]
[:main.dashboard-main [:main.dashboard-main
(header) (header)
[:section.dashboard-content [:section.dashboard-content
(nav) (nav state colls)
(menu state coll) (menu coll)
(content state coll)]])) (content state coll)]]))