diff --git a/frontend/src/uxbox/main/data/dashboard.cljs b/frontend/src/uxbox/main/data/dashboard.cljs index 4574722d2..8dc715066 100644 --- a/frontend/src/uxbox/main/data/dashboard.cljs +++ b/frontend/src/uxbox/main/data/dashboard.cljs @@ -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] diff --git a/frontend/src/uxbox/main/data/workspace/notifications.cljs b/frontend/src/uxbox/main/data/workspace/notifications.cljs index 590418669..97b1b0724 100644 --- a/frontend/src/uxbox/main/data/workspace/notifications.cljs +++ b/frontend/src/uxbox/main/data/workspace/notifications.cljs @@ -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 diff --git a/frontend/src/uxbox/main/data/workspace/persistence.cljs b/frontend/src/uxbox/main/data/workspace/persistence.cljs index a402623d4..0c957bb71 100644 --- a/frontend/src/uxbox/main/data/workspace/persistence.cljs +++ b/frontend/src/uxbox/main/data/workspace/persistence.cljs @@ -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] diff --git a/frontend/src/uxbox/util/browser_history.js b/frontend/src/uxbox/util/browser_history.js index 74e263b06..da94b8a37 100644 --- a/frontend/src/uxbox/util/browser_history.js +++ b/frontend/src/uxbox/util/browser_history.js @@ -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); + } }); diff --git a/frontend/src/uxbox/util/router.cljs b/frontend/src/uxbox/util/router.cljs index 3fee9cce1..4f747651b 100644 --- a/frontend/src/uxbox/util/router.cljs +++ b/frontend/src/uxbox/util/router.cljs @@ -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)))))))