mirror of
https://github.com/penpot/penpot.git
synced 2025-07-05 15:37:16 +02:00
🐛 Fix minor issues on browser history handling.
This commit is contained in:
parent
7fe7c3da6c
commit
8446ad13cb
5 changed files with 44 additions and 19 deletions
|
@ -141,7 +141,9 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(->> (rp/query :projects-by-team {:team-id team-id})
|
(->> (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
|
(defn projects-fetched
|
||||||
[projects]
|
[projects]
|
||||||
|
@ -208,7 +210,9 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [params {:team-id team-id}]
|
(let [params {:team-id team-id}]
|
||||||
(->> (rp/query :recent-files params)
|
(->> (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
|
(defn recent-files-fetched
|
||||||
[recent-files]
|
[recent-files]
|
||||||
|
|
|
@ -72,7 +72,8 @@
|
||||||
(ptk/reify ::finalize
|
(ptk/reify ::finalize
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(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))))
|
(rx/of ::finalize))))
|
||||||
|
|
||||||
;; --- Handle: Presence
|
;; --- Handle: Presence
|
||||||
|
|
|
@ -140,9 +140,17 @@
|
||||||
(rx/first)
|
(rx/first)
|
||||||
(rx/map (fn [[file users project pages]]
|
(rx/map (fn [[file users project pages]]
|
||||||
(bundle-fetched file users project pages)))
|
(bundle-fetched file users project pages)))
|
||||||
(rx/catch (fn [{:keys [type] :as error}]
|
(rx/catch (fn [{:keys [type code] :as error}]
|
||||||
(when (= :not-found type)
|
(cond
|
||||||
(rx/of (rt/nav :not-found)))))))))
|
(= :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
|
(defn- bundle-fetched
|
||||||
[file users project pages]
|
[file users project pages]
|
||||||
|
|
|
@ -46,4 +46,8 @@ goog.scope(function() {
|
||||||
self.set_token_BANG_ = function(instance, token) {
|
self.set_token_BANG_ = function(instance, token) {
|
||||||
instance.setToken(token);
|
instance.setToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.replace_token_BANG_ = function(instance, token) {
|
||||||
|
instance.replaceToken(token);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -87,20 +87,26 @@
|
||||||
|
|
||||||
;; --- Navigate (Event)
|
;; --- Navigate (Event)
|
||||||
|
|
||||||
(deftype Navigate [id params qparams]
|
(deftype Navigate [id params qparams replace]
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
(effect [_ state stream]
|
(effect [_ state stream]
|
||||||
|
(prn "Navigate" id params qparams replace)
|
||||||
(let [router (:router state)
|
(let [router (:router state)
|
||||||
history (:history state)
|
history (:history state)
|
||||||
path (resolve router id params qparams)]
|
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
|
(defn nav
|
||||||
([id] (nav id nil nil))
|
([id] (nav id nil nil))
|
||||||
([id params] (nav id params nil))
|
([id params] (nav id params nil))
|
||||||
([id params qparams]
|
([id params qparams] (Navigate. id params qparams false)))
|
||||||
{:pre [(keyword? id)]}
|
|
||||||
(Navigate. id params qparams)))
|
(defn nav'
|
||||||
|
([id] (nav id nil nil))
|
||||||
|
([id params] (nav id params nil))
|
||||||
|
([id params qparams] (Navigate. id params qparams true)))
|
||||||
|
|
||||||
(def navigate nav)
|
(def navigate nav)
|
||||||
|
|
||||||
|
@ -112,6 +118,7 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [history (bhistory/create)]
|
(let [history (bhistory/create)]
|
||||||
|
(bhistory/enable! history)
|
||||||
(assoc state :history history)))
|
(assoc state :history history)))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
|
@ -119,14 +126,15 @@
|
||||||
(let [stoper (rx/filter (ptk/type? ::initialize-history) stream)
|
(let [stoper (rx/filter (ptk/type? ::initialize-history) stream)
|
||||||
history (:history state)
|
history (:history state)
|
||||||
router (:router state)]
|
router (:router state)]
|
||||||
(->> (rx/create (fn [sink]
|
(rx/merge
|
||||||
(let [key (e/listen history "navigate" #(sink (.-token %)))]
|
(rx/of (on-change router (.getToken history)))
|
||||||
(bhistory/enable! history)
|
(->> (rx/create (fn [sink]
|
||||||
(fn []
|
(let [key (e/listen history "navigate" #(sink (.-token %)))]
|
||||||
(bhistory/disable! history)
|
(fn []
|
||||||
(e/unlistenByKey key)))))
|
(bhistory/disable! history)
|
||||||
(rx/map #(on-change router %))
|
(e/unlistenByKey key)))))
|
||||||
(rx/take-until stoper))))))
|
(rx/map #(on-change router %))
|
||||||
|
(rx/take-until stoper)))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue