       (-apply-update [_ state]
         (let [proj {:id uuid
                     :name name
-                    :created (time/now :unix)}]
+                    :created (dt/now)}]
           (stpr/assoc-project state proj)))
 
       rs/EffectEvent

    (-apply-update [_ state]
      (let [page {:id (random-uuid)
                  :project project
                  :created (time/now :unix)
                  :layout layout
                  :shapes []
                  :name name

;; Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn load-projects
  []
  (letfn [(transform [state projects]
            (reduce stpr/assoc-project state projects))
          (on-loaded [projects]
            #(transform % projects))]
    (reify
      rs/WatchEvent
      (-apply-watch [_ state]
        (-> (rp/do :fetch/projects)
            (p/then on-loaded))))))

(defn load-pages
  []
  (letfn [(transform [state pages]
            (reduce stpr/assoc-page state pages))
          (on-loaded [pages]
            #(transform % pages))]
    (reify
      rs/WatchEvent
      (-apply-watch [_ state]
        (println "load-pages")
        (-> (rp/do :fetch/pages)
            (p/then on-loaded))))))

(defn create-page
  [{:keys [name width height project layout] :as data}]
  (sc/validate! +create-page-schema+ data)
