0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 17:21:17 -05:00

🐛 Fix minor issues on browser history handling.

This commit is contained in:
Andrey Antukh 2020-05-01 08:58:17 +02:00
parent 7fe7c3da6c
commit 8446ad13cb
5 changed files with 44 additions and 19 deletions

View file

@ -141,7 +141,9 @@
ptk/WatchEvent
(watch [_ state stream]
(->> (rp/query :projects-by-team {:team-id team-id})
(rx/map projects-fetched)))))
(rx/map projects-fetched)
(rx/catch (fn [error]
(rx/of (rt/nav' :not-authorized))))))))
(defn projects-fetched
[projects]
@ -208,7 +210,9 @@
(watch [_ state stream]
(let [params {:team-id team-id}]
(->> (rp/query :recent-files params)
(rx/map recent-files-fetched))))))
(rx/map recent-files-fetched)
(rx/catch (fn [e]
(rx/of (rt/nav' :not-authorized)))))))))
(defn recent-files-fetched
[recent-files]

View file

@ -72,7 +72,8 @@
(ptk/reify ::finalize
ptk/WatchEvent
(watch [_ state stream]
(ws/-close (get-in state [:ws file-id]))
(when-let [ws (get-in state [:ws file-id])]
(ws/-close ws))
(rx/of ::finalize))))
;; --- Handle: Presence

View file

@ -140,9 +140,17 @@
(rx/first)
(rx/map (fn [[file users project pages]]
(bundle-fetched file users project pages)))
(rx/catch (fn [{:keys [type] :as error}]
(when (= :not-found type)
(rx/of (rt/nav :not-found)))))))))
(rx/catch (fn [{:keys [type code] :as error}]
(cond
(= :not-found type)
(rx/of (rt/nav' :not-found))
(and (= :authentication type)
(= :unauthorized code))
(rx/of (rt/nav' :not-authorized))
:else
(throw error))))))))
(defn- bundle-fetched
[file users project pages]

View file

@ -46,4 +46,8 @@ goog.scope(function() {
self.set_token_BANG_ = function(instance, token) {
instance.setToken(token);
}
self.replace_token_BANG_ = function(instance, token) {
instance.replaceToken(token);
}
});

View file

@ -87,20 +87,26 @@
;; --- Navigate (Event)
(deftype Navigate [id params qparams]
(deftype Navigate [id params qparams replace]
ptk/EffectEvent
(effect [_ state stream]
(prn "Navigate" id params qparams replace)
(let [router (:router state)
history (:history state)
path (resolve router id params qparams)]
(bhistory/set-token! history path))))
(if ^boolean replace
(bhistory/replace-token! history path)
(bhistory/set-token! history path)))))
(defn nav
([id] (nav id nil nil))
([id params] (nav id params nil))
([id params qparams]
{:pre [(keyword? id)]}
(Navigate. id params qparams)))
([id params qparams] (Navigate. id params qparams false)))
(defn nav'
([id] (nav id nil nil))
([id params] (nav id params nil))
([id params qparams] (Navigate. id params qparams true)))
(def navigate nav)
@ -112,6 +118,7 @@
ptk/UpdateEvent
(update [_ state]
(let [history (bhistory/create)]
(bhistory/enable! history)
(assoc state :history history)))
ptk/WatchEvent
@ -119,14 +126,15 @@
(let [stoper (rx/filter (ptk/type? ::initialize-history) stream)
history (:history state)
router (:router state)]
(->> (rx/create (fn [sink]
(let [key (e/listen history "navigate" #(sink (.-token %)))]
(bhistory/enable! history)
(fn []
(bhistory/disable! history)
(e/unlistenByKey key)))))
(rx/map #(on-change router %))
(rx/take-until stoper))))))
(rx/merge
(rx/of (on-change router (.getToken history)))
(->> (rx/create (fn [sink]
(let [key (e/listen history "navigate" #(sink (.-token %)))]
(fn []
(bhistory/disable! history)
(e/unlistenByKey key)))))
(rx/map #(on-change router %))
(rx/take-until stoper)))))))