0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 00:01:51 -05:00

fix(frontend): fix many issues on dashboard collections

This commit is contained in:
Andrey Antukh 2019-07-02 21:17:39 +02:00
parent 7c1168e797
commit ef47563055
5 changed files with 59 additions and 76 deletions

View file

@ -5,16 +5,17 @@
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.main.data.colors
(:require [clojure.set :as set]
[beicon.core :as rx]
[uxbox.util.time :as dt]
[uxbox.util.uuid :as uuid]
[potok.core :as ptk]
[uxbox.util.i18n :refer [tr]]
[uxbox.util.router :as r]
[uxbox.util.color :as color]
[uxbox.main.store :as st]
[uxbox.main.repo :as rp]))
(:require
[beicon.core :as rx]
[clojure.set :as set]
[potok.core :as ptk]
[uxbox.main.repo :as rp]
[uxbox.main.store :as st]
[uxbox.util.color :as color]
[uxbox.util.i18n :refer [tr]]
[uxbox.util.router :as rt]
[uxbox.util.time :as dt]
[uxbox.util.uuid :as uuid]))
;; --- Initialize
@ -39,23 +40,9 @@
(defn initialize
[type id]
(prn "colors$initialize" type id)
(Initialize. type id))
;; --- Select a Collection
(defrecord SelectCollection [type id]
ptk/WatchEvent
(watch [_ state stream]
(rx/of (r/navigate :dashboard/colors
{:type type :id id}))))
(defn select-collection
([type]
(select-collection type nil))
([type id]
{:pre [(keyword? type)]}
(SelectCollection. type id)))
;; --- Collections Fetched
(defrecord CollectionsFetched [data]
@ -103,7 +90,7 @@
ptk/WatchEvent
(watch [_ state stream]
(rx/of (persist-collections)
(select-collection :own id))))
(rt/nav :dashboard/colors nil {:type :own :id id}))))
(defn create-collection
[]
@ -120,10 +107,10 @@
version (or (get state ::version) -1)
value (->> (get state :colors-collections)
(into {} xform))
store {:key "color-collections"
:version version
:value value}]
(->> (rp/req :update/kvstore store)
data {:id "color-collections"
:version version
:value value}]
(->> (rp/req :update/kvstore data)
(rx/map :payload)
(rx/map collections-fetched)))))
@ -157,7 +144,7 @@
(watch [_ state s]
(let [type (get-in state [:dashboard :colors :type])]
(rx/of (persist-collections)
(select-collection type)))))
(rt/nav :dashboard/colors nil {:type type})))))
(defn delete-collection
[id]

View file

@ -23,7 +23,7 @@
response))))))
(defmethod request :update/kvstore
[_ data]
(let [url (str url "/kvstore")
[_ {:keys [id] :as data}]
(let [url (str url "/kvstore/" id)
params {:url url :method :put :body data}]
(send! params)))

View file

@ -6,23 +6,25 @@
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.main.ui.dashboard.colors
(:require [cuerdas.core :as str]
[lentes.core :as l]
[rumext.core :as mx :include-macros true]
[uxbox.main.data.colors :as dc]
[uxbox.main.data.dashboard :as dd]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.store :as st]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.main.ui.colorpicker :refer [colorpicker]]
[uxbox.main.ui.dashboard.header :refer [header]]
[uxbox.builtins.icons :as i]
[uxbox.main.ui.keyboard :as k]
[uxbox.main.ui.lightbox :as lbx]
[uxbox.util.color :refer [hex->rgb]]
[uxbox.util.dom :as dom]
[uxbox.util.i18n :as t :refer [tr]]
[uxbox.util.lens :as ul]))
(:require
[cuerdas.core :as str]
[lentes.core :as l]
[rumext.core :as mx :include-macros true]
[uxbox.builtins.icons :as i]
[uxbox.main.data.colors :as dc]
[uxbox.main.data.dashboard :as dd]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.store :as st]
[uxbox.main.ui.colorpicker :refer [colorpicker]]
[uxbox.main.ui.dashboard.header :refer [header]]
[uxbox.main.ui.keyboard :as k]
[uxbox.main.ui.lightbox :as lbx]
[uxbox.main.ui.messages :refer [messages-widget]]
[uxbox.util.color :refer [hex->rgb]]
[uxbox.util.dom :as dom]
[uxbox.util.i18n :as t :refer [tr]]
[uxbox.util.lens :as ul]
[uxbox.util.router :as rt]))
;; --- Refs
@ -93,7 +95,7 @@
editable? (= type :own)]
(letfn [(on-click [event]
(let [type (or type :own)]
(st/emit! (dc/select-collection type id))))
(st/emit! (rt/navigate :dashboard/colors nil {:type type :id id}))))
(on-input-change [event]
(let [value (dom/get-target event)
value (dom/get-value value)]
@ -137,7 +139,8 @@
[:ul.library-elements {}
(when own?
[:li {}
[:a.btn-primary {:on-click #(st/emit! (dc/create-collection))} (tr "ds.colors-collection.new")]])
[:a.btn-primary {:on-click #(st/emit! (dc/create-collection))}
(tr "ds.colors-collection.new")]])
(for [coll colls]
(let [id (:id coll)
selected? (= id selected)]
@ -146,18 +149,15 @@
(mx/defc nav
{:mixins [mx/static]}
[{:keys [id type] :as state} colls]
[{:keys [id type] :as state} colls]2
(letfn [(select-tab [type]
(if (= type :own)
(st/emit! (dc/select-collection type))
(let [coll (->> (map second colls)
(filter #(= type (:type %)))
(sort-by :created-at)
(first))]
(if coll
(st/emit! (dc/select-collection type (:id coll)))
(st/emit! (dc/select-collection type))))))]
[:div.library-bar {}
(if-let [coll (->> (map second colls)
(filter #(= type (:type %)))
(sort-by :created-at)
(first))]
(st/emit! (rt/nav :dashboard/colors nil {:type type :id (:id coll)}))
(st/emit! (rt/nav :dashboard/colors nil {:type type}))))]
[:div.library-bar {}
[:div.library-bar-inside {}
[:ul.library-tabs {}
[:li {:class-name (when (= type :own) "current")

View file

@ -196,12 +196,12 @@
(let [own? (= type :own)
builtin? (= type :builtin)]
(letfn [(select-tab [type]
(if (= type :builtin)
(let [colls (->> (map second colls)
(filter #(= :builtin (:type %)))
(sort-by :name))]
(st/emit! (rt/navigate :dashboard/icons {} {:type type :id (first colls)})))
(st/emit! (rt/navigate :dashboard/icons {} {:type type}))))]
(if-let [coll (->> (map second colls)
(filter #(= type (:type %)))
(sort-by :created-at)
(first))]
(st/emit! (rt/nav :dashboard/icons nil {:type type :id (:id coll)}))
(st/emit! (rt/nav :dashboard/icons nil {:type type}))))]
[:div.library-bar {}
[:div.library-bar-inside {}
[:ul.library-tabs {}
@ -211,7 +211,6 @@
[:li {:class-name (when builtin? "current")
:on-click (partial select-tab :builtin)}
(tr "ds.store-icons-title")]]
(nav-section type id colls)]])))
;; --- Grid

View file

@ -192,15 +192,12 @@
(let [own? (= type :own)
builtin? (= type :builtin)]
(letfn [(select-tab [type]
(if own?
(st/emit! (rt/nav :dashboard/images nil {:type type}))
(let [coll (->> (map second colls)
(if-let [coll (->> (map second colls)
(filter #(= type (:type %)))
(sort-by :name)
(first))]
(if coll
(st/emit! (rt/nav :dashboard/images nil {:type type :id (:id coll)}))
(st/emit! (rt/nav :dashboard/images nil {:type type}))))))]
(st/emit! (rt/nav :dashboard/images nil {:type type :id (:id coll)}))
(st/emit! (rt/nav :dashboard/images nil {:type type}))))]
[:div.library-bar {}
[:div.library-bar-inside {}
[:ul.library-tabs {}