From 0a6e8845840dc8a14ab05ad13c7a35016b0bf9c8 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 5 Mar 2025 11:24:04 +0100 Subject: [PATCH 1/2] :bug: Remove unnecesary console.log --- frontend/src/app/main/router.cljs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frontend/src/app/main/router.cljs b/frontend/src/app/main/router.cljs index c85296ef2a..168d28001a 100644 --- a/frontend/src/app/main/router.cljs +++ b/frontend/src/app/main/router.cljs @@ -220,10 +220,7 @@ (rx/of nil nil) (rx/create (fn [subs] - (let [key (e/listen history "navigate" - (fn [o] - (.log js/console ">" o) - (rx/push! subs (.-token ^js o))))] + (let [key (e/listen history "navigate" (fn [o] (rx/push! subs (.-token ^js o))))] (fn [] (bhistory/disable! history) (e/unlistenByKey key)))))) From b386403fa8da6be36010c3e6379ac1cc4951fed9 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 5 Mar 2025 11:55:26 +0100 Subject: [PATCH 2/2] :bug: Fix multiple nav events when open workspace --- frontend/src/app/main/router.cljs | 30 +++++++++++++++------------- frontend/src/app/main/ui/routes.cljs | 4 ++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/main/router.cljs b/frontend/src/app/main/router.cljs index 168d28001a..746d69ede6 100644 --- a/frontend/src/app/main/router.cljs +++ b/frontend/src/app/main/router.cljs @@ -62,18 +62,21 @@ ;; --- Navigate (Event) (defn navigated - [match] + [match send-event-info?] (ptk/reify ::navigated IDeref (-deref [_] match) - ev/Event - (-data [_] - (let [route (dm/get-in match [:data :name]) - params (get match :query-params)] - (assoc params - ::ev/name "navigate" - :route (name route)))) + ptk/WatchEvent + (watch [_ _ _] + (when send-event-info? + (let [route (dm/get-in match [:data :name]) + params (get match :query-params)] + (rx/of (ptk/event + ::ev/event + (assoc params + ::ev/name "navigate" + :route (name route))))))) ptk/UpdateEvent (update [_ state] @@ -189,7 +192,7 @@ ;; 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? +(defn- send-event-info? [old-url new-url] (let [params [:file-id :page-id :team-id] new-uri (u/uri new-url) @@ -215,7 +218,7 @@ (let [stopper (rx/filter (ptk/type? ::initialize-history) stream) history (:history state) router (:router state)] - (ts/schedule #(on-change router (.getToken ^js history))) + (ts/schedule #(on-change router (.getToken ^js history) true)) (->> (rx/concat (rx/of nil nil) (rx/create @@ -228,7 +231,6 @@ (rx/take-until stopper) (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)))))))))) + (when (some? new-url) + (let [send? (or (nil? old-url) (send-event-info? old-url new-url))] + (on-change router new-url send?)))))))))) diff --git a/frontend/src/app/main/ui/routes.cljs b/frontend/src/app/main/ui/routes.cljs index 6e04498d8d..f2a5df0005 100644 --- a/frontend/src/app/main/ui/routes.cljs +++ b/frontend/src/app/main/ui/routes.cljs @@ -88,7 +88,7 @@ :plugin-url plugin)))) (defn on-navigate - [router path] + [router path send-event-info?] (let [location (.-location js/document) [base-path qs] (str/split path "?") location-path (dm/str (.-origin location) (.-pathname location)) @@ -102,7 +102,7 @@ (st/emit! (rt/assign-exception {:type :not-found})) (some? match) - (st/emit! (rt/navigated match)) + (st/emit! (rt/navigated match send-event-info?)) :else ;; We just recheck with an additional profile request; this