Temporary that makes it possible to install only one extension at a time (required for the hackathon)

Signed-off-by: Aleksandr Pantiukhov <alwxndr@gmail.com>
This commit is contained in:
Aleksandr Pantiukhov 2018-10-19 18:58:11 +02:00
parent 83a92aa4b0
commit 5f06ebc27d
No known key found for this signature in database
GPG Key ID: 153E4F21734042F5
5 changed files with 22 additions and 22 deletions

View File

@ -26,8 +26,8 @@
(defn- deserialize-extensions [extensions] (defn- deserialize-extensions [extensions]
(reduce-kv (reduce-kv
(fn [acc _ {:keys [name] :as extension}] (fn [acc _ {:keys [id] :as extension}]
(assoc acc name extension)) (assoc acc id extension))
{} {}
extensions)) extensions))

View File

@ -426,8 +426,8 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:extensions.ui/add-extension-pressed :extensions.ui/add-extension-pressed
(fn [cofx [_ name]] (fn [cofx [_ id]]
(extensions/edit cofx name))) (extensions/edit cofx id)))
(handlers/register-handler-fx (handlers/register-handler-fx
:extensions.ui/input-changed :extensions.ui/input-changed
@ -436,8 +436,8 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:extensions.ui/activation-checkbox-pressed :extensions.ui/activation-checkbox-pressed
(fn [cofx [_ name state]] (fn [cofx [_ id state]]
(extensions/toggle-activation cofx name state))) (extensions/toggle-activation cofx id state)))
(handlers/register-handler-fx (handlers/register-handler-fx
:extensions.ui/show-button-pressed :extensions.ui/show-button-pressed

View File

@ -250,19 +250,21 @@
[{:keys [db]} input-key value] [{:keys [db]} input-key value]
{:db (update db :extensions/manage assoc input-key {:value value})}) {:db (update db :extensions/manage assoc input-key {:value value})})
(fx/defn fetch [cofx name] (fx/defn fetch [cofx id]
(get-in cofx [:db :account/account :extensions name])) (get-in cofx [:db :account/account :extensions id]))
(fx/defn edit (fx/defn edit
[cofx name] [cofx id]
(let [{:keys [url]} (fetch cofx name)] (let [{:keys [url]} (fetch cofx id)]
(fx/merge (set-input cofx :url (str url)) (fx/merge (set-input cofx :url (str url))
(navigation/navigate-to-cofx :edit-extension nil)))) (navigation/navigate-to-cofx :edit-extension nil))))
(fx/defn add (fx/defn add
[cofx extension-data active?] [cofx extension-data active?]
(when-let [extension-key (get-in extension-data ['meta :name])] (let [extension-key "extension"
extension-data (assoc-in extension-data ['meta :name] extension-key)]
(fx/merge cofx (fx/merge cofx
#(registry/deactivate extension-key %)
#(registry/add extension-data %) #(registry/add extension-data %)
(when active? (when active?
#(registry/activate extension-key %))))) #(registry/activate extension-key %)))))
@ -273,13 +275,11 @@
extension-data] extension-data]
(let [extension-key (get-in extension-data ['meta :name]) (let [extension-key (get-in extension-data ['meta :name])
{:keys [url id]} manage {:keys [url id]} manage
extension {:id (-> (:value id) extension {:id (or (:value id) "extension")
(or (random-id-generator))
(string/replace "-" ""))
:name (str extension-key) :name (str extension-key)
:url (:value url) :url (:value url)
:active? true} :active? true}
new-extensions (assoc (:extensions account) (:name extension) extension)] new-extensions (assoc (:extensions account) (:id extension) extension)]
(fx/merge cofx (fx/merge cofx
{:ui/show-confirmation {:title (i18n/label :t/success) {:ui/show-confirmation {:title (i18n/label :t/success)
:content (i18n/label :t/extension-installed) :content (i18n/label :t/extension-installed)
@ -289,15 +289,15 @@
(add extension-data true)))) (add extension-data true))))
(fx/defn toggle-activation (fx/defn toggle-activation
[cofx name state] [cofx id state]
(let [toggle-fn (get {true registry/activate (let [toggle-fn (get {true registry/activate
false registry/deactivate} false registry/deactivate}
state) state)
extensions (get-in cofx [:db :account/account :extensions]) extensions (get-in cofx [:db :account/account :extensions])
new-extensions (assoc-in extensions [name :active?] state)] new-extensions (assoc-in extensions [id :active?] state)]
(fx/merge cofx (fx/merge cofx
(accounts.update/account-update {:extensions new-extensions} {:success-event nil}) (accounts.update/account-update {:extensions new-extensions} {:success-event nil})
#(toggle-fn name %)))) #(toggle-fn id %))))
(fx/defn load (fx/defn load
[cofx url] [cofx url]

View File

@ -27,6 +27,6 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:extensions/deactivate-all :extensions/deactivate-all
(fn [cofx [_ extensions]] (fn [cofx [_ extensions]]
(apply fx/merge cofx (map (fn [{:keys [name]}] (apply fx/merge cofx (map (fn [{:keys [id]}]
(partial registry/deactivate name)) (partial registry/deactivate id))
extensions)))) extensions))))

View File

@ -14,10 +14,10 @@
[react/view (styles/wnode-icon true) [react/view (styles/wnode-icon true)
[vector-icons/icon :icons/wnode {:color :white}]]) [vector-icons/icon :icons/wnode {:color :white}]])
(defn- render-extension [{:keys [name url active?]}] (defn- render-extension [{:keys [id name url active?]}]
[list/list-item-with-checkbox [list/list-item-with-checkbox
{:checked? active? {:checked? active?
:on-value-change #(re-frame/dispatch [:extensions.ui/activation-checkbox-pressed name %])} :on-value-change #(re-frame/dispatch [:extensions.ui/activation-checkbox-pressed id %])}
[list/item [list/item
wnode-icon wnode-icon
[list/item-content [list/item-content