Skip to content

Commit

Permalink
feat(webapp): gather errors in a module
Browse files Browse the repository at this point in the history
This commit introduces the module `page/error.rs` that defines a few
components to display various error in a uniform way.
  • Loading branch information
W95Psp committed Feb 16, 2024
1 parent cfb1f1d commit 0d639c7
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 57 deletions.
89 changes: 89 additions & 0 deletions typhon-webapp/src/pages/error.rs
Original file line number Diff line number Diff line change
@@ -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,
<main>
<div id="wrapper">
<h1>{code}</h1>
<div>{message}</div>
</div>
{children()}
</main>
}
}

#[component]
pub(crate) fn Unauthorized() -> impl IntoView {
view! {
<ErrorPage code="403" message="Sorry, you don't have access to that page.">

{()}
</ErrorPage>
}
}

#[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,
<ErrorPage code="404" message="The page was not found">

<details>
<summary>Details</summary>
<pre>

{
#[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)(),
},
)
}

</pre>
</details>
</ErrorPage>
}
}
2 changes: 2 additions & 0 deletions typhon-webapp/src/pages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
pub mod dashboard;
pub mod error;
pub mod evaluation;
pub mod jobset;
pub mod login;
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;
Expand Down
57 changes: 0 additions & 57 deletions typhon-webapp/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,60 +351,3 @@ pub fn Router() -> impl IntoView {
<main>{main}</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,
<main>
<div id="wrapper">
<h1>404</h1>
<div>The page was not found!</div>
</div>
<details>
<summary>Details</summary>
<pre>

{
#[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)(),
},
)
}

</pre>
</details>
</main>
}
}

0 comments on commit 0d639c7

Please sign in to comment.