mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
WIP: improve page edition.
This commit is contained in:
parent
6595e95f12
commit
0ef064f075
2 changed files with 63 additions and 39 deletions
|
@ -71,6 +71,17 @@
|
|||
(-pr-writer [mv writer _]
|
||||
(-write writer "#<event:u.s.p/create-page>"))))
|
||||
|
||||
(defn update-page-name
|
||||
[pageid name]
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(update-in state [:pages-by-id pageid] assoc :name name))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [mv writer _]
|
||||
(-write writer "#<event:u.s.p/update-page-name>"))))
|
||||
|
||||
(defn delete-page
|
||||
[pageid]
|
||||
(reify
|
||||
|
@ -80,7 +91,7 @@
|
|||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [mv writer _]
|
||||
(-write writer "#<event:u.s.p/create-page>"))))
|
||||
(-write writer "#<event:u.s.p/edit-page>"))))
|
||||
|
||||
(defn create-project
|
||||
[{:keys [name width height layout] :as data}]
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
[uxbox.ui.icons.dashboard :as icons]
|
||||
[uxbox.ui.icons :as i]
|
||||
[uxbox.ui.lightbox :as lightbox]
|
||||
[uxbox.ui.keyboard :as k]
|
||||
[uxbox.ui.users :as ui.u]
|
||||
[uxbox.ui.navigation :as nav]
|
||||
[uxbox.ui.dom :as dom]))
|
||||
|
@ -143,19 +144,20 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- project-sidebar-pageitem-render
|
||||
[own page numpages]
|
||||
(let [pageid (:id page)]
|
||||
[own parent page numpages]
|
||||
(letfn [(on-edit [e]
|
||||
(let [data {:edit true :form page}]
|
||||
(reset! parent data)))]
|
||||
(html
|
||||
[:li.single-page
|
||||
{:class "current"
|
||||
:key pageid
|
||||
:on-click #(dp/go-to-project (:project page) (:id page))}
|
||||
[:div.tree-icon i/page]
|
||||
[:span (:name page)]
|
||||
[:div.options
|
||||
[:div {:on-click (constantly nil)} i/pencil]
|
||||
[:div {:on-click on-edit} i/pencil]
|
||||
[:div {:class (when (= 1 (count @pages-state)) "hide")
|
||||
:on-click #(rs/emit! (dp/delete-page pageid))}
|
||||
:on-click #(rs/emit! (dp/delete-page (:id page)))}
|
||||
i/trash]]])))
|
||||
|
||||
(def project-sidebar-pageitem
|
||||
|
@ -173,45 +175,56 @@
|
|||
[:div.project-bar-inside
|
||||
[:span.project-name name]
|
||||
[:ul.tree-view
|
||||
(for [page pages] (project-sidebar-pageitem page (count pages)))]
|
||||
(for [page pages]
|
||||
(let [component (project-sidebar-pageitem local page (count pages))]
|
||||
(rum/with-key component (str (:id page)))))]
|
||||
[: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"]])))
|
||||
(let [form (:form @parent)
|
||||
project @project-state]
|
||||
(letfn [(on-change [e]
|
||||
(let [value (dom/event->value e)]
|
||||
(swap! parent assoc-in [:form :name] value)))
|
||||
(persist []
|
||||
(if (nil? (:id form))
|
||||
(let [data {:project (:id project)
|
||||
:width (:width project)
|
||||
:height (:height project)
|
||||
:name (:name form)}]
|
||||
(rs/emit! (dp/create-page data))
|
||||
(reset! parent {:edit false}))
|
||||
(do
|
||||
(rs/emit! (dp/update-page-name (:id form) (:name form)))
|
||||
(reset! parent {:edit false}))))
|
||||
(on-save [e]
|
||||
(persist))
|
||||
(on-key-up [e]
|
||||
(when (k/enter? e)
|
||||
(persist)))
|
||||
(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
|
||||
:on-key-up on-key-up
|
||||
}]
|
||||
[:button.btn-primary.btn-small
|
||||
{:disabled (str/empty? (str/trim (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
|
||||
|
|
Loading…
Add table
Reference in a new issue