0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-06 04:41:57 -05:00

Merge pull request #6008 from penpot/superalex-fix-multiple-nav-events-when-open-workspace

🐛 Fix multiple nav events when open workspace
This commit is contained in:
Alejandro 2025-03-05 10:57:51 +01:00 committed by GitHub
commit 06f6a49bce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 7 deletions

View file

@ -1,5 +1,19 @@
# CHANGELOG # CHANGELOG
## 2.5.2
### :rocket: Epics and highlights
### :boom: Breaking changes & Deprecations
### :heart: Community contributions (Thank you!)
### :sparkles: New features
### :bug: Bugs fixed
- Navigate tracking event firing multiple times [Taiga #10415](https://tree.taiga.io/project/penpot/issue/10415)
## 2.5.1 ## 2.5.1
### :rocket: Epics and highlights ### :rocket: Epics and highlights

View file

@ -70,7 +70,7 @@
ev/Event ev/Event
(-data [_] (-data [_]
(let [route (dm/get-in match [:data :name]) (let [route (dm/get-in match [:data :name])
params (get match :path-params)] params (get match :query-params)]
(assoc params (assoc params
::ev/name "navigate" ::ev/name "navigate"
:route (name route)))) :route (name route))))
@ -186,6 +186,21 @@
;; --- History API ;; --- History API
;; 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
;; change in the parameters `file-id`, `page-id` or `team-id`
(defn- send-navigate?
[old-url new-url]
(let [params [:file-id :page-id :team-id]
new-uri (u/uri new-url)
new-path (:path new-uri)
new-params (-> new-uri :query u/query-string->map (select-keys params))
old-uri (u/uri old-url)
old-path (:path old-uri)
old-params (-> old-uri :query u/query-string->map (select-keys params))]
(or (not= old-path new-path)
(not= new-params old-params))))
(defn initialize-history (defn initialize-history
[on-change] [on-change]
(ptk/reify ::initialize-history (ptk/reify ::initialize-history
@ -201,10 +216,22 @@
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)))
(->> (rx/create (fn [subs] (->> (rx/concat
(let [key (e/listen history "navigate" (fn [o] (rx/push! subs (.-token ^js o))))] (rx/of nil nil)
(fn [] (rx/create
(bhistory/disable! history) (fn [subs]
(e/unlistenByKey key))))) (let [key (e/listen history "navigate"
(fn [o]
(.log js/console ">" o)
(rx/push! subs (.-token ^js o))))]
(fn []
(bhistory/disable! history)
(e/unlistenByKey key))))))
(rx/buffer 2 1)
(rx/take-until stopper) (rx/take-until stopper)
(rx/subs! #(on-change router %))))))) (rx/subs!
(fn [[old-url new-url]]
(if (nil? old-url)
(when (some? new-url) (on-change router new-url))
(when (send-navigate? old-url new-url)
(on-change router new-url))))))))))