Advertisement
Guest User

Untitled

a guest
Aug 29th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn load-users! "Fetches a list of users and adds them to the state"
  2.   [state]
  3.   (ajx/GET "/users/users.json"
  4.     {:handler (fn [users] (swap! state assoc :users users))
  5.      :error-handler (fn [details] (.warn js/console (str "Failed to fetch users!" details)))
  6.      :response-format :json :keywords? true
  7.      :headers {:Access-Control-Allow-Headers "Content-Type"
  8.                :Access-Control-Allow-Origin "*"
  9.                :Access-Control-Allow-Methods "GET"}}))
  10.  
  11. (defn <top-cpnt> []
  12.   (let [{:keys [users search]} @state]
  13.     [:div.container-fluid
  14.      [:div.row
  15.       [:div.col-md-2 [<search-cpnt> search]]
  16.       [:div.col-md-8 [<user-list> users search]]]]))
  17.  
  18. (defn <user-list> "A list of users"
  19.   [user-list search]
  20.   [:div.container-fluid
  21.    [:ul
  22.     (for [user (->> user-list (filter #(matches-search? search %)))]
  23.       ^{:key (:name user)} [<user-item> user])]])
  24.  
  25. (defn <user-item> "A single user"
  26.   [{:keys [DisplayName Title id] :as user}]
  27.   [:a {:href (path-for :user-id {:id id})}
  28.    [:li.user-item
  29.     [:span "Name: " DisplayName]
  30.     [:p "Title: " Title]]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement