Skip to content

Commit faac85c

Browse files
committed
feat(dashboard): adds recently updated component and time-since fn
1 parent 1237400 commit faac85c

File tree

5 files changed

+115
-85
lines changed

5 files changed

+115
-85
lines changed

:w

-47
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(ns codes.clj.docs.frontend.adapters.time)
2+
3+
(def MINUTE 60)
4+
(def HOUR (* MINUTE 60))
5+
(def DAY (* HOUR 24))
6+
(def WEEK (* DAY 7))
7+
(def MONTH (* DAY 30))
8+
(def YEAR (* DAY 365))
9+
10+
(defn time-since [date now]
11+
(let [seconds-ago (-> (- now date)
12+
(/ 1000)
13+
Math/round)
14+
{:keys [divisor unit]} (cond
15+
(< seconds-ago MINUTE) {:divisor 1 :unit "second"}
16+
(< seconds-ago HOUR) {:divisor MINUTE :unit "minute"}
17+
(< seconds-ago DAY) {:divisor HOUR :unit "hour"}
18+
(< seconds-ago WEEK) {:divisor DAY :unit "day"}
19+
(< seconds-ago MONTH) {:divisor WEEK :unit "week"}
20+
(< seconds-ago YEAR) {:divisor MONTH :unit "month"}
21+
:else {:divisor YEAR :unit "year"})
22+
value (-> (/ seconds-ago divisor)
23+
Math/floor)
24+
plural? (if (> value 1) "s" "")]
25+
(str value " " unit plural? " ago")))

src/codes/clj/docs/frontend/components/query.cljs

+29-37
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
(ns codes.clj.docs.frontend.components.query
2-
(:require ["@mantine/core" :refer [Alert Anchor Avatar Grid Group Indicator
3-
LoadingOverlay SimpleGrid Text Title
4-
Tooltip]]
2+
(:require ["@mantine/core" :refer [Alert Anchor Avatar Box Grid Group
3+
Indicator LoadingOverlay SimpleGrid Text
4+
Title Tooltip]]
55
["@tabler/icons-react" :refer [IconInfoCircle]]
6+
[clojure.string :as str]
67
[codes.clj.docs.frontend.infra.helix :refer [defnc]]
7-
[helix.core :refer [$]]
8-
[helix.dom :as dom]))
8+
[codes.clj.docs.frontend.adapters.time :as adapters.time]
9+
[helix.core :refer [$]]))
910

1011
(defnc latest-interactions [{:keys [value loading? error]}]
1112
($ SimpleGrid {:cols 1}
@@ -15,42 +16,31 @@
1516
($ Alert {:variant "light" :color "red" :radius "md" :title "Error" :icon ($ IconInfoCircle)}
1617
(str error))
1718

18-
($ Group {:pos "relative" :grow true}
19-
($ LoadingOverlay {:visible loading? :zIndex 1000 :overlayProps #js {:radius "sm" :blur 2}})
19+
($ Box {:pos "relative"}
20+
($ LoadingOverlay {:visible loading? :zIndex 1000
21+
:loaderProps #js {:type "dots"}
22+
:overlayProps #js {:radius "sm" :blur 2}})
2023
($ SimpleGrid {:cols 2}
2124
(map
22-
(fn [{:keys [author]}]
23-
(let [{:keys [author-id login account-source avatar-url]} author]
24-
($ Group {:key (str "latest" author-id) :grow true}
25+
(fn [{:keys [note-id example-id see-also-id definition-id author created-at]}]
26+
(let [id (str "latest" (or note-id example-id see-also-id))
27+
action (cond
28+
note-id " authored a note for "
29+
example-id " authored an example for "
30+
see-also-id " added a see also on ")
31+
definition (str/replace definition-id #"/0$" "")
32+
ago (adapters.time/time-since created-at (.now js/Date))
33+
{:keys [login account-source avatar-url]} author]
34+
($ Group {:key id :wrap "nowrap"}
2535
($ Anchor {:href (str "/author/" login "/" account-source)}
26-
($ Avatar {:size "md" :src avatar-url}))
27-
28-
(dom/div
29-
($ Text "banana")))))
30-
36+
($ Avatar {:src avatar-url}))
37+
($ Text {:size "sm"} login
38+
($ Text {:component "span"}
39+
action " "
40+
($ Anchor {:href definition-id} definition)
41+
" " ago ".")))))
3142
value))))))
3243

33-
; <UnstyledButton className={classes.user}>
34-
; <Group>
35-
; <Avatar
36-
; src="https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-8.png"
37-
; radius="xl"
38-
; />
39-
;
40-
; <div style={{ flex: 1 }}>
41-
; <Text size="sm" fw={500}>
42-
; Harriette Spoonlicker
43-
; </Text>
44-
;
45-
; <Text c="dimmed" size="xs">
46-
47-
; </Text>
48-
; </div>
49-
;
50-
; <IconChevronRight style={{ width: rem(14), height: rem(14) }} stroke={1.5} />
51-
; </Group>
52-
; </UnstyledButton>
53-
5444
(defnc top-author [{:keys [value loading? error]}]
5545
($ SimpleGrid {:cols 1}
5646
($ Title {:order 1} "Top Authors")
@@ -60,7 +50,9 @@
6050
(str error))
6151

6252
($ Group {:pos "relative"}
63-
($ LoadingOverlay {:visible loading? :zIndex 1000 :overlayProps #js {:radius "sm" :blur 2}})
53+
($ LoadingOverlay {:visible loading? :zIndex 1000
54+
:loaderProps #js {:type "dots"}
55+
:overlayProps #js {:radius "sm" :blur 2}})
6456
($ Grid {:grow false :gutter "lg"}
6557
(map
6658
(fn [{:keys [author-id login account-source interactions avatar-url]}]

0 commit comments

Comments
 (0)