Improve 404 and add broken link static page on viewer.

This commit is contained in:
Andrey Antukh 2021-09-08 12:39:16 +02:00 committed by Andrés Moya
parent 15991d0226
commit 85a1c61880
7 changed files with 89 additions and 73 deletions

View file

@ -42,10 +42,13 @@
(if-let [conform (get-in match [:data :conform])] (if-let [conform (get-in match [:data :conform])]
(let [spath (get conform :path-params ::any) (let [spath (get conform :path-params ::any)
squery (get conform :query-params ::any)] squery (get conform :query-params ::any)]
(-> (dissoc match :params) (try
(assoc :path-params (us/conform spath (get match :path-params)) (-> (dissoc match :params)
:query-params (us/conform squery (get match :query-params))))) (assoc :path-params (us/conform spath (get match :path-params))
match))) :query-params (us/conform squery (get match :query-params))))
(catch :default _
nil)))
match)))
(defn on-navigate (defn on-navigate
[router path] [router path]

View file

@ -24,6 +24,10 @@
;; --- COMMON SPECS ;; --- COMMON SPECS
(defn is-authenticated?
[{:keys [id]}]
(and (uuid? id) (not= id uuid/zero)))
(s/def ::id ::us/uuid) (s/def ::id ::us/uuid)
(s/def ::fullname ::us/string) (s/def ::fullname ::us/string)
(s/def ::email ::us/email) (s/def ::email ::us/email)

View file

@ -26,7 +26,7 @@
[app.main.ui.render :as render] [app.main.ui.render :as render]
[app.main.ui.settings :as settings] [app.main.ui.settings :as settings]
[app.main.ui.static :as static] [app.main.ui.static :as static]
[app.main.ui.viewer :refer [viewer-page]] [app.main.ui.viewer :as viewer]
[app.main.ui.workspace :as workspace] [app.main.ui.workspace :as workspace]
[app.util.timers :as ts] [app.util.timers :as ts]
[cljs.pprint :refer [pprint]] [cljs.pprint :refer [pprint]]
@ -151,11 +151,13 @@
{:keys [index share-id section page-id] :or {section :interactions}} query-params {:keys [index share-id section page-id] :or {section :interactions}} query-params
{:keys [file-id]} path-params] {:keys [file-id]} path-params]
[:& fs/fullscreen-wrapper {} [:& fs/fullscreen-wrapper {}
[:& viewer-page {:page-id page-id (if (:token query-params)
:file-id file-id [:& viewer/breaking-change-notice]
:section section [:& viewer/viewer-page {:page-id page-id
:index index :file-id file-id
:share-id share-id}]]) :section section
:index index
:share-id share-id}])])
:render-object :render-object
(do (do

View file

@ -12,82 +12,68 @@
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.i18n :refer [tr]] [app.util.i18n :refer [tr]]
[app.util.object :as obj]
[app.util.router :as rt] [app.util.router :as rt]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(defn- go-to-dashboard (mf/defc static-header
[profile] {::mf/wrap-props false}
(let [team-id (du/get-current-team-id profile)] [props]
(st/emit! (rt/nav :dashboard-projects {:team-id team-id})))) (let [children (obj/get props "children")
on-click (mf/use-callback
(fn []
(let [profile (deref refs/profile)]
(if (du/is-authenticated? profile)
(let [team-id (du/get-current-team-id profile)]
(st/emit! (rt/nav :dashboard-projects {:team-id team-id})))
(st/emit! (rt/nav :auth-login {}))))))]
[:section.exception-layout
[:div.exception-header
{:on-click on-click}
i/logo]
[:div.exception-content
[:div.container children]]]))
(mf/defc not-found (mf/defc not-found
[] []
(let [profile (mf/deref refs/profile)] [:> static-header {}
[:section.exception-layout [:div.image i/icon-empty]
[:div.exception-header [:div.main-message (tr "labels.not-found.main-message")]
{:on-click (partial go-to-dashboard profile)} [:div.desc-message (tr "labels.not-found.desc-message")]])
i/logo]
[:div.exception-content
[:div.container
[:div.image i/icon-empty]
[:div.main-message (tr "labels.not-found.main-message")]
[:div.desc-message (tr "labels.not-found.desc-message")]
[:div.sign-info
[:span (tr "labels.not-found.auth-info") " " [:b (:email profile)]]
[:a.btn-primary.btn-small
{:on-click (st/emitf (du/logout))}
(tr "labels.sign-out")]]]]]))
(mf/defc bad-gateway (mf/defc bad-gateway
[] []
(let [profile (mf/deref refs/profile)] [:> static-header {}
[:section.exception-layout [:div.image i/icon-empty]
[:div.exception-header [:div.main-message (tr "labels.bad-gateway.main-message")]
{:on-click (partial go-to-dashboard profile)} [:div.desc-message (tr "labels.bad-gateway.desc-message")]
i/logo] [:div.sign-info
[:div.exception-content [:a.btn-primary.btn-small
[:div.container {:on-click (st/emitf #(dissoc % :exception))}
[:div.image i/icon-empty] (tr "labels.retry")]]])
[:div.main-message (tr "labels.bad-gateway.main-message")]
[:div.desc-message (tr "labels.bad-gateway.desc-message")]
[:div.sign-info
[:a.btn-primary.btn-small
{:on-click (st/emitf #(dissoc % :exception))}
(tr "labels.retry")]]]]]))
(mf/defc service-unavailable (mf/defc service-unavailable
[] []
(let [profile (mf/deref refs/profile)] [:> static-header {}
[:section.exception-layout [:div.image i/icon-empty]
[:div.exception-header [:div.main-message (tr "labels.service-unavailable.main-message")]
{:on-click (partial go-to-dashboard profile)} [:div.desc-message (tr "labels.service-unavailable.desc-message")]
i/logo] [:div.sign-info
[:div.exception-content [:a.btn-primary.btn-small
[:div.container {:on-click (st/emitf #(dissoc % :exception))}
[:div.image i/icon-empty] (tr "labels.retry")]]])
[:div.main-message (tr "labels.service-unavailable.main-message")]
[:div.desc-message (tr "labels.service-unavailable.desc-message")]
[:div.sign-info
[:a.btn-primary.btn-small
{:on-click (st/emitf #(dissoc % :exception))}
(tr "labels.retry")]]]]]))
(mf/defc internal-error (mf/defc internal-error
[] []
(let [profile (mf/deref refs/profile)] [:> static-header {}
[:section.exception-layout [:div.image i/icon-empty]
[:div.exception-header [:div.main-message (tr "labels.internal-error.main-message")]
{:on-click (partial go-to-dashboard profile)} [:div.desc-message (tr "labels.internal-error.desc-message")]
i/logo] [:div.sign-info
[:div.exception-content [:a.btn-primary.btn-small
[:div.container {:on-click (st/emitf (dm/assign-exception nil))}
[:div.image i/icon-empty] (tr "labels.retry")]]])
[:div.main-message (tr "labels.internal-error.main-message")]
[:div.desc-message (tr "labels.internal-error.desc-message")]
[:div.sign-info
[:a.btn-primary.btn-small
{:on-click (st/emitf (dm/assign-exception nil))}
(tr "labels.retry")]]]]]))
(mf/defc exception-page (mf/defc exception-page
[{:keys [data] :as props}] [{:keys [data] :as props}]

View file

@ -12,7 +12,9 @@
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.hooks :as hooks] [app.main.ui.hooks :as hooks]
[app.main.ui.icons :as i]
[app.main.ui.share-link] [app.main.ui.share-link]
[app.main.ui.static :as static]
[app.main.ui.viewer.comments :refer [comments-layer]] [app.main.ui.viewer.comments :refer [comments-layer]]
[app.main.ui.viewer.handoff :as handoff] [app.main.ui.viewer.handoff :as handoff]
[app.main.ui.viewer.header :refer [header]] [app.main.ui.viewer.header :refer [header]]
@ -150,3 +152,10 @@
(when-let [data (mf/deref refs/viewer-data)] (when-let [data (mf/deref refs/viewer-data)]
(let [key (str (get-in data [:file :id]))] (let [key (str (get-in data [:file :id]))]
[:& viewer {:params props :data data :key key}]))) [:& viewer {:params props :data data :key key}])))
(mf/defc breaking-change-notice
[]
[:> static/static-header {}
[:div.image i/unchain]
[:div.main-message (tr "viewer.breaking-change.message")]
[:div.desc-message (tr "viewer.breaking-change.description")]])

View file

@ -2968,4 +2968,10 @@ msgid "workspace.updates.update"
msgstr "Update" msgstr "Update"
msgid "workspace.viewport.click-to-close-path" msgid "workspace.viewport.click-to-close-path"
msgstr "Click to close the path" msgstr "Click to close the path"
msgid "viewer.breaking-change.message"
msgstr "Sorry!"
msgid "viewer.breaking-change.description"
msgstr "This shareable link is no longer valid. Create a new one or ask the owner for a new one.

View file

@ -2853,4 +2853,10 @@ msgid "workspace.updates.update"
msgstr "Actualizar" msgstr "Actualizar"
msgid "workspace.viewport.click-to-close-path" msgid "workspace.viewport.click-to-close-path"
msgstr "Pulsar para cerrar la ruta" msgstr "Pulsar para cerrar la ruta"
msgid "viewer.breaking-change.message"
msgstr "¡Lo sentimos!"
msgid "viewer.breaking-change.description"
msgstr "Este link compartido ya no funciona. Crea uno nuevo o pídelo a la persona que lo creó."