Skip to content

Commit

Permalink
Fix(?) session image handling
Browse files Browse the repository at this point in the history
  • Loading branch information
plexus committed Aug 26, 2024
1 parent be28075 commit 89b90aa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/co/gaiwan/compass/html/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@
(o/defstyled session-image+guage :div
:p-2
[capacity-gauge :w-100px]
([{:session/keys [signup-count capacity image] :as session} user]
([{:session/keys [signup-count capacity] :as session} user]
[capacity-gauge {:capacity #_(rand) (/ (or signup-count 0) (max capacity 1))
:image (if image
(str "url(" image ")")
(str "var(--gradient-" (inc (mod (:db/id session) 7)) ")"))
:image (session/session-image-css-value session)
:checked? (session/participating? session user)}]))

(defn fmt-dur [dur-str]
Expand Down
9 changes: 9 additions & 0 deletions src/co/gaiwan/compass/model/assets.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns co.gaiwan.compass.model.assets
(:require
[clojure.string :as str]
[co.gaiwan.compass.config :as config]))

(defn asset-url [url]
(if (str/starts-with? url "http")
url
(str (config/value :http/asset-path) "/" url)))
6 changes: 6 additions & 0 deletions src/co/gaiwan/compass/model/session.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Computed properties and helpers functions."
(:require
[co.gaiwan.compass.model.assets :as assets]
[java-time.api :as time]))

(defn participating?
Expand Down Expand Up @@ -111,3 +112,8 @@
(apply-filter sessions user k v))
sessions
(merge default-filters filters)))

(defn session-image-css-value [session]
(if-let [url (:session/image session)]
(str "url(" (assets/asset-url url) ")")
(str "var(--gradient-" (inc (mod (:db/id session) 7)) ")")))
5 changes: 2 additions & 3 deletions src/co/gaiwan/compass/model/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[clojure.java.io :as io]
[clojure.string :as str]
[co.gaiwan.compass.config :as config]
[co.gaiwan.compass.model.assets :as assets]
[hato.client :as hato])
(:import
(java.security MessageDigest)
Expand All @@ -28,9 +29,7 @@

(defn avatar-css-value [user]
(if-let [url (:public-profile/avatar-url user)]
(if (str/starts-with? url "http")
(str "url(" url ")")
(str "url(" (config/value :http/asset-path) "/" url ")"))
(str "url(" (assets/asset-url url) ")")
(str "var(--gradient-" (inc (mod (:db/id user) 7)) ")")))

(defn download-avatar [url]
Expand Down

0 comments on commit 89b90aa

Please sign in to comment.