From 4697a1904a921344db144703838e13fdc7c1b392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 24 Sep 2021 16:52:22 +0200 Subject: [PATCH] :tada: Add previous screen action --- frontend/src/app/main/ui/viewer/shapes.cljs | 5 +++++ .../sidebar/options/menus/interactions.cljs | 1 + .../main/ui/workspace/viewport/interactions.cljs | 8 ++++++++ frontend/src/app/util/router.cljs | 16 ++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/frontend/src/app/main/ui/viewer/shapes.cljs b/frontend/src/app/main/ui/viewer/shapes.cljs index d4884ac8f..0591aaa27 100644 --- a/frontend/src/app/main/ui/viewer/shapes.cljs +++ b/frontend/src/app/main/ui/viewer/shapes.cljs @@ -26,6 +26,7 @@ [app.main.ui.shapes.text :as text] [app.util.dom :as dom] [app.util.object :as obj] + [app.util.router :as rt] [app.util.timers :as tm] [rumext.alpha :as mf])) @@ -65,6 +66,10 @@ (:frame-id shape)))] (st/emit! (dv/close-overlay frame-id))) + :prev-screen + (do + (st/emit! (rt/nav-back-local))) + nil)) ;; Perform the opposite action of an interaction, if possible 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 d0054dbc7..02a6f788a 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 @@ -52,6 +52,7 @@ (get destination :name (tr "workspace.options.interaction-none"))) :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") "--")) (defn- overlay-pos-type-names diff --git a/frontend/src/app/main/ui/workspace/viewport/interactions.cljs b/frontend/src/app/main/ui/workspace/viewport/interactions.cljs index 8641c1726..f39a52387 100644 --- a/frontend/src/app/main/ui/workspace/viewport/interactions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/interactions.cljs @@ -94,6 +94,14 @@ :close-overlay "M -5 -5 L 5 5 M -5 5 L 5 -5" + :prev-screen (case arrow-dir + :left "M -6.5 0 l 12 0 l -6 -6 m 6 6 l -6 6" + :right "M 6.5 0 l -12 0 l 6 -6 m -6 6 l 6 6" + nil) + + :open-url (str "M1 -5 L 3 -7 L 7 -3 L 1 3 L -1 1" + "M-1 5 L -3 7 L -7 3 L -1 -3 L 1 -1") + nil) inv-zoom (/ 1 zoom)] [:* diff --git a/frontend/src/app/util/router.cljs b/frontend/src/app/util/router.cljs index 2329af2b6..50844ae35 100644 --- a/frontend/src/app/util/router.cljs +++ b/frontend/src/app/util/router.cljs @@ -132,6 +132,22 @@ (js/window.open (str uri) name))))) +(defn nav-back + [] + (ptk/reify ::nav-back + ptk/EffectEvent + (effect [_ _ _] + (ts/asap #(.back (.-history js/window)))))) + +(defn nav-back-local + "Navigate back only if the previous page is in penpot app." + [] + (let [location (.-location js/document) + referrer (u/uri (.-referrer js/document))] + (when (or (nil? (:host referrer)) + (= (.-hostname location) (:host referrer))) + (nav-back)))) + ;; --- History API (defn initialize-history