Skip to content

Commit 38c7ff5

Browse files
Gaiwan devArielA147plexus
committed
User page cleanup
- return single profile from user-profile query - get rid of global slack-instance var - move CSS to garden - make template more straightforward, instead of for+select-keys Co-authored-by: Ariel Alexi <[email protected]> Co-authored-by: Arne Brasseur <[email protected]>
1 parent efbdbba commit 38c7ff5

File tree

4 files changed

+75
-57
lines changed

4 files changed

+75
-57
lines changed

src/clojurians_log/db/queries.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@
112112
(defn user-profile
113113
"returing all the data about the user acording to the user id slack number"
114114
[db id]
115-
(first (d/q '[:find (pull ?user [*])
116-
:in $ ?id
117-
:where [?user :user/slack-id ?id]]
118-
db
119-
id)))
115+
(ffirst (d/q '[:find (pull ?user [*])
116+
:in $ ?id
117+
:where [?user :user/slack-id ?id]]
118+
db
119+
id)))
120120

121121
(defn thread-messages
122122
"Retrieve all child messages for the given parent threads"

src/clojurians_log/routes.clj

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,13 @@
132132
views/about
133133
response/render))
134134

135-
(defn user-profile-route [{:keys [endpoint] :as request}]
136-
(let [db (db-from-endpoint endpoint)]
137-
(-> request
138-
make-context
139-
(assoc :data/user-profile
140-
(queries/user-profile db (get-in request [:path-params :user-id])))
141-
views/user-profile-route
142-
response/render)))
135+
(defn user-profile-route [{:keys [endpoint path-params] :as request}]
136+
(let [db (db-from-endpoint endpoint)]
137+
(-> request
138+
make-context
139+
(assoc :data/user-profile (queries/user-profile db (:user-id path-params)))
140+
views/user-profile-route
141+
response/render)))
143142

144143
(defn sitemap-route [{:keys [endpoint] :as request}]
145144
(let [config @(get-in endpoint [:config :value])
@@ -166,7 +165,7 @@
166165
[["/" {:name :clojurians-log.routes/index
167166
:get index-route}]
168167
["/_/_/users/{user-id}" {:name :clojurians-log.routes/user-profile-route
169-
:get user-profile-route}]
168+
:get user-profile-route}]
170169
["/x/x/x/about" {:name :clojurians-log.routes/about
171170
:get about-route}]
172171
["/x/x/x/sitemap" {:name :clojurians-log.routes/sitemap
@@ -178,9 +177,5 @@
178177
["/{channel}/{date}" {:name :clojurians-log.routes/channel-date
179178
:get log-route}]
180179
["/{channel}/{date}/{ts}" {:name :clojurians-log.routes/message :get log-route}]
181-
["/_/stats/{from-date}/{to-date}" {:name :clojurians-log.routes/message-stats
182-
:get message-stats-route}]
183-
184-
;; {:conflicts nil}
185-
]
186-
)
180+
["/_/stats/{from-date}/{to-date}" {:name :clojurians-log.routes/message-stats
181+
:get message-stats-route}]])

src/clojurians_log/styles.clj

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,28 @@
416416
:line-height "1.33rem"}]
417417
[:ul {:padding-left "1rem"}]
418418
[:li {:list-style-type "disc"}]]
419-
)
419+
420+
[:.user-profile-page
421+
[:h2 {:text-align "center"
422+
:margin-top "20px"
423+
:font-family "sans-serif"}]
424+
[:section {:box-shadow "0 4px 8px 0 rgba(0, 0, 0, 0.2)"
425+
:max-width "350px"
426+
:margin "auto"
427+
:text-align "center"
428+
:font-family "sans-serif"}]
429+
[:img {:width "95%"
430+
:border-radius "80%"
431+
:padding "8px 0px"}]
432+
[:.real-name {:color "grey"
433+
:font-size "18px"}]
434+
[:.talk-on-slack {:border "none"
435+
:outline "0"
436+
:display "inline-block"
437+
:padding "8px 0px"
438+
:color "white"
439+
:background-color "#000"
440+
:text-align "center"
441+
:cursor "pointer"
442+
:width "100%"
443+
:font-size "18px"}]])

src/clojurians_log/views.clj

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
:date future-date})}
171171
[:div.day-next ">"]])]]])
172172

173+
(defn slack-url [ctx & parts]
174+
(apply str
175+
(get-in ctx [:request :clojurians-log.application/slack-instance])
176+
parts))
177+
173178
(defn- single-message
174179
"Returns the hiccup of a single message"
175180
[{:keys [request]
@@ -179,27 +184,25 @@
179184

180185
(let [{:user/keys [name slack-id]
181186
:user-profile/keys [display-name real-name image-48]} user]
182-
(def slack-instance (:clojurians-log.application/slack-instance request))
183-
184-
185187
;; things in the profile
186188
;; :image_512 :email :real_name_normalized :image_48 :image_192 :real_name :image_72 :image_24
187189
;; :avatar_hash :title :team :image_32 :display_name :display_name_normalized
188-
(list [:div.message
189-
{:id (cl.tu/format-inst-id inst) :class (when (thread-child? message) "thread-msg")}
190-
[:a.message_profile-pic {:href (str slack-instance "/users/x/x/" slack-id) :style (str "background-image: url(" image-48 ");")}]
191-
;;[:a.message_username {:href (str slack-instance "/team/" slack-id)}
192-
[:a.message_username {:href (str "/_/_/users/" slack-id)}
193-
(some #(when-not (str/blank? %) %) [display-name real-name name])]
194-
[:span.message_timestamp [:a {:rel "nofollow"
195-
:href (path-for context
196-
:clojurians-log.routes/message
197-
{:channel (:channel/name channel)
198-
:date date
199-
:ts ts})}
200-
(cl.tu/format-inst-time inst)]]
201-
[:span.message_star]
202-
[:span.message_content [:p (slack-messages/message->hiccup text usernames emojis)]]])))
190+
[:div.message
191+
{:id (cl.tu/format-inst-id inst) :class (when (thread-child? message) "thread-msg")}
192+
[:a.message_profile-pic {:href (slack-url context "/users/x/x/" slack-id)
193+
:style (str "background-image: url(" image-48 ");")}]
194+
;;[:a.message_username {:href (str slack-instance "/team/" slack-id)}
195+
[:a.message_username {:href (str "/_/_/users/" slack-id)}
196+
(some #(when-not (str/blank? %) %) [display-name real-name name])]
197+
[:span.message_timestamp [:a {:rel "nofollow"
198+
:href (path-for context
199+
:clojurians-log.routes/message
200+
{:channel (:channel/name channel)
201+
:date date
202+
:ts ts})}
203+
(cl.tu/format-inst-time inst)]]
204+
[:span.message_star]
205+
[:span.message_content [:p (slack-messages/message->hiccup text usernames emojis)]]]))
203206

204207
(defn- message-hiccup
205208
"Returns either a single message hiccup, or if the given message starts a thread,
@@ -284,22 +287,18 @@
284287

285288
(defn- user-profile-html [context]
286289
[:html.user-profile-page
287-
[:body
288-
[:h2 {:style "text-align:center; margin-top: 20px; font-family: sans-serif;"} "User Profile"]
289-
[:div {:style " box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); max-width: 350px;
290-
margin: auto; text-align: center; font-family: sans-serif;"}
291-
292-
(for [[k v] (select-keys (get-in context [:data/user-profile 0])
293-
[:user-profile/display-name :user-profile/real-name :user-profile/image-192 :user/slack-id])
294-
:when (-> k)]
295-
(case k
296-
:user-profile/image-192 [:img {:src v, :style "width:95%; border-radius:80%; padding: 8px 0px;"}]
297-
:user-profile/display-name [:h1 v]
298-
:user-profile/real-name [:p {:style "color: grey; font-size: 18px;"} v]
299-
:user/slack-id [:a {:style "border: none; outline: 0; display: inline-block; padding: 8px 0px;
300-
color: white; background-color: #000; text-align: center; cursor: pointer;
301-
width: 100%; font-size: 18px;"
302-
:href (str slack-instance "/team/" v )} "let's talk on Slack"]))]]])
290+
(page-head context)
291+
[:body
292+
[:h2 "User Profile"]
293+
[:section
294+
(let [user-profile (get-in context [:data/user-profile])
295+
{:user-profile/keys [display-name real-name image-192]
296+
:user/keys [slack-id]} user-profile]
297+
(list
298+
[:img {:src image-192 :alt (str display-name " avatar")}]
299+
[:h1 display-name]
300+
[:p.real-name real-name]
301+
[:a.talk-on-slack {:href (slack-url context "/team/" slack-id)} "let's talk on Slack"]))]]])
303302

304303
(defn- sitemap-xml [{:data/keys [channel-day-tuples http-origin] :as context}]
305304
[:urlset {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
@@ -333,7 +332,7 @@
333332
[:body
334333
[:div
335334
[:h4 "Slack message stats"]
336-
[:p
335+
[:p
337336
[:strong {:style {:border-bottom "1px solid black"}} (:day (first message-stats))]
338337
" to "
339338
[:strong {:style {:border-bottom "1px solid black"}} (:day (last message-stats))]]
@@ -369,4 +368,4 @@
369368
(assoc context :response/xml (sitemap-xml context)))
370369

371370
(defn message-stats-page [context]
372-
(assoc context :response/html (message-stats-page-html context)))
371+
(assoc context :response/html (message-stats-page-html context)))

0 commit comments

Comments
 (0)