Show spinner when repos are loading

This commit is contained in:
Teemu Patja 2017-01-30 21:06:17 +02:00
parent da7107ce87
commit fb136e656d
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
4 changed files with 15 additions and 4 deletions

View File

@ -4,6 +4,7 @@
{:page :issues {:page :issues
:user nil :user nil
:user-profile nil :user-profile nil
:repos-loading? false
:repos [] :repos []
:enabled-repos {} :enabled-repos {}
:all-bounties [] :all-bounties []

View File

@ -111,12 +111,14 @@
(reg-event-db (reg-event-db
:set-user-repos :set-user-repos
(fn [db [_ repos]] (fn [db [_ repos]]
(assoc db :repos repos))) (-> db
(assoc :repos repos)
(assoc :repos-loading? false))))
(reg-event-fx (reg-event-fx
:load-user-repos :load-user-repos
(fn [{:keys [db]} [_]] (fn [{:keys [db]} [_]]
{:db db {:db (assoc db :repos-loading? true)
:http {:method GET :http {:method GET
:url "/api/user/repositories" :url "/api/user/repositories"
:on-success #(dispatch [:set-user-repos (:repositories %)])}})) :on-success #(dispatch [:set-user-repos (:repositories %)])}}))

View File

@ -22,10 +22,13 @@
[:p.text-gray.mt-1 description]]]])) [:p.text-gray.mt-1 description]]]]))
(defn repos-list [] (defn repos-list []
(let [repos (rf/subscribe [:repos])] (let [repos-loading? (rf/subscribe [:repos-loading?])
repos (rf/subscribe [:repos])]
(fn [] (fn []
[:div [:div
(map repository-row @repos)]))) (if @repos-loading?
[:i.fa.fa-spinner.fa-spin]
(map repository-row @repos))])))
(defn enable-disable-button (defn enable-disable-button
[button-id disable] [button-id disable]

View File

@ -11,6 +11,11 @@
(fn [db _] (fn [db _]
(:user db))) (:user db)))
(reg-sub
:repos-loading?
(fn [db _]
(:repos-loading? db)))
(reg-sub (reg-sub
:repos :repos
(fn [db _] (fn [db _]