Skip to content

Commit

Permalink
Merge branch 'master' into 257-form-empty-fields-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
skydread1 committed Aug 4, 2023
2 parents 374625f + 56a701b commit 20b5956
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 158 deletions.
141 changes: 66 additions & 75 deletions client/common/src/flybot/client/common/db/event.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@

;; Overridden by the figwheel config option :closure-defines
(goog-define BASE-URI "")
(goog-define MOBILE? false)

(defn base-uri
"Given the relative `path`, use the BASE-URI to build the absolute path uri."
[path]
(str BASE-URI path))

(def http-xhrio-default
{:method :post
:uri (base-uri "/pattern")
:format (edn-request-format {:keywords? true})
:response-format (edn-response-format {:keywords? true})
:on-failure [:fx.http/failure]})

;; ---------- http success/failure ----------

(rf/reg-event-db
Expand Down Expand Up @@ -112,11 +120,10 @@
(rf/reg-event-fx
:evt.user/logout
(fn [_ _]
{:http-xhrio {:method :get
:uri (base-uri "/users/logout")
:response-format (edn-response-format {:keywords? true})
:on-success [:fx.http/logout-success]
:on-failure [:fx.http/failure]}}))
{:http-xhrio (merge http-xhrio-default
{:method :get
:uri (base-uri "/users/logout")
:on-success [:fx.http/logout-success]})}))

(rf/reg-event-fx
:evt.user.form/update-role
Expand All @@ -126,19 +133,15 @@
user-email (-> role-info operation role :user/email)]
(if (:errors role-info)
{:fx [[:dispatch [:evt.notif/set-notif :error/form "Form Input Error" (valid/error-msg role-info)]]]}
{:http-xhrio {:method :post
:uri (base-uri "/pattern")
:headers {:cookie (:user/cookie db)}
:params {:users
{operation
{(list role :with [user-email])
{:user/name '?
:user/roles [{:role/name '?
:role/date-granted '?}]}}}}
:format (edn-request-format {:keywords? true})
:response-format (edn-response-format {:keywords? true})
:on-success [:fx.http/update-role-success operation role]
:on-failure [:fx.http/failure]}}))))
{:http-xhrio (merge http-xhrio-default
{:headers (when MOBILE? {:cookie (:user/cookie db)})
:params {:users
{operation
{(list role :with [user-email])
{:user/name '?
:user/roles [{:role/name '?
:role/date-granted '?}]}}}}
:on-success [:fx.http/update-role-success operation role]})}))))

;; ---------- Post ----------

Expand Down Expand Up @@ -195,18 +198,14 @@
:evt.post/remove-post
(fn [{:keys [db]} [_ post-id]]
(let [user-id (-> db :app/user :user/id)]
{:http-xhrio {:method :post
:uri (base-uri "/pattern")
:headers {:cookie (:user/cookie db)}
:params {:posts
{(list :removed-post :with [post-id user-id])
{:post/id '?
:post/md-content '?
:post/page '?}}}
:format (edn-request-format {:keywords? true})
:response-format (edn-response-format {:keywords? true})
:on-success [:fx.http/remove-post-success]
:on-failure [:fx.http/failure]}})))
{:http-xhrio (merge http-xhrio-default
{:headers (when MOBILE? {:cookie (:user/cookie db)})
:params {:posts
{(list :removed-post :with [post-id user-id])
{:post/id '?
:post/md-content '?
:post/page '?}}}
:on-success [:fx.http/remove-post-success]})})))

;; ---------- Post Form ----------

Expand All @@ -225,29 +224,25 @@
post (-> db :form/fields (valid/prepare-post user-id) (valid/validate valid/post-schema-create))]
(if (:errors post)
{:fx [[:dispatch [:evt.notif/set-notif :error/form "Form Input Error" (valid/error-msg post)]]]}
{:http-xhrio {:method :post
:uri (base-uri "/pattern")
:headers {:cookie (:user/cookie db)}
:params {:posts
{(list :new-post :with [post])
{:post/id '?
:post/page '?
:post/css-class '?
:post/creation-date '?
:post/last-edit-date '?
:post/author {:user/id '?
:user/name '?}
:post/last-editor {:user/id '?
:user/name '?}
:post/md-content '?
:post/image-beside {:image/src '?
:image/src-dark '?
:image/alt '?}
:post/default-order '?}}}
:format (edn-request-format {:keywords? true})
:response-format (edn-response-format {:keywords? true})
:on-success [:fx.http/send-post-success]
:on-failure [:fx.http/failure]}}))))
{:http-xhrio (merge http-xhrio-default
{:headers (when MOBILE? {:cookie (:user/cookie db)})
:params {:posts
{(list :new-post :with [post])
{:post/id '?
:post/page '?
:post/css-class '?
:post/creation-date '?
:post/last-edit-date '?
:post/author {:user/id '?
:user/name '?}
:post/last-editor {:user/id '?
:user/name '?}
:post/md-content '?
:post/image-beside {:image/src '?
:image/src-dark '?
:image/alt '?}
:post/default-order '?}}}
:on-success [:fx.http/send-post-success]})}))))

;; Form body

Expand All @@ -265,28 +260,24 @@
:post/author (-> db :app/user (select-keys [:user/id :user/name]))
:post/creation-date (utils/mk-date)
:post/default-order (->> db :app/posts vals (filter #(= page (:post/page %))) count)})})
{:http-xhrio {:method :post
:uri (base-uri "/pattern")
:params {:posts
{(list :post :with [post-id])
{:post/id '?
:post/page '?
:post/css-class '?
:post/creation-date '?
:post/last-edit-date '?
:post/author {:user/id '?
:user/name '?}
:post/last-editor {:user/id '?
:user/name '?}
:post/md-content '?
:post/image-beside {:image/src '?
:image/src-dark '?
:image/alt '?}
:post/default-order '?}}}
:format (edn-request-format {:keywords? true})
:response-format (edn-response-format {:keywords? true})
:on-success [:fx.http/post-success]
:on-failure [:fx.http/failure]}})))
{:http-xhrio (merge http-xhrio-default
{:params {:posts
{(list :post :with [post-id])
{:post/id '?
:post/page '?
:post/css-class '?
:post/creation-date '?
:post/last-edit-date '?
:post/author {:user/id '?
:user/name '?}
:post/last-editor {:user/id '?
:user/name '?}
:post/md-content '?
:post/image-beside {:image/src '?
:image/src-dark '?
:image/alt '?}
:post/default-order '?}}}
:on-success [:fx.http/post-success]})})))

(rf/reg-event-db
:evt.post.form/set-field
Expand Down
64 changes: 30 additions & 34 deletions client/mobile/src/flybot/client/mobile/core/db/event.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns flybot.client.mobile.core.db.event
(:require [ajax.edn :refer [edn-request-format edn-response-format]]
[flybot.client.common.db.event :refer [base-uri]]
(:require [flybot.client.common.db.event :refer [http-xhrio-default]]
[flybot.client.common.utils :as client.utils]
[flybot.client.mobile.core.navigation :as nav]
[flybot.common.utils :refer [temporary-id?]]
Expand Down Expand Up @@ -31,38 +30,35 @@
{:db (assoc
db
:navigator/ref @nav/nav-ref)
:http-xhrio {:method :post
:uri (base-uri "/pattern")
:headers {:cookie (:user/cookie db)}
:params {:posts
{(list :all :with [])
[{:post/id '?
:post/page '?
:post/css-class '?
:post/creation-date '?
:post/last-edit-date '?
:post/author {:user/id '?
:user/name '?}
:post/last-editor {:user/id '?
:user/name '?}
:post/md-content '?
:post/image-beside {:image/src '?
:image/src-dark '?
:image/alt '?}
:post/default-order '?}]}
:users
{:auth
{(list :logged :with [])
{:user/id '?
:user/email '?
:user/name '?
:user/picture '?
:user/roles [{:role/name '?
:role/date-granted '?}]}}}}
:format (edn-request-format {:keywords? true})
:response-format (edn-response-format {:keywords? true})
:on-success [:fx.http/all-success]
:on-failure [:fx.http/failure]}}))
:http-xhrio (merge http-xhrio-default
{:headers {:cookie (:user/cookie db)}
:params {:posts
{(list :all :with [])
[{:post/id '?
:post/page '?
:post/css-class '?
:post/creation-date '?
:post/last-edit-date '?
:post/author {:user/id '?
:user/name '?}
:post/last-editor {:user/id '?
:user/name '?}
:post/md-content '?
:post/image-beside {:image/src '?
:image/src-dark '?
:image/alt '?}
:post/default-order '?}]}
:users
{:auth
{(list :logged :with [])
{:user/id '?
:user/email '?
:user/name '?
:user/picture '?
:user/roles [{:role/name '?
:role/date-granted '?}]}}}}

:on-success [:fx.http/all-success]})}))

(rf/reg-event-fx
:evt.app/initialize-with-cookie
Expand Down
70 changes: 36 additions & 34 deletions client/web/src/flybot/client/web/core/db/event.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(ns flybot.client.web.core.db.event
(:require [ajax.edn :refer [edn-request-format edn-response-format]]
[clojure.string :as str]
(:require [clojure.string :as str]
[day8.re-frame.http-fx]
[flybot.client.common.db.event]
[flybot.client.common.db.event :refer [http-xhrio-default]]
[flybot.client.common.utils :as client.utils]
[flybot.client.web.core.utils :as web.utils]
[flybot.common.utils :as utils :refer [toggle]]
Expand Down Expand Up @@ -84,37 +83,33 @@
:app/theme app-theme
:user/mode :reader
:nav/navbar-open? false)
:http-xhrio {:method :post
:uri "/pattern"
:params {:posts
{(list :all :with [])
[{:post/id '?
:post/page '?
:post/css-class '?
:post/creation-date '?
:post/last-edit-date '?
:post/author {:user/id '?
:user/name '?}
:post/last-editor {:user/id '?
:user/name '?}
:post/md-content '?
:post/image-beside {:image/src '?
:image/src-dark '?
:image/alt '?}
:post/default-order '?}]}
:users
{:auth
{(list :logged :with [])
{:user/id '?
:user/email '?
:user/name '?
:user/picture '?
:user/roles [{:role/name '?
:role/date-granted '?}]}}}}
:format (edn-request-format {:keywords? true})
:response-format (edn-response-format {:keywords? true})
:on-success [:fx.http/all-success]
:on-failure [:fx.http/failure]}
:http-xhrio (merge http-xhrio-default
{:params {:posts
{(list :all :with [])
[{:post/id '?
:post/page '?
:post/css-class '?
:post/creation-date '?
:post/last-edit-date '?
:post/author {:user/id '?
:user/name '?}
:post/last-editor {:user/id '?
:user/name '?}
:post/md-content '?
:post/image-beside {:image/src '?
:image/src-dark '?
:image/alt '?}
:post/default-order '?}]}
:users
{:auth
{(list :logged :with [])
{:user/id '?
:user/email '?
:user/name '?
:user/picture '?
:user/roles [{:role/name '?
:role/date-granted '?}]}}}}
:on-success [:fx.http/all-success]})
:fx [[:fx.app/update-html-class app-theme]]})))

;; Theme (dark/light)
Expand All @@ -128,6 +123,13 @@
:fx [[:fx.app/set-theme-local-store next-theme]
[:fx.app/toggle-css-class [cur-theme next-theme]]]})))

;; Code syntax highlighting

(rf/reg-event-fx
:evt.app/highlight-code
(fn [_ [_ html-id]]
{:fx [[:fx.app/highlight-code html-id]]}))

;; ---------- Navbar ----------

(rf/reg-event-db
Expand Down
12 changes: 11 additions & 1 deletion client/web/src/flybot/client/web/core/db/fx.cljs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
(ns flybot.client.web.core.db.fx
(:require [clojure.edn :as edn]
(:require [cljsjs.highlight]
[clojure.edn :as edn]
[clojure.string :as str]
[flybot.client.common.db.fx]
[flybot.client.common.utils :refer [cljs->js]]
[flybot.client.web.core.db.class-utils :as cu]
[flybot.client.web.core.db.fx.highlight]
[flybot.client.web.core.db.localstorage :as l-storage]
[re-frame.core :as rf]
[reagent.core :as reagent]
Expand Down Expand Up @@ -64,6 +66,14 @@
(fn [next-theme]
(l-storage/set-item :theme next-theme)))

;; code syntax highlighting

(rf/reg-fx
:fx.app/highlight-code
(fn [id]
(.configure js/hljs #js {:cssSelector (str "#" id " pre code")})
(.highlightAll js/hljs)))

;; ----- Notification ------

;; Pop-ups (toasts)
Expand Down
Loading

0 comments on commit 20b5956

Please sign in to comment.