Skip to content

Commit

Permalink
Merge pull request #73 from open-simulation-platform/feature/71-user-…
Browse files Browse the repository at this point in the history
…feedback-when-simulator-is-paused

feature(variable-override-editor): immediate feedback when editing
  • Loading branch information
flakstad authored Mar 19, 2019
2 parents 9e3abfc + f8da3a9 commit 13295d3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/cse_client/components.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
[reagent.core :as r]))

(defn variable-override-editor [module {:keys [name causality type]} value event]
(let [editing? (r/atom false)
(let [simulation-status @(rf/subscribe [:status])
editing? (r/atom false)
edited? (r/atom false)
internal-value (r/atom value)
save (fn []
(rf/dispatch (if event
(conj event @internal-value)
[::controller/set-value module name causality type @internal-value]))
(reset! editing? false))
(conj event @internal-value)
[::controller/set-value module name causality type @internal-value]))
(reset! editing? false)
(reset! edited? true))
save-if-changed (fn [value]
(if (not= value @internal-value)
(save)
Expand All @@ -21,7 +24,7 @@
[:input {:type :text
:auto-focus true
:id (str "input-" name)
:value (if @editing? @internal-value value)
:value @internal-value
:on-change #(reset! internal-value (.. % -target -value))
:on-key-press #(when (= (.-key %) "Enter") (save-if-changed value))
:on-blur #(save-if-changed value)}]
Expand All @@ -34,7 +37,9 @@

[:div
[:span.plotname-edit
{:on-click #(rf/dispatch [::controller/reset-value module name causality type])
{:on-click (fn []
(reset! edited? false)
(rf/dispatch [::controller/reset-value module name causality type]))
:data-tooltip "Remove override"}
[:i.eraser.icon]]
[:span.plotname-edit
Expand All @@ -43,4 +48,6 @@
(reset! internal-value value))
:data-tooltip "Override value"}
[:i.edit.link.icon]]
value]))))
(if (and @edited? (= "pause" simulation-status))
@internal-value
value)]))))

0 comments on commit 13295d3

Please sign in to comment.