From 57245dd77ec56ece4960ef4d691c830873292d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Mon, 27 Sep 2021 09:41:01 +0200 Subject: [PATCH] :tada: Add open url action --- common/src/app/common/types/interactions.cljc | 8 ++++++-- frontend/src/app/main/ui/viewer/shapes.cljs | 6 ++++-- .../sidebar/options/menus/interactions.cljs | 16 +++++++++++++++- frontend/src/app/util/browser_history.js | 1 - frontend/src/app/util/dom.cljs | 11 +++++++++++ frontend/src/app/util/router.cljs | 11 ++++------- frontend/translations/en.po | 8 ++++++++ frontend/translations/es.po | 8 ++++++++ 8 files changed, 56 insertions(+), 13 deletions(-) diff --git a/common/src/app/common/types/interactions.cljc b/common/src/app/common/types/interactions.cljc index 2c5fa6c1e..868d617c5 100644 --- a/common/src/app/common/types/interactions.cljc +++ b/common/src/app/common/types/interactions.cljc @@ -204,6 +204,12 @@ shape objects :center)))) +(defn set-url + [interaction url] + (us/verify ::interaction interaction) + (us/verify ::url url) + (assert (= (:action-type interaction) :open-url)) + (assoc interaction :url url)) (defn set-overlay-pos-type [interaction overlay-pos-type shape objects] @@ -217,7 +223,6 @@ shape objects overlay-pos-type))) - (defn toggle-overlay-pos-type [interaction overlay-pos-type shape objects] (us/verify ::interaction interaction) @@ -233,7 +238,6 @@ shape objects new-pos-type)))) - (defn set-overlay-position [interaction overlay-position] (us/verify ::interaction interaction) diff --git a/frontend/src/app/main/ui/viewer/shapes.cljs b/frontend/src/app/main/ui/viewer/shapes.cljs index 0591aaa27..225c04a1d 100644 --- a/frontend/src/app/main/ui/viewer/shapes.cljs +++ b/frontend/src/app/main/ui/viewer/shapes.cljs @@ -67,8 +67,10 @@ (st/emit! (dv/close-overlay frame-id))) :prev-screen - (do - (st/emit! (rt/nav-back-local))) + (st/emit! (rt/nav-back-local)) + + :open-url + (st/emit! (dom/open-new-window (:url interaction))) nil)) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs index 02a6f788a..0da0941bd 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs @@ -39,7 +39,8 @@ :open-overlay (tr "workspace.options.interaction-open-overlay") :toggle-overlay (tr "workspace.options.interaction-toggle-overlay") :close-overlay (tr "workspace.options.interaction-close-overlay") - :prev-screen (tr "workspace.options.interaction-prev-screen")}) + :prev-screen (tr "workspace.options.interaction-prev-screen") + :open-url (tr "workspace.options.interaction-open-url")}) (defn- action-summary [interaction destination] @@ -53,6 +54,7 @@ :close-overlay (tr "workspace.options.interaction-close-overlay-dest" (get destination :name (tr "workspace.options.interaction-self"))) :prev-screen (tr "workspace.options.interaction-prev-screen") + :open-url (tr "workspace.options.interaction-open-url") "--")) (defn- overlay-pos-type-names @@ -106,6 +108,11 @@ value (when (not= value "") (uuid/uuid value))] (update-interaction index #(cti/set-destination % value shape objects)))) + change-url + (fn [event] + (let [value (-> event dom/get-target dom/get-value)] + (update-interaction index #(cti/set-url % value)))) + change-overlay-pos-type (fn [event] (let [value (-> event dom/get-target dom/get-value d/read-string)] @@ -186,6 +193,13 @@ (not= (:id frame) (:frame-id shape))) ; nor a shape to its container frame [:option {:value (str (:id frame))} (:name frame)]))]]) + ; URL + (when (= action-type :open-url) + [:div.interactions-element + [:span.element-set-subtitle.wide (tr "workspace.options.interaction-url")] + [:input.input-text {:default-value (str (:url interaction)) + :on-blur change-url}]]) + (when (or (= action-type :open-overlay) (= action-type :toggle-overlay)) [:* diff --git a/frontend/src/app/util/browser_history.js b/frontend/src/app/util/browser_history.js index 380cb32ab..8663bd684 100644 --- a/frontend/src/app/util/browser_history.js +++ b/frontend/src/app/util/browser_history.js @@ -11,7 +11,6 @@ goog.provide("app.util.browser_history"); goog.require("goog.history.Html5History"); - goog.scope(function() { const self = app.util.browser_history; const Html5History = goog.history.Html5History; diff --git a/frontend/src/app/util/dom.cljs b/frontend/src/app/util/dom.cljs index 5c3074e14..1f952fb35 100644 --- a/frontend/src/app/util/dom.cljs +++ b/frontend/src/app/util/dom.cljs @@ -394,3 +394,14 @@ (defn left-mouse? [bevent] (let [event (.-nativeEvent ^js bevent)] (= 1 (.-which event)))) + +(defn open-new-window + ([uri] + (open-new-window uri "_blank")) + ([uri name] + (js/window.open (str uri) name))) + +(defn browser-back + [] + (.back (.-history js/window))) + diff --git a/frontend/src/app/util/router.cljs b/frontend/src/app/util/router.cljs index 50844ae35..5ca77cbf2 100644 --- a/frontend/src/app/util/router.cljs +++ b/frontend/src/app/util/router.cljs @@ -10,6 +10,7 @@ [app.common.uri :as u] [app.config :as cfg] [app.util.browser-history :as bhistory] + [app.util.dom :as dom] [app.util.timers :as ts] [beicon.core :as rx] [goog.events :as e] @@ -110,14 +111,13 @@ uri (-> (u/uri cfg/public-uri) (assoc :fragment path)) name (str (name id) "-" (:file-id params))] - (js/window.open (str uri) name)))) + (dom/open-new-window (str uri) name)))) (defn nav-new-window ([id] (nav-new-window id nil nil)) ([id params] (nav-new-window id params nil)) ([id params qparams] (NavigateNewWindow. id params qparams))) - (defn nav-new-window* [{:keys [rname path-params query-params name]}] (ptk/reify ::nav-new-window @@ -127,17 +127,14 @@ path (resolve router rname path-params query-params) uri (-> (u/uri cfg/public-uri) (assoc :fragment path))] - - - - (js/window.open (str uri) name))))) + (dom/open-new-window (str uri) name))))) (defn nav-back [] (ptk/reify ::nav-back ptk/EffectEvent (effect [_ _ _] - (ts/asap #(.back (.-history js/window)))))) + (ts/asap dom/browser-back)))) (defn nav-back-local "Navigate back only if the previous page is in penpot app." diff --git a/frontend/translations/en.po b/frontend/translations/en.po index 6dce8ee4d..e5211a76d 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -2465,6 +2465,10 @@ msgstr "On Click" msgid "workspace.options.interaction-open-overlay" msgstr "Open overlay" +#: src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs +msgid "workspace.options.interaction-open-url" +msgstr "Open url" + #: src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs msgid "workspace.options.interaction-prev-screen" msgstr "Previous screen" @@ -2481,6 +2485,10 @@ msgstr "Open overlay: %s" msgid "workspace.options.interaction-toggle-overlay-dest" msgstr "Toggle overlay: %s" +#: src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs +msgid "workspace.options.interaction-url" +msgstr "URL" + #: src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs msgid "workspace.options.interaction-pos-manual" msgstr "Manual" diff --git a/frontend/translations/es.po b/frontend/translations/es.po index bb6765b50..6b716a299 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -2348,6 +2348,10 @@ msgstr "En click" msgid "workspace.options.interaction-open-overlay" msgstr "SuperposiciĆ³n" +#: src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs +msgid "workspace.options.interaction-open-url" +msgstr "Abrir url" + #: src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs msgid "workspace.options.interaction-prev-screen" msgstr "Pantalla anterior" @@ -2364,6 +2368,10 @@ msgstr "SuperposiciĆ³n: %s" msgid "workspace.options.interaction-toggle-overlay-dest" msgstr "Alternar superpos.: %s" +#: src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs +msgid "workspace.options.interaction-url" +msgstr "URL" + #: src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs msgid "workspace.options.interaction-pos-manual" msgstr "Manual"