diff --git a/src/cljs/auto_ap/db.cljs b/src/cljs/auto_ap/db.cljs index 4cea68f8..77af3868 100644 --- a/src/cljs/auto_ap/db.cljs +++ b/src/cljs/auto_ap/db.cljs @@ -4,4 +4,5 @@ {:company {:name "Campbell brewery"} :invoices {:pending #{} :unpaid #{}} + :status {:loading false} }) diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index 3f6f451d..9d88dfd3 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -32,7 +32,8 @@ (re-frame/reg-event-fx ::view-unpaid-invoices (fn [cofx []] - {:http {:method :get + {:db (assoc-in (:db cofx) [:status :loading] true) + :http {:method :get :uri "/api/invoices/unpaid" :on-success [::received-invoices :unpaid]}})) @@ -47,4 +48,7 @@ (re-frame/reg-event-db ::received-invoices (fn [db [_ type new-invoices]] - (assoc-in db [:invoices type] new-invoices))) + (-> db + (assoc-in [:invoices type] new-invoices) + (assoc-in [:status :loading] false) + ))) diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index 4e384842..f406652f 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -20,3 +20,8 @@ ::unpaid-invoices (fn [db] (:unpaid (:invoices db)))) + +(re-frame/reg-sub + ::status + (fn [db] + (:status db))) diff --git a/src/cljs/auto_ap/views.cljs b/src/cljs/auto_ap/views.cljs index 6a20d72a..1bca1553 100644 --- a/src/cljs/auto_ap/views.cljs +++ b/src/cljs/auto_ap/views.cljs @@ -32,8 +32,7 @@ :paramName "file" :url "/pdf-upload" :previewsContainer "#dz-hidden" - :previewTemplate "
" - })))})) + :previewTemplate "
"})))})) (defmulti active-page identity) @@ -49,25 +48,29 @@ (defmethod active-page :unpaid-invoices [] [(with-meta (fn [] - (let [invoices (re-frame/subscribe [::subs/unpaid-invoices])] - + (let [invoices (re-frame/subscribe [::subs/unpaid-invoices]) + status (re-frame/subscribe [::subs/status])] [:div {:class "inbox-messages"} [:h1.title "Unpaid invoices"] - [:table {:class "table", :style {:width "100%"}} - [:thead - [:tr - [:th "Customer"] - [:th "Invoice #"] - [:th "Date"] - [:th "Amount"]]] - [:tbody (for [{:keys [customer-identifier invoice-number date total id] :as i} @invoices] - ^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)} - [:tr - [:td customer-identifier] - [:td invoice-number] - [:td date] - [:td total]])]]])) - {:component-did-mount #(re-frame/dispatch [::events/view-unpaid-invoices]) })]) + (if (:loading @status) + [:div {:class "inbox-messages"} + [:h1.title + [:i.fa.fa-spin.fa-spinner]]] + [:table {:class "table", :style {:width "100%"}} + [:thead + [:tr + [:th "Customer"] + [:th "Invoice #"] + [:th "Date"] + [:th "Amount"]]] + [:tbody (for [{:keys [customer-identifier invoice-number date total id] :as i} @invoices] + ^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)} + [:tr + [:td customer-identifier] + [:td invoice-number] + [:td date] + [:td total]])]])])) + {:component-will-mount #(re-frame/dispatch-sync [::events/view-unpaid-invoices]) })]) (defmethod active-page :paid-invoices [] [:div {:class "inbox-messages"} @@ -121,7 +124,7 @@ (re-frame/dispatch [::events/reject-invoices]))} "Reject all"] ]]])) - {:component-did-mount (fn [] + {:component-will-mount (fn [] (go (->> (