diff options
author | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-12-19 22:46:41 +0100 |
---|---|---|
committer | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-12-19 22:46:41 +0100 |
commit | d787d6c6139d365f5d7f4fa7b37e5455ecc1dca1 (patch) | |
tree | 2f8decba50169726b39beebcb50b2be382a830aa /src | |
parent | ead190b485080a656451fa952bf27d8864da5725 (diff) |
feat: simplify settings event handlers
Diffstat (limited to 'src')
-rw-r--r-- | src/frontend/tubo/settings/events.cljs | 40 | ||||
-rw-r--r-- | src/frontend/tubo/settings/views.cljs | 8 |
2 files changed, 19 insertions, 29 deletions
diff --git a/src/frontend/tubo/settings/events.cljs b/src/frontend/tubo/settings/events.cljs index 57e173f..da1a8d1 100644 --- a/src/frontend/tubo/settings/events.cljs +++ b/src/frontend/tubo/settings/events.cljs @@ -6,9 +6,10 @@ (rf/reg-event-fx :settings/change [(rf/inject-cofx :store)] - (fn [{:keys [db store]} [_ key val]] - {:db (assoc-in db [:settings key] val) - :store (assoc store key val)})) + (fn [{:keys [db store]} [_ keys val]] + (let [update-settings #(assoc-in % (into [:settings] keys) val)] + {:db (update-settings db) + :store (update-settings store)}))) (rf/reg-event-fx :settings/load-kiosks @@ -22,21 +23,17 @@ default-kiosk (if (some #(= % default-service-kiosk) (:available-kiosks kiosks-res)) default-service-kiosk - (:default-kiosk kiosks-res))] - {:db (update-in db - [:settings :default-service] - assoc - :id service-name - :service-id service-id - :available-kiosks (:available-kiosks kiosks-res) - :default-kiosk default-kiosk) - :store (update-in store - [:default-service] - assoc - :id service-name - :service-id service-id - :available-kiosks (:available-kiosks kiosks-res) - :default-kiosk default-kiosk)}))) + (:default-kiosk kiosks-res)) + update-settings #(update-in % + [:settings :default-service] + assoc + :id service-name + :service-id service-id + :available-kiosks (:available-kiosks + kiosks-res) + :default-kiosk default-kiosk)] + {:db (update-settings db) + :store (update-settings store)}))) (rf/reg-event-fx :settings/change-service @@ -54,13 +51,6 @@ [:bad-response])))) (rf/reg-event-fx - :settings/change-kiosk - [(rf/inject-cofx :store)] - (fn [{:keys [db store]} [_ val]] - {:db (assoc-in db [:settings :default-service :default-kiosk] val) - :store (assoc-in store [:default-service :default-kiosk] val)})) - -(rf/reg-event-fx :settings/fetch-page (fn [{:keys [db]} _] (let [id (-> db diff --git a/src/frontend/tubo/settings/views.cljs b/src/frontend/tubo/settings/views.cljs index 415d474..3afed5e 100644 --- a/src/frontend/tubo/settings/views.cljs +++ b/src/frontend/tubo/settings/views.cljs @@ -5,15 +5,15 @@ [tubo.layout.views :as layout])) (defn boolean-input - [label key value] + [label keys value] [layout/boolean-input label value - #(rf/dispatch [:settings/change key (not value)])]) + #(rf/dispatch [:settings/change keys (not value)])]) (defn select-input - [label key value options on-change] + [label keys value options on-change] [layout/select-input label value options (or on-change - #(rf/dispatch [:settings/change key (.. % -target -value)]))]) + #(rf/dispatch [:settings/change keys (.. % -target -value)]))]) (defn general-settings [{:keys [theme default-service items-layout]}] |