Skip to content

Commit

Permalink
- Add page/route to see a profile. Only showing (pr entity)
Browse files Browse the repository at this point in the history
  • Loading branch information
humorless committed Aug 2, 2024
1 parent c1fe4c4 commit e2e2d22
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/co/gaiwan/compass/html/profiles.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(ns co.gaiwan.compass.html.profiles
"Views and components (hiccup/ornament) related to profiles"
{:ornament/prefix "profiles-"}
(:require
[clojure.string :as str]
[co.gaiwan.compass.css.tokens :as t :refer :all]
[java-time.api :as time]
[co.gaiwan.compass.html.sessions :as s]
[lambdaisland.ornament :as o]))

(o/defprop --arc-thickness "30px")

(o/defstyled image-frame :div
[:.img :w-full
{:padding --arc-thickness
#_#_:margin-left "-100%"}
[:>* :w-full :aspect-square :rounded-full
{:background-size "cover"
:background-position "50% 50%"}]]
([{:profile/keys [image] :as profile} user]
[:<>
[:div.img
[:div
{:style {:background-image image}}]]]))

(o/defstyled profile-detail :div
[image-frame :w-100px]
([{:discord/keys [access-token id refresh-token expires-at]
:user/keys [email handle name uuid image] :as profile}
user]
[:<>
[image-frame {:profile/image
(if image
(str "url(" image ")")
(str "var(--gradient-" (inc (rand-int 7)) ")"))} user]
[:div.details
(pr-str profile)]]))
2 changes: 2 additions & 0 deletions src/co/gaiwan/compass/http/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[co.gaiwan.compass.config :as config]
[co.gaiwan.compass.http.oauth :as oauth]
[co.gaiwan.compass.routes.sessions :as sessions]
[co.gaiwan.compass.routes.profiles :as profiles]
[co.gaiwan.compass.routes.home :as home]
[co.gaiwan.compass.routes.meta :as meta]
[hato.client :as hato]
Expand All @@ -12,6 +13,7 @@
[(meta/routes)
(home/routes)
(sessions/routes)
(profiles/routes)
(oauth/routes)
["/fail" {:get {:handler (fn [_] (throw (ex-info "fail" {:fail 1})))}}]])

Expand Down
22 changes: 22 additions & 0 deletions src/co/gaiwan/compass/routes/profiles.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(ns co.gaiwan.compass.routes.profiles
"We need a page/route for user's profile"
(:require
[clojure.string :as str]
[co.gaiwan.compass.db :as db]
[co.gaiwan.compass.html.profiles :as h]
[co.gaiwan.compass.http.oauth :as oauth]
[co.gaiwan.compass.util :as util]
[io.pedestal.log :as log]
[java-time.api :as time]))

(defn GET-profile [req]
(let [profile-eid (parse-long (get-in req [:path-params :id]))]
{:html/body [h/profile-detail
(db/entity profile-eid)
(:identity req)]}))

(defn routes []
["/profiles"
["/:id"
{:get {:handler (fn [req]
(GET-profile req))}}]])

0 comments on commit e2e2d22

Please sign in to comment.