diff --git a/src/day8/re_frame/trace/components/container.cljs b/src/day8/re_frame/trace/components/container.cljs index 1dd51c2..0790ed1 100644 --- a/src/day8/re_frame/trace/components/container.cljs +++ b/src/day8/re_frame/trace/components/container.cljs @@ -5,6 +5,7 @@ [day8.re-frame.trace.panels.subvis :as subvis] [day8.re-frame.trace.panels.traces :as traces] [day8.re-frame.trace.panels.subs :as subs] + [day8.re-frame.trace.panels.save :as save] [re-frame.trace] [reagent.core :as r])) @@ -29,7 +30,8 @@ (tab-button :traces "Traces") (tab-button :app-db "App DB") (tab-button :subs "Subs") - #_ (tab-button :subvis "SubVis") + (tab-button :save "Save") + #_(tab-button :subvis "SubVis") (when-not external-window? [:img.popout-icon {:src (str "data:image/svg+xml;utf8," @@ -40,4 +42,5 @@ :app-db [app-db/render-state db/app-db] :subvis [subvis/render-subvis traces] :subs [subs/subs-panel] + :save [save/save-panel] [app-db/render-state db/app-db])])) diff --git a/src/day8/re_frame/trace/panels/save.cljs b/src/day8/re_frame/trace/panels/save.cljs new file mode 100644 index 0000000..5c39ae7 --- /dev/null +++ b/src/day8/re_frame/trace/panels/save.cljs @@ -0,0 +1,30 @@ +(ns day8.re-frame.trace.panels.save + (:require [mranderson047.re-frame.v0v10v2.re-frame.core :as rf] + [re-frame.db] + [day8.re-frame.trace.utils.localstorage :as localstorage])) + +(rf/reg-event-db + :save/save-app-db + (fn [db _] + (localstorage/save! "saved-app-db" @re-frame.db/app-db) + db + )) + +(rf/reg-event-db + :save/restore-app-db + (fn [db _] + (if-let [app-db (localstorage/get "saved-app-db")] + (reset! re-frame.db/app-db app-db) + db))) + +(defn save-panel [] + [:div + [:h1 "Save State"] + [:br] + [:button.text-button + {:on-click #(rf/dispatch [:save/save-app-db])} + "Save"] + [:br] + [:button.text-button + {:on-click #(rf/dispatch [:save/restore-app-db])} + "Reload"]])