mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 13:46:38 +02:00
WIP
This commit is contained in:
parent
56f7613453
commit
6b6aba7358
8 changed files with 258 additions and 37 deletions
|
@ -1,32 +1,104 @@
|
|||
(ns uxbox.data.projects
|
||||
(:require [uxbox.rstore :as rs]
|
||||
[uxbox.router :as r]
|
||||
[uxbox.state :as st]
|
||||
[uxbox.schema :as sc]
|
||||
[bouncer.validators :as v]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Schemas
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(def ^:static +project-schema+
|
||||
{:name [v/required v/string]
|
||||
:width [v/required v/integer]
|
||||
:height [v/required v/integer]
|
||||
:layout [v/required sc/keyword?]})
|
||||
:layout [v/required sc/keyword]})
|
||||
|
||||
(defn create-project
|
||||
[{:keys [name width height layout] :as data}]
|
||||
(sc/validate! +project-schema+ data)
|
||||
(println "create-project")
|
||||
(def ^:static +page-schema+
|
||||
{:name [v/required v/string]
|
||||
:width [v/required v/integer]
|
||||
:height [v/required v/integer]
|
||||
:project [v/required sc/uuid]})
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Events
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn create-page
|
||||
[{:keys [name width height project] :as data}]
|
||||
(sc/validate! +page-schema+ data)
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [uuid (random-uuid)
|
||||
proj {:id uuid
|
||||
page {:id uuid
|
||||
:project project
|
||||
:name name
|
||||
:width width
|
||||
:height height
|
||||
:pages []}]
|
||||
:height height}]
|
||||
(-> state
|
||||
(update-in [:projects] conj uuid)
|
||||
(update-in [:projects-by-id] assoc uuid {:name name}))))
|
||||
(update-in [:pages] conj uuid)
|
||||
(update-in [:projects-by-id project :pages] conj uuid)
|
||||
(update-in [:pages-by-id] assoc uuid page))))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [mv writer _]
|
||||
(-write writer "#<event:u.s.p/create-project>"))))
|
||||
(-write writer "#<event:u.s.p/create-page>"))))
|
||||
|
||||
(defn create-project
|
||||
[{:keys [name width height layout] :as data}]
|
||||
(sc/validate! +project-schema+ data)
|
||||
(let [uuid (random-uuid)]
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [proj {:id uuid
|
||||
:name name
|
||||
:width width
|
||||
:height height
|
||||
:pages []}]
|
||||
(-> state
|
||||
(update-in [:projects] conj uuid)
|
||||
(update-in [:projects-by-id] assoc uuid proj))))
|
||||
|
||||
rs/EffectEvent
|
||||
(-apply-effect [_ state]
|
||||
(rs/emit! (create-page {:name "Page 1"
|
||||
:width width
|
||||
:height height
|
||||
:project uuid})))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [mv writer _]
|
||||
(-write writer "#<event:u.s.p/create-project>")))))
|
||||
|
||||
(defn initialize-workspace
|
||||
[projectid pageid]
|
||||
(reify
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc state :workspace {:project projectid :page pageid}))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [mv writer _]
|
||||
(-write writer "#<event:u.s.p/go-to-project>"))))
|
||||
|
||||
(defn go-to-project
|
||||
"A shortcut event that redirects the user to the
|
||||
first page of the project."
|
||||
([projectid]
|
||||
(go-to-project projectid nil))
|
||||
([projectid pageid]
|
||||
(reify
|
||||
rs/EffectEvent
|
||||
(-apply-effect [_ state]
|
||||
(if pageid
|
||||
(rs/emit! (r/navigate :main/page {:project-uuid projectid
|
||||
:page-uuid pageid}))
|
||||
(let [pages (get-in state [:projects-by-id projectid :pages])]
|
||||
(rs/emit! (r/navigate :main/page {:project-uuid projectid
|
||||
:page-uuid (first pages)})))))
|
||||
IPrintWithWriter
|
||||
(-pr-writer [mv writer _]
|
||||
(-write writer "#<event:u.s.p/go-to-project")))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue