Persist filter category settings to localstorage

Fixes #121
This commit is contained in:
Daniel Compton 2017-12-19 21:21:16 +13:00
parent 08c19d13b3
commit d5e8c154f2
4 changed files with 26 additions and 12 deletions

View File

@ -10,7 +10,8 @@
app-db-paths (localstorage/get "app-db-paths" '()) app-db-paths (localstorage/get "app-db-paths" '())
json-ml-paths (localstorage/get "app-db-json-ml-expansions" #{}) json-ml-paths (localstorage/get "app-db-json-ml-expansions" #{})
external-window? (localstorage/get "external-window?" false) external-window? (localstorage/get "external-window?" false)
using-trace? (localstorage/get "using-trace?" true)] using-trace? (localstorage/get "using-trace?" true)
categories (localstorage/get "categories" #{:event :sub/run :sub/create :sub/dispose})]
(when using-trace? (when using-trace?
(rf/dispatch [:global/enable-tracing])) (rf/dispatch [:global/enable-tracing]))
(rf/dispatch [:settings/panel-width% panel-width%]) (rf/dispatch [:settings/panel-width% panel-width%])
@ -19,6 +20,7 @@
(when external-window? (when external-window?
(rf/dispatch [:global/launch-external])) (rf/dispatch [:global/launch-external]))
(rf/dispatch [:traces/filter-items filter-items]) (rf/dispatch [:traces/filter-items filter-items])
(rf/dispatch [:traces/toggle-categories categories])
(rf/dispatch [:app-db/paths app-db-paths]) (rf/dispatch [:app-db/paths app-db-paths])
(rf/dispatch [:app-db/set-json-ml-paths json-ml-paths]) (rf/dispatch [:app-db/set-json-ml-paths json-ml-paths])
(rf/dispatch [:global/add-unload-hook]))) (rf/dispatch [:global/add-unload-hook])))

View File

@ -7,7 +7,8 @@
[goog.object] [goog.object]
[re-frame.db] [re-frame.db]
[day8.re-frame.trace.view.container :as container] [day8.re-frame.trace.view.container :as container]
[day8.re-frame.trace.styles :as styles])) [day8.re-frame.trace.styles :as styles]
[clojure.set :as set]))
(defonce traces (r/atom [])) (defonce traces (r/atom []))
(defonce total-traces (r/atom 0)) (defonce total-traces (r/atom 0))
@ -213,6 +214,16 @@
(let [showing? (get-in expansions [:overrides id] (:show-all? expansions))] (let [showing? (get-in expansions [:overrides id] (:show-all? expansions))]
(update-in expansions [:overrides id] #(if showing? false (not %)))))) (update-in expansions [:overrides id] #(if showing? false (not %))))))
(rf/reg-event-db
:traces/toggle-categories
[(rf/path [:traces :categories])]
(fn [categories [_ new-categories]]
(let [new-categories (if (set/superset? categories new-categories)
(set/difference categories new-categories)
(set/union categories new-categories))]
(localstorage/save! "categories" new-categories)
new-categories)))
;; App DB ;; App DB
(rf/reg-event-db (rf/reg-event-db

View File

@ -67,6 +67,11 @@
(fn [db _] (fn [db _]
(get-in db [:traces :expansions]))) (get-in db [:traces :expansions])))
(rf/reg-sub
:traces/categories
(fn [db _]
(get-in db [:traces :categories])))
(rf/reg-sub (rf/reg-sub
:global/unloading? :global/unloading?
(fn [db _] (fn [db _]

View File

@ -85,14 +85,10 @@
filter-items (rf/subscribe [:traces/filter-items]) filter-items (rf/subscribe [:traces/filter-items])
filter-type (r/atom :contains) filter-type (r/atom :contains)
input-error (r/atom false) input-error (r/atom false)
categories (r/atom #{:event :sub/run :sub/create :sub/dispose}) categories (rf/subscribe [:traces/categories])
trace-detail-expansions (rf/subscribe [:traces/expansions])] trace-detail-expansions (rf/subscribe [:traces/expansions])]
(fn [] (fn []
(let [toggle-category-fn (fn [category-keys] (let [toggle-category-fn #(rf/dispatch [:traces/toggle-categories %])
(swap! categories #(if (set/superset? % category-keys)
(set/difference % category-keys)
(set/union % category-keys))))
visible-traces (cond->> @traces visible-traces (cond->> @traces
;; Remove cached subscriptions. Could add this back in as a setting later ;; Remove cached subscriptions. Could add this back in as a setting later
;; but it's pretty low signal/noise 99% of the time. ;; but it's pretty low signal/noise 99% of the time.
@ -112,16 +108,16 @@
[:div.filter-control [:div.filter-control
[:ul.filter-categories "show: " [:ul.filter-categories "show: "
[:li.filter-category {:class (when (contains? @categories :event) "active") [:li.filter-category {:class (when (contains? @categories :event) "active")
:on-click #(toggle-category-fn #{:event})} :on-click #(rf/dispatch [:traces/toggle-categories #{:event}])}
"events"] "events"]
[:li.filter-category {:class (when (contains? @categories :sub/run) "active") [:li.filter-category {:class (when (contains? @categories :sub/run) "active")
:on-click #(toggle-category-fn #{:sub/run :sub/create :sub/dispose})} :on-click #(rf/dispatch [:traces/toggle-categories #{:sub/run :sub/create :sub/dispose}])}
"subscriptions"] "subscriptions"]
[:li.filter-category {:class (when (contains? @categories :render) "active") [:li.filter-category {:class (when (contains? @categories :render) "active")
:on-click #(toggle-category-fn #{:render})} :on-click #(rf/dispatch [:traces/toggle-categories #{:render}])}
"reagent"] "reagent"]
[:li.filter-category {:class (when (contains? @categories :re-frame.router/fsm-trigger) "active") [:li.filter-category {:class (when (contains? @categories :re-frame.router/fsm-trigger) "active")
:on-click #(toggle-category-fn #{:re-frame.router/fsm-trigger :componentWillUnmount})} :on-click #(rf/dispatch [:traces/toggle-categories #{:re-frame.router/fsm-trigger :componentWillUnmount}])}
"internals"]] "internals"]]
[:div.filter-fields [:div.filter-fields
[:select {:value @filter-type [:select {:value @filter-type