mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 21:09:00 -05:00
Reorganize repo code.
This commit is contained in:
parent
299c2bf06c
commit
cad95c67a5
11 changed files with 63 additions and 38 deletions
|
@ -53,7 +53,7 @@
|
||||||
(let [params {:username username
|
(let [params {:username username
|
||||||
:password password
|
:password password
|
||||||
:scope "webapp"}]
|
:scope "webapp"}]
|
||||||
(->> (rp/do :fetch/token params)
|
(->> (rp/req :fetch/token params)
|
||||||
(rx/catch on-error)
|
(rx/catch on-error)
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/mapcat #(rx/of (logged-in %)
|
(rx/mapcat #(rx/of (logged-in %)
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
(uum/error (tr "errors.fetch-page-history"))
|
(uum/error (tr "errors.fetch-page-history"))
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(let [params {:page id :pinned true}]
|
(let [params {:page id :pinned true}]
|
||||||
(->> (rp/do :fetch/page-history params)
|
(->> (rp/req :fetch/page-history params)
|
||||||
(rx/map on-success)
|
(rx/map on-success)
|
||||||
(rx/catch on-failure))))))
|
(rx/catch on-failure))))))
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
(let [params (merge
|
(let [params (merge
|
||||||
{:page id :max (or max 15)}
|
{:page id :max (or max 15)}
|
||||||
(when since {:since since}))]
|
(when since {:since since}))]
|
||||||
(->> (rp/do :fetch/page-history params)
|
(->> (rp/req :fetch/page-history params)
|
||||||
(rx/map on-success)
|
(rx/map on-success)
|
||||||
(rx/catch on-failure))))))
|
(rx/catch on-failure))))))
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@
|
||||||
(uum/error (tr "errors.page-history-update"))
|
(uum/error (tr "errors.page-history-update"))
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(->> (rp/do :update/page-history item)
|
(->> (rp/req :update/page-history item)
|
||||||
(rx/map on-success)
|
(rx/map on-success)
|
||||||
(rx/catch on-failure))
|
(rx/catch on-failure))
|
||||||
(->> (rx/filter history-updated? s)
|
(->> (rx/filter history-updated? s)
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
(on-error [err]
|
(on-error [err]
|
||||||
(js/console.error err)
|
(js/console.error err)
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(->> (rp/do :fetch/pages-by-project {:project projectid})
|
(->> (rp/req :fetch/pages-by-project {:project projectid})
|
||||||
(rx/map on-loaded)
|
(rx/map on-loaded)
|
||||||
(rx/catch on-error)))))
|
(rx/catch on-error)))))
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(let [params (-> (into {} this)
|
(let [params (-> (into {} this)
|
||||||
(assoc :data {}))]
|
(assoc :data {}))]
|
||||||
(->> (rp/do :create/page params)
|
(->> (rp/req :create/page params)
|
||||||
(rx/mapcat on-created)
|
(rx/mapcat on-created)
|
||||||
(rx/catch on-failed))))))
|
(rx/catch on-failed))))))
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@
|
||||||
(uum/error (tr "errors.page-update"))
|
(uum/error (tr "errors.page-update"))
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(let [page (stpr/pack-page state id)]
|
(let [page (stpr/pack-page state id)]
|
||||||
(->> (rp/do :update/page page)
|
(->> (rp/req :update/page page)
|
||||||
(rx/map on-success)
|
(rx/map on-success)
|
||||||
(rx/catch on-failure))))))
|
(rx/catch on-failure))))))
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@
|
||||||
(on-failure [e]
|
(on-failure [e]
|
||||||
(uum/error (tr "errors.page-update"))
|
(uum/error (tr "errors.page-update"))
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(->> (rp/do :update/page-metadata (into {} this))
|
(->> (rp/req :update/page-metadata (into {} this))
|
||||||
(rx/map on-success)
|
(rx/map on-success)
|
||||||
(rx/catch on-failure)))))
|
(rx/catch on-failure)))))
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@
|
||||||
(on-failure [e]
|
(on-failure [e]
|
||||||
(uum/error (tr "errors.delete-page"))
|
(uum/error (tr "errors.delete-page"))
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(->> (rp/do :delete/page id)
|
(->> (rp/req :delete/page id)
|
||||||
(rx/map on-success)
|
(rx/map on-success)
|
||||||
(rx/tap callback)
|
(rx/tap callback)
|
||||||
(rx/filter identity)
|
(rx/filter identity)
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
#(reduce stpr/assoc-project % projects))
|
#(reduce stpr/assoc-project % projects))
|
||||||
(on-error [err]
|
(on-error [err]
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(->> (rp/do :fetch/projects)
|
(->> (rp/req :fetch/projects)
|
||||||
(rx/map on-loaded)
|
(rx/map on-loaded)
|
||||||
(rx/catch on-error)))))
|
(rx/catch on-error)))))
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
:data nil))))
|
:data nil))))
|
||||||
(on-failure [err]
|
(on-failure [err]
|
||||||
(uum/error (tr "errors.create-project")))]
|
(uum/error (tr "errors.create-project")))]
|
||||||
(->> (rp/do :create/project {:name name})
|
(->> (rp/req :create/project {:name name})
|
||||||
(rx/mapcat on-success)
|
(rx/mapcat on-success)
|
||||||
(rx/catch on-failure)))))
|
(rx/catch on-failure)))))
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@
|
||||||
(rs/swap #(stpr/dissoc-project % id)))
|
(rs/swap #(stpr/dissoc-project % id)))
|
||||||
(on-failure [e]
|
(on-failure [e]
|
||||||
(uum/error (tr "errors.delete-project")))]
|
(uum/error (tr "errors.delete-project")))]
|
||||||
(->> (rp/do :delete/project id)
|
(->> (rp/req :delete/project id)
|
||||||
(rx/map on-success)
|
(rx/map on-success)
|
||||||
(rx/catch on-failure)))))
|
(rx/catch on-failure)))))
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
(letfn [(on-error [err]
|
(letfn [(on-error [err]
|
||||||
(uum/error (tr "errors.profile-fetch"))
|
(uum/error (tr "errors.profile-fetch"))
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(->> (rp/do :fetch/profile)
|
(->> (rp/req :fetch/profile)
|
||||||
(rx/catch on-error)
|
(rx/catch on-error)
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/map profile-fetched)))))
|
(rx/map profile-fetched)))))
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
(letfn [(on-error [err]
|
(letfn [(on-error [err]
|
||||||
(uum/error (tr "errors.update-profile"))
|
(uum/error (tr "errors.update-profile"))
|
||||||
(rx/empty))]
|
(rx/empty))]
|
||||||
(->> (rp/do :update/profile data)
|
(->> (rp/req :update/profile data)
|
||||||
(rx/catch on-error)
|
(rx/catch on-error)
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/map profile-fetched)))))
|
(rx/map profile-fetched)))))
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
;; (letfn [(on-error [err]
|
;; (letfn [(on-error [err]
|
||||||
;; (uum/error (tr "errors.update-password"))
|
;; (uum/error (tr "errors.update-password"))
|
||||||
;; (rx/empty))]
|
;; (rx/empty))]
|
||||||
;; (->> (rp/do :update/password data)
|
;; (->> (rp/req :update/password data)
|
||||||
;; (rx/catch on-error)))))
|
;; (rx/catch on-error)))))
|
||||||
(js/alert "Not implemented")
|
(js/alert "Not implemented")
|
||||||
(rx/empty)))
|
(rx/empty)))
|
||||||
|
|
|
@ -7,16 +7,17 @@
|
||||||
(ns uxbox.repo
|
(ns uxbox.repo
|
||||||
"A main interface for access to remote resources."
|
"A main interface for access to remote resources."
|
||||||
(:refer-clojure :exclude [do])
|
(:refer-clojure :exclude [do])
|
||||||
(:require [uxbox.repo.core :refer (-do)]
|
(:require [uxbox.repo.core :refer (request)]
|
||||||
[uxbox.repo.auth]
|
[uxbox.repo.auth]
|
||||||
|
[uxbox.repo.users]
|
||||||
[uxbox.repo.projects]
|
[uxbox.repo.projects]
|
||||||
[uxbox.repo.pages]
|
[uxbox.repo.pages]
|
||||||
[beicon.core :as rx]))
|
[beicon.core :as rx]))
|
||||||
|
|
||||||
(defn do
|
(defn req
|
||||||
"Perform a side effectfull action accesing
|
"Perform a side effectfull action accesing
|
||||||
remote resources."
|
remote resources."
|
||||||
([type]
|
([type]
|
||||||
(-do type nil))
|
(request type nil))
|
||||||
([type data]
|
([type data]
|
||||||
(-do type data)))
|
(request type data)))
|
||||||
|
|
|
@ -8,15 +8,15 @@
|
||||||
"A main interface for access to remote resources."
|
"A main interface for access to remote resources."
|
||||||
(:refer-clojure :exclude [do])
|
(:refer-clojure :exclude [do])
|
||||||
(:require [beicon.core :as rx]
|
(:require [beicon.core :as rx]
|
||||||
[uxbox.repo.core :refer (-do url send!)]
|
[uxbox.repo.core :refer (request url send!)]
|
||||||
[uxbox.state :as ust]))
|
[uxbox.state :as ust]))
|
||||||
|
|
||||||
(defmethod -do :fetch/profile
|
(defmethod request :fetch/profile
|
||||||
[type _]
|
[type _]
|
||||||
(let [url (str url "/profile/me")]
|
(let [url (str url "/profile/me")]
|
||||||
(send! {:method :get :url url})))
|
(send! {:method :get :url url})))
|
||||||
|
|
||||||
(defmethod -do :fetch/token
|
(defmethod request :fetch/token
|
||||||
[type data]
|
[type data]
|
||||||
(let [url (str url "/auth/token")]
|
(let [url (str url "/auth/token")]
|
||||||
(send! {:url url
|
(send! {:url url
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
:auth false
|
:auth false
|
||||||
:body data})))
|
:body data})))
|
||||||
|
|
||||||
(defmethod -do :update/profile
|
(defmethod request :update/profile
|
||||||
[type data]
|
[type data]
|
||||||
(let [params {:url (str url "/profile/me")
|
(let [params {:url (str url "/profile/me")
|
||||||
:method :put
|
:method :put
|
||||||
|
|
|
@ -78,9 +78,9 @@
|
||||||
(rx/map conditional-decode)
|
(rx/map conditional-decode)
|
||||||
(rx/mapcat handle-http-status))))
|
(rx/mapcat handle-http-status))))
|
||||||
|
|
||||||
(defmulti -do
|
(defmulti request
|
||||||
(fn [type data] type))
|
(fn [type data] type))
|
||||||
|
|
||||||
(defmethod -do :default
|
(defmethod request :default
|
||||||
[type data]
|
[type data]
|
||||||
(throw (ex-info (str "No implementation found for " type) {:data data})))
|
(throw (ex-info (str "No implementation found for " type) {:data data})))
|
||||||
|
|
|
@ -7,55 +7,55 @@
|
||||||
(ns uxbox.repo.pages
|
(ns uxbox.repo.pages
|
||||||
"A main interface for access to remote resources."
|
"A main interface for access to remote resources."
|
||||||
(:require [beicon.core :as rx]
|
(:require [beicon.core :as rx]
|
||||||
[uxbox.repo.core :refer (-do url send!)]
|
[uxbox.repo.core :refer (request url send!)]
|
||||||
[uxbox.state :as ust]))
|
[uxbox.state :as ust]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Login
|
;; Login
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defmethod -do :fetch/pages
|
(defmethod request :fetch/pages
|
||||||
[type data]
|
[type data]
|
||||||
(send! {:url (str url "/pages") :method :get}))
|
(send! {:url (str url "/pages") :method :get}))
|
||||||
|
|
||||||
(defmethod -do :fetch/pages-by-project
|
(defmethod request :fetch/pages-by-project
|
||||||
[type {:keys [project] :as params}]
|
[type {:keys [project] :as params}]
|
||||||
(let [url (str url "/projects/" project "/pages")]
|
(let [url (str url "/projects/" project "/pages")]
|
||||||
(send! {:method :get :url url})))
|
(send! {:method :get :url url})))
|
||||||
|
|
||||||
(defmethod -do :fetch/page-history
|
(defmethod request :fetch/page-history
|
||||||
[type {:keys [page] :as params}]
|
[type {:keys [page] :as params}]
|
||||||
(let [url (str url "/pages/" page "/history")
|
(let [url (str url "/pages/" page "/history")
|
||||||
query (select-keys params [:max :since :pinned])]
|
query (select-keys params [:max :since :pinned])]
|
||||||
(send! {:method :get :url url :query query })))
|
(send! {:method :get :url url :query query })))
|
||||||
|
|
||||||
(defmethod -do :delete/page
|
(defmethod request :delete/page
|
||||||
[_ id]
|
[_ id]
|
||||||
(let [url (str url "/pages/" id)]
|
(let [url (str url "/pages/" id)]
|
||||||
(send! {:url url :method :delete})))
|
(send! {:url url :method :delete})))
|
||||||
|
|
||||||
(defmethod -do :create/page
|
(defmethod request :create/page
|
||||||
[type {:keys [id] :as data}]
|
[type {:keys [id] :as data}]
|
||||||
(let [params {:url (str url "/pages")
|
(let [params {:url (str url "/pages")
|
||||||
:method :post
|
:method :post
|
||||||
:body data}]
|
:body data}]
|
||||||
(send! params)))
|
(send! params)))
|
||||||
|
|
||||||
(defmethod -do :update/page
|
(defmethod request :update/page
|
||||||
[type {:keys [id] :as data}]
|
[type {:keys [id] :as data}]
|
||||||
(let [params {:url (str url "/pages/" id)
|
(let [params {:url (str url "/pages/" id)
|
||||||
:method :put
|
:method :put
|
||||||
:body data}]
|
:body data}]
|
||||||
(send! params)))
|
(send! params)))
|
||||||
|
|
||||||
(defmethod -do :update/page-history
|
(defmethod request :update/page-history
|
||||||
[type {:keys [id page] :as data}]
|
[type {:keys [id page] :as data}]
|
||||||
(let [params {:url (str url "/pages/" page "/history/" id)
|
(let [params {:url (str url "/pages/" page "/history/" id)
|
||||||
:method :put
|
:method :put
|
||||||
:body data}]
|
:body data}]
|
||||||
(send! params)))
|
(send! params)))
|
||||||
|
|
||||||
(defmethod -do :update/page-metadata
|
(defmethod request :update/page-metadata
|
||||||
[type {:keys [id] :as data}]
|
[type {:keys [id] :as data}]
|
||||||
(let [params {:url (str url "/pages/" id "/metadata")
|
(let [params {:url (str url "/pages/" id "/metadata")
|
||||||
:method :put
|
:method :put
|
||||||
|
|
|
@ -7,26 +7,26 @@
|
||||||
(ns uxbox.repo.projects
|
(ns uxbox.repo.projects
|
||||||
"A main interface for access to remote resources."
|
"A main interface for access to remote resources."
|
||||||
(:require [beicon.core :as rx]
|
(:require [beicon.core :as rx]
|
||||||
[uxbox.repo.core :refer (-do url send!)]
|
[uxbox.repo.core :refer (request url send!)]
|
||||||
[uxbox.state :as ust]))
|
[uxbox.state :as ust]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Login
|
;; Login
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defmethod -do :fetch/projects
|
(defmethod request :fetch/projects
|
||||||
[type data]
|
[type data]
|
||||||
(let [url (str url "/projects")]
|
(let [url (str url "/projects")]
|
||||||
(send! {:url url :method :get})))
|
(send! {:url url :method :get})))
|
||||||
|
|
||||||
(defmethod -do :create/project
|
(defmethod request :create/project
|
||||||
[_ data]
|
[_ data]
|
||||||
(let [params {:url (str url "/projects")
|
(let [params {:url (str url "/projects")
|
||||||
:method :post
|
:method :post
|
||||||
:body data}]
|
:body data}]
|
||||||
(send! params)))
|
(send! params)))
|
||||||
|
|
||||||
(defmethod -do :delete/project
|
(defmethod request :delete/project
|
||||||
[_ id]
|
[_ id]
|
||||||
(let [url (str url "/projects/" id)]
|
(let [url (str url "/projects/" id)]
|
||||||
(send! {:url url :method :delete})))
|
(send! {:url url :method :delete})))
|
||||||
|
|
24
src/uxbox/repo/users.cljs
Normal file
24
src/uxbox/repo/users.cljs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||||
|
|
||||||
|
(ns uxbox.repo.users
|
||||||
|
"A main interface for access to remote resources."
|
||||||
|
(:refer-clojure :exclude [do])
|
||||||
|
(:require [beicon.core :as rx]
|
||||||
|
[uxbox.repo.core :refer (request url send!)]
|
||||||
|
[uxbox.state :as ust]))
|
||||||
|
|
||||||
|
(defmethod request :fetch/profile
|
||||||
|
[type _]
|
||||||
|
(let [url (str url "/profile/me")]
|
||||||
|
(send! {:method :get :url url})))
|
||||||
|
|
||||||
|
(defmethod request :update/profile
|
||||||
|
[type data]
|
||||||
|
(let [params {:url (str url "/profile/me")
|
||||||
|
:method :put
|
||||||
|
:body data}]
|
||||||
|
(send! params)))
|
Loading…
Add table
Reference in a new issue