a little ux

This commit is contained in:
Bryce Covert
2017-12-09 14:49:09 -08:00
parent 02a1ad0d47
commit e368b719ec
4 changed files with 35 additions and 22 deletions

View File

@@ -4,4 +4,5 @@
{:company {:name "Campbell brewery"} {:company {:name "Campbell brewery"}
:invoices {:pending #{} :invoices {:pending #{}
:unpaid #{}} :unpaid #{}}
:status {:loading false}
}) })

View File

@@ -32,7 +32,8 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::view-unpaid-invoices ::view-unpaid-invoices
(fn [cofx []] (fn [cofx []]
{:http {:method :get {:db (assoc-in (:db cofx) [:status :loading] true)
:http {:method :get
:uri "/api/invoices/unpaid" :uri "/api/invoices/unpaid"
:on-success [::received-invoices :unpaid]}})) :on-success [::received-invoices :unpaid]}}))
@@ -47,4 +48,7 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::received-invoices ::received-invoices
(fn [db [_ type new-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)
)))

View File

@@ -20,3 +20,8 @@
::unpaid-invoices ::unpaid-invoices
(fn [db] (fn [db]
(:unpaid (:invoices db)))) (:unpaid (:invoices db))))
(re-frame/reg-sub
::status
(fn [db]
(:status db)))

View File

@@ -32,8 +32,7 @@
:paramName "file" :paramName "file"
:url "/pdf-upload" :url "/pdf-upload"
:previewsContainer "#dz-hidden" :previewsContainer "#dz-hidden"
:previewTemplate "<div class='dz-hidden-preview'></div>" :previewTemplate "<div class='dz-hidden-preview'></div>"})))}))
})))}))
(defmulti active-page identity) (defmulti active-page identity)
@@ -49,25 +48,29 @@
(defmethod active-page :unpaid-invoices [] (defmethod active-page :unpaid-invoices []
[(with-meta [(with-meta
(fn [] (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"} [:div {:class "inbox-messages"}
[:h1.title "Unpaid invoices"] [:h1.title "Unpaid invoices"]
[:table {:class "table", :style {:width "100%"}} (if (:loading @status)
[:thead [:div {:class "inbox-messages"}
[:tr [:h1.title
[:th "Customer"] [:i.fa.fa-spin.fa-spinner]]]
[:th "Invoice #"] [:table {:class "table", :style {:width "100%"}}
[:th "Date"] [:thead
[:th "Amount"]]] [:tr
[:tbody (for [{:keys [customer-identifier invoice-number date total id] :as i} @invoices] [:th "Customer"]
^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)} [:th "Invoice #"]
[:tr [:th "Date"]
[:td customer-identifier] [:th "Amount"]]]
[:td invoice-number] [:tbody (for [{:keys [customer-identifier invoice-number date total id] :as i} @invoices]
[:td date] ^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)}
[:td total]])]]])) [:tr
{:component-did-mount #(re-frame/dispatch [::events/view-unpaid-invoices]) })]) [: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 [] (defmethod active-page :paid-invoices []
[:div {:class "inbox-messages"} [:div {:class "inbox-messages"}
@@ -121,7 +124,7 @@
(re-frame/dispatch [::events/reject-invoices]))} (re-frame/dispatch [::events/reject-invoices]))}
"Reject all"] "Reject all"]
]]])) ]]]))
{:component-did-mount (fn [] {:component-will-mount (fn []
(go (go
(->> (<! (http/get "/api/invoices/pending")) (->> (<! (http/get "/api/invoices/pending"))
:body :body