invoice number like incorporates a timeout.

This commit is contained in:
Bryce Covert
2019-02-08 07:40:14 -08:00
parent dccaecf86b
commit 111710365b
2 changed files with 31 additions and 5 deletions

View File

@@ -119,6 +119,19 @@
node)) node))
m)) m))
(defonce timeouts
(atom {}))
(re-frame/reg-fx
:dispatch-debounce
(fn [{:keys [event time key]}]
(js/clearTimeout (@timeouts key))
(swap! timeouts assoc key
(js/setTimeout (fn []
(re-frame/dispatch event)
(swap! timeouts dissoc key))
time))))
(re-frame/reg-fx (re-frame/reg-fx
:graphql :graphql
(fn [{:keys [query on-success on-error token variables query-obj]}] (fn [{:keys [query on-success on-error token variables query-obj]}]

View File

@@ -72,6 +72,7 @@
(fn [db] (fn [db]
(-> db (::params {})))) (-> db (::params {}))))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::params-change ::params-change
(fn [cofx [_ params]] (fn [cofx [_ params]]
@@ -79,7 +80,7 @@
(assoc-in [:status :loading] true) (assoc-in [:status :loading] true)
(assoc-in [::params] params)) (assoc-in [::params] params))
:graphql {:token (-> cofx :db :user) :graphql {:token (-> cofx :db :user)
:query-obj (invoice-table/query (doto (assoc params :imported true) println)) :query-obj (invoice-table/query (-> params (assoc :imported true) (dissoc :invoice-number-like-current)) )
:on-success [::received]}})) :on-success [::received]}}))
(re-frame/reg-event-db (re-frame/reg-event-db
::unmount-invoices ::unmount-invoices
@@ -683,14 +684,26 @@
(assoc-in updated [::params :vendor-id] value)) (assoc-in updated [::params :vendor-id] value))
updated)))) updated))))
(re-frame/reg-event-fx
::invoice-number-like-current-changed
(fn [{:keys [db]} [_ params invoice-like]]
{:db (assoc-in db [::params :invoice-number-like-current] invoice-like )
:dispatch-debounce {:event [::invoice-number-like-settled invoice-like]
:time 500
:key ::invoice-nuber-like}}))
(re-frame/reg-event-fx
::invoice-number-like-settled
(fn [{:keys [db]} [_ invoice-like]]
{:dispatch [::params-change (assoc (::params db) :invoice-number-like invoice-like) ]}))
(defn invoice-number-filter [] (defn invoice-number-filter []
(let [{:keys [invoice-number-like] :as params} @(re-frame/subscribe [::params])] (let [{:keys [invoice-number-like-current] :as params} @(re-frame/subscribe [::params])]
[:div.field [:div.field
[:div.control [:input.input {:placeholder "AP-123" [:div.control [:input.input {:placeholder "AP-123"
:value invoice-number-like :value invoice-number-like-current
:on-change (fn [x] :on-change (fn [x]
(re-frame/dispatch [::params-change (assoc params :invoice-number-like (.. x -target -value) :start 0) ]) (re-frame/dispatch [::invoice-number-like-current-changed params (.. x -target -value) ]))} ]]]))
)} ]]]))
(defn pay-button [{:keys [print-checks-shown? checked-invoices print-checks-loading?]}] (defn pay-button [{:keys [print-checks-shown? checked-invoices print-checks-loading?]}]
(let [current-client @(re-frame/subscribe [::subs/client])] (let [current-client @(re-frame/subscribe [::subs/client])]