From d07f95658a4cdd91baa7818b2c79296e27aa855d Mon Sep 17 00:00:00 2001 From: jeluard Date: Wed, 21 Nov 2018 12:19:34 +0100 Subject: [PATCH] Display QR code on first page load --- src/pluto/js.cljs | 24 ++++++++++++------------ src/pluto/reader/errors.cljc | 3 ++- src/pluto/reader/views.cljc | 24 ++++++++++++++++++------ website/pages/try.html | 1 + 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/pluto/js.cljs b/src/pluto/js.cljs index c052653..25e4063 100644 --- a/src/pluto/js.cljs +++ b/src/pluto/js.cljs @@ -90,20 +90,20 @@ :arguments {:to :string :method :string :params? :vector - :on-result? :event}}} - :hooks {:wallet.settings {:properties {:title :string + :on-result :event}}} + :hooks {:wallet.settings {:properties {:label :string :view :view :on-click? :event}} - :commands {:properties {:description? :string - :scope #{:personal-chats :public-chats} - :short-preview :view - :preview :view - :parameters? [{:id :keyword - :type {:one-of #{:text :phone :password :number}} - :placeholder :string - :suggestions? :view}] - :on-send? :event - :on-receive? :event}}}}}) + :chat.command {:properties {:description? :string + :scope #{:personal-chats :public-chats} + :short-preview :view + :preview :view + :parameters? [{:id :keyword + :type {:one-of #{:text :phone :password :number}} + :placeholder :string + :suggestions? :view}] + :on-send? :event + :on-receive? :event}}}}}) (defn ^:export parse [m] (reader/parse ctx (:data m))) diff --git a/src/pluto/reader/errors.cljc b/src/pluto/reader/errors.cljc index ee5b685..62cc1a1 100644 --- a/src/pluto/reader/errors.cljc +++ b/src/pluto/reader/errors.cljc @@ -35,7 +35,8 @@ ::invalid-if-block ::invalid-when-block ::unsupported-test-type - ::invalid-local-event}) + ::invalid-local-event + ::unresolved-properties}) (spec/def ::value any?) diff --git a/src/pluto/reader/views.cljc b/src/pluto/reader/views.cljc index 2ab2f07..00af3d8 100644 --- a/src/pluto/reader/views.cljc +++ b/src/pluto/reader/views.cljc @@ -94,7 +94,6 @@ (spec/explain-data ::element o) (spec/explain-data ::form o))] (cond - ;; TODO Validate views, not hiccup (not (nil? explain)) {:errors [(errors/error ::errors/invalid-view o {:explain-data explain})]} @@ -116,13 +115,26 @@ (seq errors) (errors/accumulate-errors errors))) :else {:errors [(errors/error ::errors/unknown-component o)]}))) +(defn unresolved-properties [acc o] + (cond + (symbol? o) (conj acc o) + (vector? o) + (let [[component properties & children] o] + (reduce #(apply conj %1 (unresolved-properties acc %2)) acc children)) + :else acc)) + (defn parse [ctx ext o] (if (list? o) ;; TODO introduce a block? fn - (let [{:keys [data errors] :as m} (blocks/parse ctx ext o)] - (errors/merge-errors - (when data - (parse ctx ext data)) - errors)) + (let [{:keys [data errors] :as m} (blocks/parse ctx ext o) + ] + (if data + (let [d (parse ctx ext data) + props (reduce unresolved-properties #{} d)] + (errors/merge-errors + d + (concat errors (when (seq props) + {:errors [(errors/error ::errors/unresolved-properties props)]})))) + {:errors errors})) (parse-hiccup-element ctx ext o))) (defn- hiccup-with-properties [h properties] diff --git a/website/pages/try.html b/website/pages/try.html index cf3bcd0..ed4b010 100644 --- a/website/pages/try.html +++ b/website/pages/try.html @@ -53,6 +53,7 @@ if (content != null) { codeMirror.setValue(content); history.replaceState({hash: hash}, null, document.location.href.split('?')[0] + "?hash=" + hash); + displayQR(hash); } else { codeMirror.setValue("Failed to load the extension"); history.replaceState({hash: null}, null, document.location.href.split('?')[0]);