Skip to content

Commit

Permalink
Fix overlay+back handling on prod
Browse files Browse the repository at this point in the history
  • Loading branch information
dhleong committed Nov 17, 2018
1 parent 0ea71c7 commit 2ec4f9f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/cljs/wish/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@

; always dismiss
(assoc db :showing-overlay nil))
:make-overlay-closable! (and overlay-spec
(nil? (:showing-overlay db)))}))
:make-overlay-closeable! (and overlay-spec
(nil? (:showing-overlay db)))}))

(reg-event-fx
:title!
Expand Down
28 changes: 4 additions & 24 deletions src/cljs/wish/fx.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
[wish.push :as push]
[wish.providers :as providers :refer [load-sheet! save-sheet!]]
[wish.sheets :as sheets]
[wish.util :refer [>evt]]))
[wish.util :refer [>evt]]
[wish.util.nav :as nav]))

; ======= html stuff =======================================

Expand All @@ -38,30 +39,9 @@

; ======= support back button to close overlays ===========

(def ^:private overlay-suffix "?overlay")

(defn- dismiss-from-event []
(set! js/window.onpopstate nil)
(>evt [:toggle-overlay nil]))

(reg-fx
:make-overlay-closable!
(fn [closable?]
(cond
closable?
(do
; such hacks: navigate to the same url but with a trivial suffix
; appended (so it doesn't register as a different page) then
; hook onpopstate
(set! js/window.location (str js/window.location overlay-suffix))
(set! js/window.onpopstate dismiss-from-event))

; closing manually; if we have the ?overlay url, go back to remove it
(str/ends-with? (str js/window.location) overlay-suffix)
(do
; stop listening to onpopstate
(set! js/window.onpopstate nil)
(js/history.go -1)))))
:make-overlay-closeable!
nav/make-overlay-closeable!)


; ======= provider-related =================================
Expand Down
31 changes: 31 additions & 0 deletions src/cljs/wish/util/nav.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,34 @@
(name %)
(str %))
extra-sections)))))


; ======= support back button to close overlays ===========

(def ^:private overlay-suffix
(if pushy-supported?
"#overlay"
"?overlay"))

(defn- dismiss-from-event []
(set! js/window.onpopstate nil)
(>evt [:toggle-overlay nil]))

(defn make-overlay-closeable!
[closable?]
(cond
closable?
(do
; such hacks: navigate to the same url but with a trivial suffix
; appended (so it doesn't register as a different page) then
; hook onpopstate
(set! js/window.location (str js/window.location overlay-suffix))
(set! js/window.onpopstate dismiss-from-event))

; closing manually; if we have the ?overlay url, go back to remove it
(str/ends-with? (str js/window.location) overlay-suffix)
(do
; stop listening to onpopstate
(set! js/window.onpopstate nil)
(js/history.go -1))))

0 comments on commit 2ec4f9f

Please sign in to comment.