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))
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
:graphql
(fn [{:keys [query on-success on-error token variables query-obj]}]

View File

@@ -72,6 +72,7 @@
(fn [db]
(-> db (::params {}))))
(re-frame/reg-event-fx
::params-change
(fn [cofx [_ params]]
@@ -79,7 +80,7 @@
(assoc-in [:status :loading] true)
(assoc-in [::params] params))
: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]}}))
(re-frame/reg-event-db
::unmount-invoices
@@ -683,14 +684,26 @@
(assoc-in updated [::params :vendor-id] value))
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 []
(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.control [:input.input {:placeholder "AP-123"
:value invoice-number-like
:value invoice-number-like-current
: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?]}]
(let [current-client @(re-frame/subscribe [::subs/client])]