0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-02 20:39:09 -05:00
penpot/frontend/uxbox/ui/dashboard/icons.cljs
2015-12-30 00:19:48 +02:00

193 lines
6.1 KiB
Clojure

(ns uxbox.ui.dashboard.icons
(:require [sablono.core :refer-macros [html]]
[rum.core :as rum]
[cuerdas.core :as str]
[cats.labs.lens :as l]
[uxbox.state :as st]
[uxbox.rstore :as rs]
[uxbox.schema :as sc]
[uxbox.library :as library]
[uxbox.shapes :as shapes]
[uxbox.data.dashboard :as dd]
[uxbox.util.lens :as ul]
[uxbox.ui.icons :as i]
[uxbox.ui.form :as form]
[uxbox.ui.lightbox :as lightbox]
[uxbox.ui.dom :as dom]
[uxbox.ui.mixins :as mx]
[uxbox.ui.util :as util]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lenses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:static dashboard-state
(as-> (l/in [:dashboard]) $
(l/focus-atom $ st/state)))
;; (def ^:static collections-state
;; (as-> (l/in [:icons-by-id]) $
;; (l/focus-atom $ st/state)))
;; (def ^:static collection-state
;; (as-> (ul/dep-in [:icons-by-id] [:dashboard :collection-id]) $
;; (l/focus-atom $ st/state)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Menu
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn menu-render
[]
(let [pcount 20]
(html
[:section#dashboard-bar.dashboard-bar
[:div.dashboard-info
[:span.dashboard-projects pcount " projects"]
[:span "Sort by"]]
[:div.dashboard-search i/search]])))
(def ^:static menu
(util/component
{:render menu-render
:name "icons-menu"
:mixins [rum/reactive]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Page Title
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn page-title-render
[own coll]
(let [dashboard (rum/react dashboard-state)
own? (:builtin coll false)]
(html
[:div.dashboard-title {}
(if coll
[:h2 {}
[:span "Library: "]
[:span {:content-editable ""
:on-key-up (constantly nil)}
(:name coll)]]
[:h2 "No library selected"])
(if (and (not own?) coll)
[:div.edition {}
[:span {:on-click (constantly nil)}
i/trash]])])))
(def ^:static page-title
(util/component
{:render page-title-render
:name "page-title"
:mixins [mx/static rum/reactive]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Nav
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn nav-render
[own]
(let [dashboard (rum/react dashboard-state)
;; colors (rum/react collections-state)
collid (:collection-id dashboard)
own? (= (:collection-type dashboard) :own)
builtin? (= (:collection-type dashboard) :builtin)
collections (if own?
[] #_(sort-by :id (vals colors))
library/+icon-collections+)]
(html
[:div.library-bar
[:div.library-bar-inside
[:ul.library-tabs
[:li {:class-name (when builtin? "current")
:on-click #(rs/emit! (dd/set-collection-type :builtin))}
"STANDARD"]
[:li {:class-name (when own? "current")
:on-click #(rs/emit! (dd/set-collection-type :own))}
"YOUR LIBRARIES"]]
[:ul.library-elements
(when own?
[:li
[:a.btn-primary
{:on-click (constantly nil)}
"+ New library"]])
(for [props collections]
[:li {:key (str (:id props))
:on-click #(rs/emit! (dd/set-collection (:id props)))
:class-name (when (= (:id props) collid) "current")}
[:span.element-title (:name props)]
[:span.element-subtitle
(str (count (:icons props)) " elements")]])]]])))
(def ^:static nav
(util/component
{:render nav-render
:name "nav"
:mixins [rum/reactive]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Grid
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn grid-render
[own]
(let [dashboard (rum/react dashboard-state)
coll-type (:collection-type dashboard)
coll-id (:collection-id dashboard)
own? (= coll-type :own)
coll (get library/+icon-collections-by-id+ coll-id)]
;; coll (case coll-type
;; :builtin (get library/+color-collections-by-id+ coll-id)
;; :own (rum/react collection-state))]
;; edit-cb #(lightbox/open! :icon-form {:coll coll :icon %})
;; remove-cb #(rs/emit! (dd/remove-icon {:id (:id coll) :icon %}))]
;; (println "KAKAKKA" coll-type coll-id coll)
(when coll
(html
[:section.dashboard-grid.library
(page-title coll)
[:div.dashboard-grid-content
(for [icon (:icons coll)]
[:div.grid-item.small-item.project-th {}
[:span.grid-item-image #_i/toggle (shapes/render icon)]
[:h3 (:name icon)]
#_[:div.project-th-actions
[:div.project-th-icon.edit i/pencil]
[:div.project-th-icon.delete i/trash]]])]]))))
(def grid
(util/component
{:render grid-render
:name "grid"
:mixins [mx/static rum/reactive]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lightbox
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- new-icon-lightbox-render
[own]
(html
[:div.lightbox-body
[:h3 "New icon"]
[:div.row-flex
[:div.lightbox-big-btn
[:span.big-svg i/shapes]
[:span.text "Go to workspace"]
]
[:div.lightbox-big-btn
[:span.big-svg.upload i/exit]
[:span.text "Upload file"]
]
]
[:a.close {:href "#"
:on-click #(do (dom/prevent-default %)
(lightbox/close!))}
i/close]]))
(def new-icon-lightbox
(util/component
{:render new-icon-lightbox-render
:name "new-icon-lightbox"}))