|
| 1 | +(ns codes.clj.docs.frontend.panels.author.view |
| 2 | + (:require ["@mantine/core" :refer [Alert Avatar Center Container Group |
| 3 | + LoadingOverlay Text Title Space]] |
| 4 | + ["@tabler/icons-react" :refer [IconInfoCircle]] |
| 5 | + [codes.clj.docs.frontend.components.navigation :refer [back-to-top]] |
| 6 | + [codes.clj.docs.frontend.infra.helix :refer [defnc]] |
| 7 | + [helix.core :refer [$]] |
| 8 | + [helix.dom :as dom])) |
| 9 | + |
| 10 | +(def author-value {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 11 | + :login "rafaeldelboni" |
| 12 | + :account-source "github" |
| 13 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 14 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00" |
| 15 | + :socials [{:definition-id "org.clojure/clojure/clojure.core/assoc/0" |
| 16 | + :notes [{:note-id #uuid "77f27f87-0c60-49cd-bb26-d1eef3ed2453" |
| 17 | + :definition-id "org.clojure/clojure/clojure.core/assoc/0" |
| 18 | + :body "Here is a version that will create a vector when the key is numerical. This may be useful instead of throwing an IndexOutOfBoundsException.\n```clojure\n(defn assoc-in-idx [m [k & ks] v]\n (let [value (get m k (when (number? (first ks)) []))\n m (if (and (vector? m) (number? k) (-> m count (< k)))\n (reduce (fn [m _] (conj m nil)) m (range (count m) k))\n m)\n v (if ks\n (assoc-in-idx value ks v)\n v)]\n (assoc m k v)))\n```\n> copied from [clojuredocs.org](https://clojuredocs.org/clojure.core/assoc) for test" |
| 19 | + :created-at #inst "2024-03-20T14:09:03.779336000-00:00" |
| 20 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 21 | + :login "rafaeldelboni" |
| 22 | + :account-source "github" |
| 23 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 24 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}}] |
| 25 | + :examples [{:example-id #uuid "20292593-cad2-45e9-9c7f-6873863f8a8b" |
| 26 | + :definition-id "org.clojure/clojure/clojure.core/assoc/0" |
| 27 | + :body ";;assoc applied to a vector\n\n(def my-vec [1 2 5 6 8 9])\n\n(assoc my-vec 0 77)\n;;[77 2 5 6 8 9]" |
| 28 | + :created-at #inst "2024-03-20T14:09:23.011242000-00:00" |
| 29 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 30 | + :login "rafaeldelboni" |
| 31 | + :account-source "github" |
| 32 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 33 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"} |
| 34 | + :editors [{:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 35 | + :login "rafaeldelboni" |
| 36 | + :account-source "github" |
| 37 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 38 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00" |
| 39 | + :edited-at #inst "2024-03-20T14:09:23.011242000-00:00"}]}] |
| 40 | + :see-alsos [{:see-also-id #uuid "393ab547-3bb6-406f-9fce-aa1098fdd7c8" |
| 41 | + :definition-id "org.clojure/clojure/clojure.core/assoc/0" |
| 42 | + :definition-id-to "org.clojure/clojure/clojure.core/dissoc/0" |
| 43 | + :created-at #inst "2024-03-21T10:07:35.853221000-00:00" |
| 44 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 45 | + :login "rafaeldelboni" |
| 46 | + :account-source "github" |
| 47 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 48 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}} |
| 49 | + {:see-also-id #uuid "c71ce7d0-d739-43ad-9360-23f28d196af4" |
| 50 | + :definition-id "org.clojure/clojure/clojure.core/assoc/0" |
| 51 | + :definition-id-to "org.clojure/clojure/clojure.core/update/0" |
| 52 | + :created-at #inst "2024-03-21T10:08:04.647016000-00:00" |
| 53 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 54 | + :login "rafaeldelboni" |
| 55 | + :account-source "github" |
| 56 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 57 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}} |
| 58 | + {:see-also-id #uuid "e64be101-17c8-454c-935c-5296a1588f58" |
| 59 | + :definition-id "org.clojure/clojure/clojure.core/assoc/0" |
| 60 | + :definition-id-to "org.clojure/clojure/clojure.core/assoc-in/0" |
| 61 | + :created-at #inst "2024-03-21T11:01:42.085837000-00:00" |
| 62 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 63 | + :login "rafaeldelboni" |
| 64 | + :account-source "github" |
| 65 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 66 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}}]} |
| 67 | + {:definition-id "org.clojure/clojure/clojure.core/keep/0" |
| 68 | + :notes [] |
| 69 | + :examples [{:example-id #uuid "2a0253a8-6edf-4f94-9b63-c9f558064c55" |
| 70 | + :definition-id "org.clojure/clojure/clojure.core/keep/0" |
| 71 | + :body "; removes nil from list or vector\n(keep identity [:a :b nil :d nil :f])\n; => (:a :b :d :f)" |
| 72 | + :created-at #inst "2024-03-27T11:41:57.364949000-00:00" |
| 73 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 74 | + :login "rafaeldelboni" |
| 75 | + :account-source "github" |
| 76 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 77 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"} |
| 78 | + :editors [{:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 79 | + :login "rafaeldelboni" |
| 80 | + :account-source "github" |
| 81 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 82 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00" |
| 83 | + :edited-at #inst "2024-03-27T11:41:57.364949000-00:00"}]}] |
| 84 | + :see-alsos [{:see-also-id #uuid "2657682d-fb87-4b71-807d-9ba86c9160ba" |
| 85 | + :definition-id "org.clojure/clojure/clojure.core/keep/0" |
| 86 | + :definition-id-to "org.clojure/clojure/clojure.core/remove/0" |
| 87 | + :created-at #inst "2024-03-27T11:43:32.582037000-00:00" |
| 88 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 89 | + :login "rafaeldelboni" |
| 90 | + :account-source "github" |
| 91 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 92 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}}]} |
| 93 | + {:definition-id "org.clojure/clojure/clojure.core/take/0" |
| 94 | + :notes [] |
| 95 | + :examples [{:example-id #uuid "dcaccd23-50fe-4a10-a66b-611fc4e776d5" |
| 96 | + :definition-id "org.clojure/clojure/clojure.core/take/0" |
| 97 | + :body "; 6 random integers (from 0 to 60)\n(take 6 (repeatedly #(rand-int 60)))" |
| 98 | + :created-at #inst "2024-03-28T15:36:49.571386000-00:00" |
| 99 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 100 | + :login "rafaeldelboni" |
| 101 | + :account-source "github" |
| 102 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 103 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"} |
| 104 | + :editors [{:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 105 | + :login "rafaeldelboni" |
| 106 | + :account-source "github" |
| 107 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 108 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00" |
| 109 | + :edited-at #inst "2024-03-28T15:36:49.571386000-00:00"}]}] |
| 110 | + :see-alsos [{:see-also-id #uuid "8d18bf94-195e-4459-81ad-f3a0fcb2b85d" |
| 111 | + :definition-id "org.clojure/clojure/clojure.core/take/0" |
| 112 | + :definition-id-to "org.clojure/clojure/clojure.core/repeatedly/0" |
| 113 | + :created-at #inst "2024-03-28T15:37:09.314558000-00:00" |
| 114 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 115 | + :login "rafaeldelboni" |
| 116 | + :account-source "github" |
| 117 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 118 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}}]} |
| 119 | + {:definition-id "org.clojure/clojure/clojure.core/remove/0" |
| 120 | + :notes [] |
| 121 | + :examples [] |
| 122 | + :see-alsos [{:see-also-id #uuid "3daba272-d969-4e55-92f4-052c7ce64a64" |
| 123 | + :definition-id "org.clojure/clojure/clojure.core/remove/0" |
| 124 | + :definition-id-to "org.clojure/clojure/clojure.core/keep/0" |
| 125 | + :created-at #inst "2024-03-27T11:43:50.674432000-00:00" |
| 126 | + :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5" |
| 127 | + :login "rafaeldelboni" |
| 128 | + :account-source "github" |
| 129 | + :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4" |
| 130 | + :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}}]}]}) |
| 131 | + |
| 132 | +; TODO move to adapters & unit test |
| 133 | +(defn author-socials->summary [socials] |
| 134 | + (reduce (fn [{notes-a :notes examples-a :examples see-alsos-a :see-alsos |
| 135 | + :as accum} |
| 136 | + {notes-c :notes examples-c :examples see-alsos-c :see-alsos}] |
| 137 | + (assoc accum |
| 138 | + :notes (+ notes-a (count notes-c)) |
| 139 | + :examples (+ examples-a (count examples-c)) |
| 140 | + :see-alsos (+ see-alsos-a (count see-alsos-c)))) |
| 141 | + {:notes 0 :examples 0 :see-alsos 0} |
| 142 | + socials)) |
| 143 | + |
| 144 | +(defnc author-detail-page [] |
| 145 | + (let [{:keys [loading? error value]} {:loading? false :error nil :value author-value} |
| 146 | + {:keys [login account-source avatar-url socials]} value] |
| 147 | + |
| 148 | + ($ Container {:p "sm"} |
| 149 | + (if loading? |
| 150 | + |
| 151 | + ($ LoadingOverlay {:visible loading? :zIndex 1000 |
| 152 | + :overlayProps #js {:radius "sm" :blur 2}}) |
| 153 | + |
| 154 | + (if error |
| 155 | + ($ Alert {:variant "light" :color "red" |
| 156 | + :radius "md" :title "Error" |
| 157 | + :icon ($ IconInfoCircle)} |
| 158 | + (str error)) |
| 159 | + |
| 160 | + (dom/div |
| 161 | + |
| 162 | + ($ Center |
| 163 | + ($ Group {:wrap "nowrap"} |
| 164 | + ($ Avatar {:src avatar-url |
| 165 | + :size 200 |
| 166 | + :radius 200}) |
| 167 | + (dom/div |
| 168 | + ($ Title {:order 3} |
| 169 | + login) |
| 170 | + |
| 171 | + ($ Text {:fz "xs" :tt "uppercase" :fw 700 :c "dimmed"} |
| 172 | + (name account-source)) |
| 173 | + |
| 174 | + ($ Space {:h "md"}) |
| 175 | + |
| 176 | + ($ Text {:fz "lg" :fw 500} |
| 177 | + (let [{:keys [examples notes see-alsos]} (author-socials->summary socials)] |
| 178 | + (str "This has user has authored " |
| 179 | + examples " examples, " |
| 180 | + notes " notes and " |
| 181 | + see-alsos " see alsos.")))))) |
| 182 | + |
| 183 | + ($ back-to-top))))))) |
0 commit comments