Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all the hardcoded URL by (url-for) function #31

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/co/gaiwan/compass/html/navigation.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
([user]
[:<>
[graphics/compass-logo]
[:h1 [:a {:href "/"} "Compass"]]
[:h1 [:a {:href (url-for :sessions/index)} "Compass"]]
[:button {:cx-toggle "menu-open" :cx-target "body"}
[graphics/hamburger]
(when (and user (not (user/assigned-ticket user)))
Expand All @@ -42,7 +42,7 @@
(into [:a props] children)
(into
[:a {:hx-target "#modal"
:hx-get (str "/login?next=" (:href props))
:hx-get (str (url-for :login/index) "?next=" (:href props))
:href "#"}]
children)))

Expand Down Expand Up @@ -79,7 +79,7 @@
(when user
[:<>
[c/avatar (user/avatar-css-value user)]
"Signed in as " (:public-profile/name user) "." [:a {:href "/logout"} "Sign out"]])]
"Signed in as " (:public-profile/name user) "." [:a {:href (url-for :logout/index)} "Sign out"]])]
[:button {:cx-toggle "menu-open" :cx-target "body"}
[graphics/cross]]]
#_[:pre (pr-str user)]
Expand All @@ -95,18 +95,17 @@
:on-click "document.body.classList.toggle('menu-open')"}
[:strong "Claim your Ti.to ticket for full access"]]]
[:div.notifier-dot]]))
(for [[href caption] {"/" "Sessions & Activities"
;; "/attendees" "Attendees"
;; "/profile" "Profile & Settings"
"/sessions/new" "Create Activity"
}]
(for [[href caption] {(url-for :sessions/index) "Sessions & Activities"
;; (url-for :attendees/index) "Attendees"
;; (url-for :profile/index) "Profile & Settings"
(url-for :session/new) "Create Activity"}]
[:li [:a {:href href
:on-click "document.body.classList.toggle('menu-open')"}
caption]])]
[:li [:a {:href (url-for :contact/qr)
:hx-target "#modal"
:on-click "document.body.classList.toggle('menu-open')"}
"Add Contact"]]]))
caption]])
[:li [:a {:href (url-for :contact/qr)
:hx-target "#modal"
:on-click "document.body.classList.toggle('menu-open')"}
"Add Contact"]]]]))

(o/defrules toggle-menu-button)

Expand Down
2 changes: 1 addition & 1 deletion src/co/gaiwan/compass/html/profiles.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
(o/defstyled edit-profile-btn :button
([user]
[:<>
{:hx-get "/profile/edit"
{:hx-get (url-for :profile/edit)
:hx-select "#form"
:hx-target "#detail"
:hx-swap "outerHTML"}
Expand Down
20 changes: 9 additions & 11 deletions src/co/gaiwan/compass/html/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
([session user]
[:<>
[join-btn session user]
[:a.btn {:href (str "/sessions/" (:db/id session))}
[:a.btn {:href (url-for :session/get {:id (:db/id session)})}
"Details"]]))

(o/defprop --session-type-color)
Expand Down Expand Up @@ -143,7 +143,7 @@
capacity signup-count] :as session}
user]
[:<>
{:hx-get (str "/sessions/" (:db/id session) "/card")
{:hx-get (url-for :session/card {:id (:db/id session)})
:hx-trigger (str "session-" (:db/id session) "-updated from:body")
:hx-target (str "closest ." session-card)
:hx-select (str "." session-card " > *")
Expand All @@ -159,7 +159,7 @@

[:div.details
[:h2.title
[:a {:href (str "/sessions/" (:db/id session))}
[:a {:href (url-for :session/get {:id (:db/id session)})}
[:span.datetime
(str (time/truncate-to (time/local-time time) :minutes)) " · "]
title]]
Expand Down Expand Up @@ -196,8 +196,7 @@
:background t/--highlight-yellow}
:p-4 :max-w-lg :mt-2 :mb-6 :ml-2
[:>p :font-semibold]
[:.datetime :font-size-7 :font-bold]
]
[:.datetime :font-size-7 :font-bold]]
[:.three-box #_{:background t/--activity-color}
:relative
:font-size-6 :my-4 :flex :p-4 :gap-4
Expand All @@ -214,16 +213,15 @@
:z-index -1
:background-color t/--activity-color
:border-radius "900px"
:transform "rotate(1deg)"}
]]
:transform "rotate(1deg)"}]]

([{:session/keys [type title subtitle organized
time location image capacity
signup-count description
participants] :as session}
user]
[:<>
{:hx-get (str "/sessions/" (:db/id session))
{:hx-get (url-for :session/get {:id (:db/id session)})
:hx-trigger (str "session-" (:db/id session) "-updated from:body")
:hx-target (str "closest ." session-detail)
:hx-select (str "." session-detail " > *")
Expand All @@ -232,7 +230,7 @@

[:div.details
[:a
{:href "/"
{:href (url-for :sessions/index)
:style {:display "none"}
:hx-trigger (str "session-" (:db/id session) "-deleted from:body")}]
[:div.header-row
Expand Down Expand Up @@ -274,9 +272,9 @@
(when (or (user/admin? user)
(session/organizing? session user))
[:<>
[:a {:href (str "/sessions/" (:db/id session) "/edit")}
[:a {:href (url-for :session/edit {:id (:db/id session)})}
[:button "Edit"]]
[:button {:hx-delete (str "/sessions/" (:db/id session))} "Delete"]])]
[:button {:hx-delete (url-for :session/get {:id (:db/id session)})} "Delete"]])]
#_[:p.host "Organized by " organized]
#_[:ol (map attendee participants)]
#_[:p (pr-str user)]
Expand Down
13 changes: 8 additions & 5 deletions src/co/gaiwan/compass/routes/oauth.clj
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@
{:get {:handler GET-discord-redirect}}]
["/callback"
{:get {:handler GET-discord-callback}}]]]
["/login" {:get {:handler GET-login}}]
["/login"
{:name :login/index
:get {:handler GET-login}}]
["/logout"
{:get {:handler (fn [req]
{:name :logout/index
:get {:handler (fn [req]
(assoc
(response/redirect "/")
:flash "Thank you for using Compass! Please come again."
:session {}))}}]])
(response/redirect "/")
:flash "Thank you for using Compass! Please come again."
:session {}))}}]])
9 changes: 6 additions & 3 deletions src/co/gaiwan/compass/routes/profiles.clj
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@
(defn routes []
[["/profile"
[""
{:middleware [[response/wrap-requires-auth]]
{:name :profile/index
:middleware [[response/wrap-requires-auth]]
:get {:handler GET-profile}}]
["/edit"
{:get {:handler GET-profile-form}}]
{:name :profile/edit
:get {:handler GET-profile-form}}]
["/edit/private-name"
{:name :profile/private-name
:get {:handler GET-private-name}}]
Expand All @@ -217,7 +219,8 @@
:get {:handler GET-qr-code}}]]
["/attendees"
[""
{:middleware [[response/wrap-requires-auth]]
{:name :attendees/index
:middleware [[response/wrap-requires-auth]]
:get {:handler GET-attendees}}]
["/:qr-hash"
{:middleware [[response/wrap-requires-auth]]
Expand Down
5 changes: 3 additions & 2 deletions src/co/gaiwan/compass/routes/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

(defn PATCH-edit-session
"Same as [[POST-create-session]], but edits an existing session."
[{ :keys [params path-params identity]}]
[{:keys [params path-params identity]}]
(let [{:keys [id]} path-params
id (parse-long id)
session (db/pull '[*] id)
Expand Down Expand Up @@ -188,7 +188,8 @@
:patch {:middleware [[response/wrap-requires-auth]]
:handler PATCH-edit-session}}]
["/:id/edit"
{:get {:handler GET-session-edit}}]
{:name :session/edit
:get {:handler GET-session-edit}}]
["/:id/participate"
{:name :session/participate
:post {:middleware [[response/wrap-requires-auth]]
Expand Down
Loading