From 89b90aa61770952ff6c68704ad8960b7f395286b Mon Sep 17 00:00:00 2001 From: Arne Brasseur Date: Mon, 26 Aug 2024 11:11:46 +0200 Subject: [PATCH] Fix(?) session image handling --- src/co/gaiwan/compass/html/sessions.clj | 6 ++---- src/co/gaiwan/compass/model/assets.clj | 9 +++++++++ src/co/gaiwan/compass/model/session.clj | 6 ++++++ src/co/gaiwan/compass/model/user.clj | 5 ++--- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/co/gaiwan/compass/model/assets.clj diff --git a/src/co/gaiwan/compass/html/sessions.clj b/src/co/gaiwan/compass/html/sessions.clj index a6a94fa..ee29060 100644 --- a/src/co/gaiwan/compass/html/sessions.clj +++ b/src/co/gaiwan/compass/html/sessions.clj @@ -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] diff --git a/src/co/gaiwan/compass/model/assets.clj b/src/co/gaiwan/compass/model/assets.clj new file mode 100644 index 0000000..017746e --- /dev/null +++ b/src/co/gaiwan/compass/model/assets.clj @@ -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))) diff --git a/src/co/gaiwan/compass/model/session.clj b/src/co/gaiwan/compass/model/session.clj index c7ab04d..6bbd26d 100644 --- a/src/co/gaiwan/compass/model/session.clj +++ b/src/co/gaiwan/compass/model/session.clj @@ -3,6 +3,7 @@ Computed properties and helpers functions." (:require + [co.gaiwan.compass.model.assets :as assets] [java-time.api :as time])) (defn participating? @@ -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)) ")"))) diff --git a/src/co/gaiwan/compass/model/user.clj b/src/co/gaiwan/compass/model/user.clj index e28eca8..e76e072 100644 --- a/src/co/gaiwan/compass/model/user.clj +++ b/src/co/gaiwan/compass/model/user.clj @@ -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) @@ -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]