just some refactoring for action-dialogue.

This commit is contained in:
Bryce Covert
2018-05-22 21:11:10 -07:00
parent 2c42146a3d
commit 6bb4c6e928
7 changed files with 110 additions and 65 deletions

View File

@@ -1,5 +1,8 @@
(ns auto-ap.views.components.modal
(:require [re-frame.core :as re-frame]))
(:require [re-frame.core :as re-frame]
[auto-ap.events :as events]
[auto-ap.subs :as subs]
[auto-ap.views.utils :refer [with-keys]]))
(defn modal [{:keys [title foot hide-event]} & body]
[:div.modal.is-active
@@ -11,8 +14,25 @@
title]
[:button.delete {:on-click (fn [] (re-frame/dispatch hide-event))}]]
[:section.modal-card-body
body]
(with-keys body)]
(when foot
[:footer.modal-card-foot
foot])]])
(defn action-modal [{:keys [title action-text id save-event]} & rest]
(let [{:keys [visible? saving?]} @(re-frame/subscribe [::subs/modal-state id])]
(when visible?
[modal {:title title
:foot [:a.button.is-primary {:on-click (fn []
(re-frame/dispatch [::events/modal-status id {:saving? true}])
(re-frame/dispatch save-event))
:class (when saving?
"is-loading")}
[:span action-text]]
:id id
:hide-event [::events/modal-status id {:visible? false}]}
(with-keys rest)
(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])))