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]
(reduce-kv
(fn [acc _ {:keys [name] :as extension}]
(assoc acc name extension))
(fn [acc _ {:keys [id] :as extension}]
(assoc acc id extension))
{}
extensions))

View File

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

View File

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

View File

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

View File

@ -14,10 +14,10 @@
[react/view (styles/wnode-icon true)
[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
{: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
wnode-icon
[list/item-content