for better or worse, moving to localized events and subs.

This commit is contained in:
Bryce Covert
2018-04-12 21:37:27 -07:00
parent 78ced354de
commit e1e0835bee
5 changed files with 120 additions and 53 deletions

View File

@@ -4,11 +4,10 @@
[reagent.core :as reagent]))
(defn toggle-sort-by [params key]
(-> params
(assoc :sort-by key)
(assoc :asc (if (:asc params)
false
true))))
(update :asc not)))
(defn sort-icon [which sort-by asc]
(cond
@@ -24,14 +23,21 @@
[:span.icon
[:i.fa.fa-sort]]))
(defn invoice-table [{:keys [id invoices status on-params-change vendors]}]
(let [state (reagent/atom {})]
(fn []
(defn query [params]
{:venia/queries [[:invoice
(assoc params
:company-id (:id @(re-frame/subscribe [::subs/company])))
[:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]]]]]})
(defn invoice-table [{:keys [id invoices status on-params-change vendors params]}]
(let [state (reagent/atom (or @params {}))]
(fn [{:keys [id invoices status on-params-change vendors]}]
(let [{:keys [sort-by asc]} @state]
[:table.table.is-fullwidth
[:thead
[:tr
[:th {:on-click (fn [e] (on-params-change (swap! state toggle-sort-by "vendor"))) :style {:width "25%" :cursor "pointer"}} "Vendor"
[:th {:on-click (fn [e]
(on-params-change (swap! state toggle-sort-by "vendor"))) :style {:width "25%" :cursor "pointer"}} "Vendor"
(sort-icon "vendor" sort-by asc)]
[:th {:on-click (fn [e] (on-params-change (swap! state toggle-sort-by "company"))) :style {:width "25%" :cursor "pointer"}} "Company"
(sort-icon "company" sort-by asc)]
@@ -47,7 +53,7 @@
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(for [{:keys [company invoice-number date total id vendor] :as i} @invoices]
^{:key (str company "-" invoice-number "-" date "-" total "-" id)}
^{:key id}
[:tr
[:td (:name vendor)]
[:td (:name company)]