mirror of
https://github.com/penpot/penpot.git
synced 2026-09-18 09:56:15 +00:00
🐛 Fix multiple nav events when open workspace
This commit is contained in:
parent
0a6e884584
commit
b386403fa8
@ -62,18 +62,21 @@
|
|||||||
;; --- Navigate (Event)
|
;; --- Navigate (Event)
|
||||||
|
|
||||||
(defn navigated
|
(defn navigated
|
||||||
[match]
|
[match send-event-info?]
|
||||||
(ptk/reify ::navigated
|
(ptk/reify ::navigated
|
||||||
IDeref
|
IDeref
|
||||||
(-deref [_] match)
|
(-deref [_] match)
|
||||||
|
|
||||||
ev/Event
|
ptk/WatchEvent
|
||||||
(-data [_]
|
(watch [_ _ _]
|
||||||
(let [route (dm/get-in match [:data :name])
|
(when send-event-info?
|
||||||
params (get match :query-params)]
|
(let [route (dm/get-in match [:data :name])
|
||||||
(assoc params
|
params (get match :query-params)]
|
||||||
::ev/name "navigate"
|
(rx/of (ptk/event
|
||||||
:route (name route))))
|
::ev/event
|
||||||
|
(assoc params
|
||||||
|
::ev/name "navigate"
|
||||||
|
:route (name route)))))))
|
||||||
|
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
@ -189,7 +192,7 @@
|
|||||||
;; Check the urls to see if we need to send the navigated event.
|
;; Check the urls to see if we need to send the navigated event.
|
||||||
;; If two paths are the same we only send the event when there is a
|
;; If two paths are the same we only send the event when there is a
|
||||||
;; change in the parameters `file-id`, `page-id` or `team-id`
|
;; change in the parameters `file-id`, `page-id` or `team-id`
|
||||||
(defn- send-navigate?
|
(defn- send-event-info?
|
||||||
[old-url new-url]
|
[old-url new-url]
|
||||||
(let [params [:file-id :page-id :team-id]
|
(let [params [:file-id :page-id :team-id]
|
||||||
new-uri (u/uri new-url)
|
new-uri (u/uri new-url)
|
||||||
@ -215,7 +218,7 @@
|
|||||||
(let [stopper (rx/filter (ptk/type? ::initialize-history) stream)
|
(let [stopper (rx/filter (ptk/type? ::initialize-history) stream)
|
||||||
history (:history state)
|
history (:history state)
|
||||||
router (:router state)]
|
router (:router state)]
|
||||||
(ts/schedule #(on-change router (.getToken ^js history)))
|
(ts/schedule #(on-change router (.getToken ^js history) true))
|
||||||
(->> (rx/concat
|
(->> (rx/concat
|
||||||
(rx/of nil nil)
|
(rx/of nil nil)
|
||||||
(rx/create
|
(rx/create
|
||||||
@ -228,7 +231,6 @@
|
|||||||
(rx/take-until stopper)
|
(rx/take-until stopper)
|
||||||
(rx/subs!
|
(rx/subs!
|
||||||
(fn [[old-url new-url]]
|
(fn [[old-url new-url]]
|
||||||
(if (nil? old-url)
|
(when (some? new-url)
|
||||||
(when (some? new-url) (on-change router new-url))
|
(let [send? (or (nil? old-url) (send-event-info? old-url new-url))]
|
||||||
(when (send-navigate? old-url new-url)
|
(on-change router new-url send?))))))))))
|
||||||
(on-change router new-url))))))))))
|
|
||||||
|
|||||||
@ -88,7 +88,7 @@
|
|||||||
:plugin-url plugin))))
|
:plugin-url plugin))))
|
||||||
|
|
||||||
(defn on-navigate
|
(defn on-navigate
|
||||||
[router path]
|
[router path send-event-info?]
|
||||||
(let [location (.-location js/document)
|
(let [location (.-location js/document)
|
||||||
[base-path qs] (str/split path "?")
|
[base-path qs] (str/split path "?")
|
||||||
location-path (dm/str (.-origin location) (.-pathname location))
|
location-path (dm/str (.-origin location) (.-pathname location))
|
||||||
@ -102,7 +102,7 @@
|
|||||||
(st/emit! (rt/assign-exception {:type :not-found}))
|
(st/emit! (rt/assign-exception {:type :not-found}))
|
||||||
|
|
||||||
(some? match)
|
(some? match)
|
||||||
(st/emit! (rt/navigated match))
|
(st/emit! (rt/navigated match send-event-info?))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
;; We just recheck with an additional profile request; this
|
;; We just recheck with an additional profile request; this
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user