From 0d639c711e9c23333437dbca4b065b9d73cd9369 Mon Sep 17 00:00:00 2001 From: Lucas Franceschino Date: Fri, 16 Feb 2024 22:45:17 +0100 Subject: [PATCH] feat(webapp): gather errors in a module This commit introduces the module `page/error.rs` that defines a few components to display various error in a uniform way. --- typhon-webapp/src/pages/error.rs | 89 ++++++++++++++++++++++++++++++++ typhon-webapp/src/pages/mod.rs | 2 + typhon-webapp/src/routes.rs | 57 -------------------- 3 files changed, 91 insertions(+), 57 deletions(-) create mode 100644 typhon-webapp/src/pages/error.rs diff --git a/typhon-webapp/src/pages/error.rs b/typhon-webapp/src/pages/error.rs new file mode 100644 index 0000000..faf4cc2 --- /dev/null +++ b/typhon-webapp/src/pages/error.rs @@ -0,0 +1,89 @@ +use crate::prelude::*; + +#[component] +pub(crate) fn ErrorPage( + #[prop(into)] code: String, + #[prop(into)] message: String, + children: Children, +) -> impl IntoView { + let style = style! { + main { + padding: 20px; + } + #wrapper { + text-align: center; + } + }; + view! { class=style, +
+
+

{code}

+
{message}
+
+ {children()} +
+ } +} + +#[component] +pub(crate) fn Unauthorized() -> impl IntoView { + view! { + + + {()} + + } +} + +#[component] +pub(crate) fn BadLocation(loc: leptos_router::Location) -> impl IntoView { + let style = style! { + main { + padding: 20px; + } + #wrapper { + text-align: center; + } + details { + margin-top: 30px; + font-size: 12px; + color: var(--color-lgray); + } + pre { + color: black; + font-size: 11px; + } + }; + view! { class=style, + + +
+ Details +
+
+                    {
+                        #[derive(Debug)]
+                        pub struct Location {
+                            pub pathname: String,
+                            pub search: String,
+                            pub query: leptos_router::ParamsMap,
+                            pub hash: String,
+                            pub state: leptos_router::State,
+                        }
+                        format!(
+                            "{:#?}",
+                            Location {
+                                pathname: (loc.pathname)(),
+                                search: (loc.search)(),
+                                query: (loc.query)(),
+                                hash: (loc.hash)(),
+                                state: (loc.state)(),
+                            },
+                        )
+                    }
+
+                
+
+
+ } +} diff --git a/typhon-webapp/src/pages/mod.rs b/typhon-webapp/src/pages/mod.rs index 76facc5..cf157ed 100644 --- a/typhon-webapp/src/pages/mod.rs +++ b/typhon-webapp/src/pages/mod.rs @@ -1,4 +1,5 @@ pub mod dashboard; +pub mod error; pub mod evaluation; pub mod jobset; pub mod login; @@ -6,6 +7,7 @@ pub mod project; pub mod projects; pub(crate) use dashboard::Dashboard; +pub(crate) use error::*; pub(crate) use evaluation::Evaluation; pub(crate) use jobset::Jobset; pub(crate) use login::Login; diff --git a/typhon-webapp/src/routes.rs b/typhon-webapp/src/routes.rs index 17522d4..48a3e01 100644 --- a/typhon-webapp/src/routes.rs +++ b/typhon-webapp/src/routes.rs @@ -351,60 +351,3 @@ pub fn Router() -> impl IntoView {
{main}
} } - -#[component] -fn BadLocation(loc: leptos_router::Location) -> impl IntoView { - pub use stylers::style; - let style = style! { - main { - padding: 20px; - } - #wrapper { - text-align: center; - } - details { - margin-top: 30px; - font-size: 12px; - color: var(--color-lgray); - } - pre { - color: black; - font-size: 11px; - } - }; - view! { class=style, -
-
-

404

-
The page was not found!
-
-
- Details -
-
-                    {
-                        #[derive(Debug)]
-                        pub struct Location {
-                            pub pathname: String,
-                            pub search: String,
-                            pub query: leptos_router::ParamsMap,
-                            pub hash: String,
-                            pub state: leptos_router::State,
-                        }
-                        format!(
-                            "{:#?}",
-                            Location {
-                                pathname: (loc.pathname)(),
-                                search: (loc.search)(),
-                                query: (loc.query)(),
-                                hash: (loc.hash)(),
-                                state: (loc.state)(),
-                            },
-                        )
-                    }
-
-                
-
-
- } -}