Skip to content

Commit

Permalink
Validate and give a proper error on import
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
jbondeson committed Nov 6, 2017
1 parent 7920b21 commit 6e530c8
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/kii/ui/conf/actions/components.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@

(defn load-json
[raw-str]
(let [json (goog-json/parse raw-str)
cnv (js->clj json :keywordize-keys true)]
(>=> [:load-config cnv])
))
(try
(let [json (goog-json/parse raw-str)
cnv (js->clj json :keywordize-keys true)]
(if (and (:header cnv) (:matrix cnv))
(do (>=> [:load-config cnv]) true)
false)
)
(catch :default e
(logf :warn e "Could not import JSON")
false)))

(defn code-popup [visible? kll]
(let [mangled (-> kll config/mangle clj->js)]
Expand All @@ -61,10 +67,12 @@
[popup
"import layout json" visible? false ""
[{:text "import"
:fn #(do
(load-json %)
(reset! visible? false)
(=>> [:alert/add {:type :success :msg "Successfully imported layout!"}]))
:fn (fn [val]
(if (load-json val)
(=>> [:alert/add {:type :success :msg "Successfully imported layout!"}])
(=>> [:alert/add {:type :error :msg "Could not import, invalid format."}])
)
(reset! visible? false))
}]])

;;==== Action Bar ====;;
Expand Down Expand Up @@ -153,7 +161,7 @@
[button-comp "file_upload" "Import keymap" false #(reset! import-visible? true)]
(if (:firmware-dl current-actions)
[:div {:style {:height "36px" :width "36px" :margin "1px 10px 1px 0"}}
[mui/circular-progress {:size 28 :thickness 5}]]
[mui/circular-progress {:size 28 :thickness 3}]]
[button-comp "file_download" "Download firmware" false #(=>> [:start-firmware-compile])])
]))
)
Expand Down

0 comments on commit 6e530c8

Please sign in to comment.