0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-26 08:29:42 -05:00

Integrate basic page update with backend.

This commit is contained in:
Andrey Antukh 2016-03-15 22:26:15 +02:00
parent 098d38e079
commit 92060878d7
3 changed files with 34 additions and 19 deletions

View file

@ -11,11 +11,13 @@
[beicon.core :as rx] [beicon.core :as rx]
[uxbox.rstore :as rs] [uxbox.rstore :as rs]
[uxbox.router :as r] [uxbox.router :as r]
[uxbox.state :as st]
[uxbox.schema :as sc]
[uxbox.repo :as rp] [uxbox.repo :as rp]
[uxbox.util.datetime :as dt] [uxbox.locales :refer (tr)]
[uxbox.schema :as sc]
[uxbox.state :as st]
[uxbox.state.project :as stpr] [uxbox.state.project :as stpr]
[uxbox.ui.messages :as uum]
[uxbox.util.datetime :as dt]
[uxbox.util.data :refer (without-keys)])) [uxbox.util.data :refer (without-keys)]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -103,18 +105,24 @@
(defn create-page (defn create-page
[{:keys [name width height project layout] :as data}] [{:keys [name width height project layout] :as data}]
(sc/validate! +create-page-schema+ data) (sc/validate! +create-page-schema+ data)
(reify (letfn [(create []
rs/UpdateEvent (rp/do :create/page {:project project
(-apply-update [_ state] :layout layout
(let [page {:id (random-uuid) :data []
:project project :name name
:created (dt/now) :width width
:layout layout :height height}))
:shapes [] (on-created [page]
:name name #(stpr/assoc-page % page))
:width width
:height height}] (on-failed [page]
(stpr/assoc-page state page))))) (uum/error (tr "errors.auth")))]
(reify
rs/WatchEvent
(-apply-watch [_ state]
(-> (create)
(p/then on-created)
(p/catch on-failed))))))
(defn update-page (defn update-page
[{:keys [id name width height layout] :as data}] [{:keys [id name width height layout] :as data}]
@ -126,7 +134,15 @@
(when width {:width width}) (when width {:width width})
(when height {:height height}) (when height {:height height})
(when name {:name name}))] (when name {:name name}))]
(assoc-in state [:pages-by-id id] page))))) (assoc-in state [:pages-by-id id] page)))
rs/WatchEvent
(-apply-watch [_ state]
(let [page (get-in state [:pages-by-id id])
on-success (fn [{:keys [version]}]
#(assoc-in % [:pages-by-id id :version] version))]
(-> (rp/do :update/page page)
(p/then on-success))))))
(defn delete-page (defn delete-page
[pageid] [pageid]
@ -171,7 +187,6 @@
(reify (reify
rs/WatchEvent rs/WatchEvent
(-apply-watch [_ state] (-apply-watch [_ state]
(println "go-to" projectid)
(let [pages (stpr/project-pages state projectid) (let [pages (stpr/project-pages state projectid)
pageid (:id (first pages)) pageid (:id (first pages))
params {:project-uuid projectid params {:project-uuid projectid

View file

@ -34,7 +34,8 @@
(defn- workspace-render (defn- workspace-render
[own projectid] [own projectid]
(let [{:keys [flags] :as workspace} (rum/react uuwb/workspace-l) (let [{:keys [flags] :as workspace} (rum/react uuwb/workspace-l)
left-sidebar? (not (empty? (keep flags [:layers :sitemap :document-history]))) left-sidebar? (not (empty? (keep flags [:layers :sitemap
:document-history])))
right-sidebar? (not (empty? (keep flags [:icons :drawtools right-sidebar? (not (empty? (keep flags [:icons :drawtools
:element-options]))) :element-options])))
local (:rum/local own) local (:rum/local own)

View file

@ -113,7 +113,6 @@
[own local page] [own local page]
(let [edition? (:id page) (let [edition? (:id page)
page (merge page @local) page (merge page @local)
;; {:keys [name width height] :or {name ""} :as page} (merge page @local)
valid? (and (not (str/empty? (str/trim (:name page "")))) valid? (and (not (str/empty? (str/trim (:name page ""))))
(pos? (:width page)) (pos? (:width page))
(pos? (:height page)))] (pos? (:height page)))]