From 27fbade39229093e4d83e4b90f2a4fd743306b53 Mon Sep 17 00:00:00 2001 From: Bryce Date: Mon, 4 Sep 2023 14:44:53 -0700 Subject: [PATCH] defaults to a single client if there is only one client. --- src/cljs/auto_ap/events.cljs | 32 ++++++++++++++++++++------------ src/cljs/auto_ap/subs.cljs | 1 + 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index 5f397d35..708b75b4 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -116,18 +116,26 @@ (re-frame/reg-event-fx ::received-initial (fn [{:keys [db]} [_ {clients :client}]] - {:db (-> db - (assoc :clients (by :id clients) ) - (assoc :is-initial-loading? false) - (assoc :client (or (when (= 1 (count clients)) (->> clients first :id )) - (->> clients - (map :id) - (filter #(= % (:last-client-id db))) - first)))) - :interval {:action :start - :id :refresh-clients - :frequency 600000 - :event [::refresh-clients]}})) + (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 :is-initial-loading? false) + (assoc :client (or only-one-client + (->> clients + (map :id) + (filter #(= % (:last-client-id db))) + first)))) + only-one-client (assoc :last-client-id only-one-client + :selected-clients [only-one-client])) + :interval {:action :start + :id :refresh-clients + :frequency 600000 + :event [::refresh-clients]}}))) (re-frame/reg-event-fx ::refresh-clients diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index 20f30c46..1f488860 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -17,6 +17,7 @@ ::client :<- [::selected-clients] (fn [selected-clients] + (println "SELECTED CLIENTS ARE" selected-clients) (when (= 1 (count selected-clients)) (first selected-clients))))