From e2e2d225d73562c744e1222132c4b4f82f8e81b9 Mon Sep 17 00:00:00 2001 From: Laurence Chen Date: Fri, 2 Aug 2024 17:57:14 +0800 Subject: [PATCH] - Add page/route to see a profile. Only showing (pr entity) --- src/co/gaiwan/compass/html/profiles.clj | 37 +++++++++++++++++++++++ src/co/gaiwan/compass/http/routes.clj | 2 ++ src/co/gaiwan/compass/routes/profiles.clj | 22 ++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/co/gaiwan/compass/html/profiles.clj create mode 100644 src/co/gaiwan/compass/routes/profiles.clj diff --git a/src/co/gaiwan/compass/html/profiles.clj b/src/co/gaiwan/compass/html/profiles.clj new file mode 100644 index 0000000..b694788 --- /dev/null +++ b/src/co/gaiwan/compass/html/profiles.clj @@ -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)]])) diff --git a/src/co/gaiwan/compass/http/routes.clj b/src/co/gaiwan/compass/http/routes.clj index 40cfb47..982b981 100644 --- a/src/co/gaiwan/compass/http/routes.clj +++ b/src/co/gaiwan/compass/http/routes.clj @@ -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] @@ -12,6 +13,7 @@ [(meta/routes) (home/routes) (sessions/routes) + (profiles/routes) (oauth/routes) ["/fail" {:get {:handler (fn [_] (throw (ex-info "fail" {:fail 1})))}}]]) diff --git a/src/co/gaiwan/compass/routes/profiles.clj b/src/co/gaiwan/compass/routes/profiles.clj new file mode 100644 index 0000000..82be31b --- /dev/null +++ b/src/co/gaiwan/compass/routes/profiles.clj @@ -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))}}]])