0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 14:39:45 -05:00

WIP: add/remove pages from workspace.

This commit is contained in:
Andrey Antukh 2015-12-15 22:42:02 +02:00
parent 9182244e88
commit 6595e95f12
3 changed files with 91 additions and 23 deletions

View file

@ -71,6 +71,17 @@
(-pr-writer [mv writer _] (-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/create-page>")))) (-write writer "#<event:u.s.p/create-page>"))))
(defn delete-page
[pageid]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(update-in state [:pages-by-id] dissoc pageid))
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/create-page>"))))
(defn create-project (defn create-project
[{:keys [name width height layout] :as data}] [{:keys [name width height layout] :as data}]
(sc/validate! +project-schema+ data) (sc/validate! +project-schema+ data)

View file

@ -7,3 +7,7 @@
(defn prevent-default (defn prevent-default
[e] [e]
(.preventDefault e)) (.preventDefault e))
(defn event->value
[e]
(.-value (.-target e)))

View file

@ -142,53 +142,106 @@
;; Project Bar ;; Project Bar
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- project-sidebar-item-render (defn- project-sidebar-pageitem-render
[own page-l] [own page numpages]
(let [page @page-l] (let [pageid (:id page)]
(html (html
[:li.single-page [:li.single-page
{:class "current" {:class "current"
:key pageid
:on-click #(dp/go-to-project (:project page) (:id page))} :on-click #(dp/go-to-project (:project page) (:id page))}
[:div.tree-icon i/page] [:div.tree-icon i/page]
[:span (:name page)] [:span (:name page)]
[:div.options [:div.options
[:div {:on-click (constantly nil)} i/pencil] [:div {:on-click (constantly nil)} i/pencil]
[:div {:class (when-not false "hide") [:div {:class (when (= 1 (count @pages-state)) "hide")
:on-click (constantly nil)} :on-click #(rs/emit! (dp/delete-page pageid))}
i/trash]]]))) i/trash]]])))
(def project-sidebar-item (def project-sidebar-pageitem
(util/component (util/component
{:render project-sidebar-item-render {:render project-sidebar-pageitem-render
:name "project-sidebar-item" :name "project-sidebar-pageitem"
:mixins [util/cursored]})) :mixins [util/cursored]}))
(defn- project-sidebar-pagelist-render
[own local]
(let [project (rum/react project-state)
pages (rum/react pages-state)
name (:name project)]
(html
[:div.project-bar-inside
[:span.project-name name]
[:ul.tree-view
(for [page pages] (project-sidebar-pageitem page (count pages)))]
[:button.btn-primary.btn-small
{:on-click #(reset! local {:edit true :form {}})}
"+ Add new page"]])))
(defn- project-sidebar-form-render
[own parent]
(letfn [(on-change [e]
(let [value (str/trim (dom/event->value e))]
(swap! parent assoc-in [:form :name] value)))
(on-save [e]
(let [project @project-state
name (get-in @parent [:form :name])
data {:project (:id project)
:width (:width project)
:height (:height project)
:name name}]
(rs/emit! (dp/create-page data))
(reset! parent {:edit false})))
(on-cancel [e]
(reset! parent {:edit false}))]
(html
[:div.project-bar-inside
[:input.input-text
{
:name "test"
:auto-focus true
:placeholder "Page title"
:type "text"
:value (get-in @parent [:form :name] "")
:on-change on-change
}]
[:button.btn-primary.btn-small
{:disabled (str/empty? (get-in @parent [:form :name] ""))
:on-click on-save}
"Save"]
[:button.btn-primary.btn-small
{:on-click on-cancel}
"Cancel"]])))
(def project-sidebar-form
(util/component
{:render project-sidebar-form-render
:name "project-sidebar-form"
:mixins [rum/reactive]}))
(def project-sidebar-pagelist
(util/component
{:render project-sidebar-pagelist-render
:name "project-sidebar-pagelist"
:mixins [rum/reactive]}))
(defn project-sidebar-render (defn project-sidebar-render
[own] [own]
(let [project (rum/react project-state) (let [local (:rum/local own)
name (:name project) project (rum/react project-state)]
pages (rum/react pages-state)]
(println "project-sidebar-render" pages)
(html (html
[:div#project-bar.project-bar [:div#project-bar.project-bar
(when-not (:visible project true) (when-not (:visible project true)
{:class "toggle"}) {:class "toggle"})
[:div.project-bar-inside (if (:edit @local)
[:span.project-name name] (project-sidebar-form local)
[:ul.tree-view (project-sidebar-pagelist local))])))
(for [page pages]
(let [pageid (:id page)
lense (l/in [:pages-by-id pageid])
page-l (l/focus-atom lense s/state)]
;; (println "project-sidebar-render$1" @page-l)
(rum/with-key (project-sidebar-item page-l) (str pageid))))]
#_(new-page conn project)]])))
(def project-sidebar (def project-sidebar
(util/component (util/component
{:render project-sidebar-render {:render project-sidebar-render
:name "project-sidebar" :name "project-sidebar"
:mixins [rum/reactive]})) :mixins [rum/reactive (rum/local {:edit false :form {}})]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Workspace ;; Workspace