defaults to a single client if there is only one client.
This commit is contained in:
@@ -116,18 +116,26 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::received-initial
|
::received-initial
|
||||||
(fn [{:keys [db]} [_ {clients :client}]]
|
(fn [{:keys [db]} [_ {clients :client}]]
|
||||||
{:db (-> db
|
(let [only-one-client (when (= 1 (count clients))
|
||||||
|
(->> clients first :id ))]
|
||||||
|
(when only-one-client
|
||||||
|
(.setItem js/localStorage "last-client-id" only-one-client)
|
||||||
|
(.setItem js/localStorage "last-selected-clients"
|
||||||
|
(pr-str [(js/parseInt only-one-client)])))
|
||||||
|
{:db (cond-> (-> db
|
||||||
(assoc :clients (by :id clients) )
|
(assoc :clients (by :id clients) )
|
||||||
(assoc :is-initial-loading? false)
|
(assoc :is-initial-loading? false)
|
||||||
(assoc :client (or (when (= 1 (count clients)) (->> clients first :id ))
|
(assoc :client (or only-one-client
|
||||||
(->> clients
|
(->> clients
|
||||||
(map :id)
|
(map :id)
|
||||||
(filter #(= % (:last-client-id db)))
|
(filter #(= % (:last-client-id db)))
|
||||||
first))))
|
first))))
|
||||||
|
only-one-client (assoc :last-client-id only-one-client
|
||||||
|
:selected-clients [only-one-client]))
|
||||||
:interval {:action :start
|
:interval {:action :start
|
||||||
:id :refresh-clients
|
:id :refresh-clients
|
||||||
:frequency 600000
|
:frequency 600000
|
||||||
:event [::refresh-clients]}}))
|
:event [::refresh-clients]}})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::refresh-clients
|
::refresh-clients
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
::client
|
::client
|
||||||
:<- [::selected-clients]
|
:<- [::selected-clients]
|
||||||
(fn [selected-clients]
|
(fn [selected-clients]
|
||||||
|
(println "SELECTED CLIENTS ARE" selected-clients)
|
||||||
(when (= 1 (count selected-clients))
|
(when (= 1 (count selected-clients))
|
||||||
(first selected-clients))))
|
(first selected-clients))))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user